我在github上分了一个项目,做了一些改动,到目前为止一直很好.
与此同时,我分叉的存储库发生了变化,我希望将这些更改存入我的存储库.我怎么做 ?
如何在Java中获取用户名/登录名?
这是我试过的代码......
try{
LoginContext lc = new LoginContext(appName,new TextCallbackHandler());
lc.login();
Subject subject = lc.getSubject();
Principal principals[] = (Principal[])subject.getPrincipals().toArray(new Principal[0]);
for (int i=0; i<principals.length; i++) {
if (principals[i] instanceof NTUserPrincipal || principals[i] instanceof UnixPrincipal) {
String loggedInUserName = principals[i].getName();
}
}
}
catch(SecurityException se){
System.out.println("SecurityException: " + se.getMessage());
}
Run Code Online (Sandbox Code Playgroud)
SecurityException
当我尝试运行此代码时,我得到了一个.有人可以告诉我,我是否正朝着正确的方向前进,并帮助我理解这个问题.
我有一个列表,它将始终只包含1和0.我需要获得列表的非零索引列表:
a = [0, 1, 0, 1, 0, 0, 0, 0]
b = []
for i in range(len(a)):
if a[i] == 1: b.append(i)
print b
Run Code Online (Sandbox Code Playgroud)
实现这一目标的"pythonic"方式是什么?
我可以使用计算机从设备上卸载应用程序adb uninstall <package_name>
,但是我想对实际设备上的脚本执行相同的操作.
我也试过运行一个android.intent.action.DELETE
意图,am
但它提示用户确认.
鉴于设备已植根,是否可以在设备上运行命令以卸载应用程序而无需用户操作/确认?
我是Java新手,但对ActionScript 3有一些OOP经验,所以我试图依靠我所知道的东西进行迁移.
在ActionScript 3中,您可以使用get和set关键字创建getter和setter,这意味着您在类中创建方法并通过该类的实例的属性访问数据.我可能听起来很复杂,但事实并非如此.这是一个例子:
class Dummy{
private var _name:String;
public function Dummy(name:String=null){
this._name = name;
}
//getter
public function get name():String{
return _name;
}
//setter
public function set name(value:String):void{
//do some validation if necessary
_name = value;
}
}
Run Code Online (Sandbox Code Playgroud)
我会name
在一个对象中访问:
var dummy:Dummy = new Dummy("fred");
trace(dummy.name);//prints: fred
dummy.name = "lolo";//setter
trace(dummy.name);//getter
Run Code Online (Sandbox Code Playgroud)
我怎么用Java做到这一点?
只是拥有一些公共领域是不可能的.我注意到有一种在方法前面使用get和set的约定,我很好.
例如,
class Dummy{
String _name;
public void Dummy(){}
public void Dummy(String name){
_name = name;
}
public String getName(){
return _name;
}
public void setName(String …
Run Code Online (Sandbox Code Playgroud) 我需要将任意字符串转换为python中有效变量名称的字符串.
这是一个非常基本的例子:
s1 = 'name/with/slashes'
s2 = 'name '
def clean(s):
s = s.replace('/','')
s = s.strip()
return s
print clean(s1)+'_'#the _ is there so I can see the end of the string
Run Code Online (Sandbox Code Playgroud)
这是一种非常天真的方法.我需要检查字符串是否包含无效的变量名字符并将其替换为''
什么是pythonic方式来做到这一点?
我正在看这个Web Audio API演示,这本好书的一部分
如果你看一下演示,fft峰值会顺利下降.我正在尝试使用minim库来处理Java模式下的Processing.我已经看过如何使用doFFTAnalysis()方法中的web音频api完成此操作,并尝试使用minim复制它.我还尝试移植abs()如何处理复杂类型:
/ 26.2.7/3 abs(__z): Returns the magnitude of __z.
00565 template<typename _Tp>
00566 inline _Tp
00567 __complex_abs(const complex<_Tp>& __z)
00568 {
00569 _Tp __x = __z.real();
00570 _Tp __y = __z.imag();
00571 const _Tp __s = std::max(abs(__x), abs(__y));
00572 if (__s == _Tp()) // well ...
00573 return __s;
00574 __x /= __s;
00575 __y /= __s;
00576 return __s * sqrt(__x * __x + __y * __y);
00577 }
00578 …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用OpenCV从它的背景中分割弯曲的杆,然后在其中找到弯曲并计算每个弯曲之间的角度.
幸运的是,第一部分是微不足道的,前景和背景之间有足够的对比.在分割时,一些侵蚀/扩张会处理反射/高光.
第二部分是我不知道如何处理它的地方.
我可以轻松地检索轮廓(顶部和底部非常相似,所以要么会这样做),但我似乎无法弄清楚如何将轮廓分成直线部分和弯曲杆来计算角度.
到目前为止,我已经尝试过简单地修复轮廓,但要么我得到太多或太少的点,并且感觉很难确定正确的设置以保持笔直部分和弯曲部分简化.
这是我的输入图像(bend.png)
这是我到目前为止所尝试的内容:
#!/usr/bin/env python
import numpy as np
import cv2
threshold = 229
# erosion/dilation kernel
kernel = np.ones((5,5),np.uint8)
# contour simplification
epsilon = 0
# slider callbacks
def onThreshold(x):
global threshold
print "threshold = ",x
threshold = x
def onEpsilon(x):
global epsilon
epsilon = x * 0.01
print "epsilon = ",epsilon
# make a window to add sliders/preview to
cv2.namedWindow('processed')
#make some sliders
cv2.createTrackbar('threshold','processed',60,255,onThreshold)
cv2.createTrackbar('epsilon','processed',1,1000,onEpsilon)
# load image
img = cv2.imread('bend.png',0)
# continuously process …
Run Code Online (Sandbox Code Playgroud) 我正试图在3d中挤出一条路径.没什么好看的,只是遵循一些要点并使用正常的多边形来表示"管道".我现在正在使用Processing来快速原型化,但稍后会将代码转换为OpenGL.
我的问题是以正确的角度旋转"关节".我想我对如何获得角度有一个粗略的想法,不确定.
我从Simon Greenwold的一个样本开始(处理>文件>示例> 3D>表格>顶点).这是我迄今为止的尝试:
更新>改进/简化代码
Here is the main sketch code:
int pointsNum = 10;
Extrusion star;
int zoom = 0;
void setup() {
size(500, 500, P3D);
PVector[] points = new PVector[pointsNum+1];
for(int i = 0 ; i <= pointsNum ; i++){
float angle = TWO_PI/pointsNum * i;
if(i % 2 == 0)
points[i] = new PVector(cos(angle) * 100,sin(angle) * 100,0);
else
points[i] = new PVector(cos(angle) * 50,sin(angle) * 50,0);
}
star = new Extrusion(10,10,points,3);
}
void draw() { …
Run Code Online (Sandbox Code Playgroud) 我正在使用OpenCV的VideoCapture(使用ffmpeg支持编译)从IP摄像机传输H264内容.
到目前为止,工作正常,但每隔一段时间我就会出现解码错误(来自我假设的ffmpeg):
[h264 @ 0x103006400] mb_type 137 in I slice too large at 26 10
[h264 @ 0x103006400] error while decoding MB 26 10
[h264 @ 0x103006400] negative number of zero coeffs at 25 5
[h264 @ 0x103006400] error while decoding MB 25 5
[h264 @ 0x103006400] cbp too large (421) at 35 13
[h264 @ 0x103006400] error while decoding MB 35 13
[h264 @ 0x103006400] mb_type 121 in P slice too large at 20 3
[h264 @ 0x103006400] error …
Run Code Online (Sandbox Code Playgroud) java ×3
python ×3
geometry ×2
opencv ×2
processing ×2
3d ×1
accessor ×1
android ×1
audio ×1
command-line ×1
decoding ×1
ffmpeg ×1
fft ×1
getter ×1
git ×1
github ×1
h.264 ×1
ip-camera ×1
list ×1
opengl ×1
root ×1
setter ×1
string ×1
trigonometry ×1
uninstall ×1
username ×1
validation ×1
variables ×1