程序设计

专业和发烧友程序员的问答

30
如何在C#中为URL建立查询字符串?
从代码调用Web资源时的常见任务是构建查询字符串以包含所有必要的参数。虽然绝对不是火箭科学,但您需要处理一些细微的细节,例如附加&第一个参数(如果不是第一个参数),对参数进行编码等。 要做的代码很简单,但是有点乏味: StringBuilder SB = new StringBuilder(); if (NeedsToAddParameter A) { SB.Append("A="); SB.Append(HttpUtility.UrlEncode("TheValueOfA")); } if (NeedsToAddParameter B) { if (SB.Length>0) SB.Append("&"); SB.Append("B="); SB.Append(HttpUtility.UrlEncode("TheValueOfB")); } } 这是一项如此常见的任务,人们期望存在一个实用程序类,该实用程序类将使其更优雅,更易读。扫描MSDN时,我找不到一个,这使我想到以下问题: 您做上述事情时最优雅的清洁方式是什么?
473 c#  .net  url  query-string 

7
Nginx —静态文件,混淆了根和别名
我需要通过我的应用服务器(位于)为我的应用提供服务8080,并从目录中获取我的静态文件,而无需触摸应用服务器。我拥有的Nginx配置是这样的... # app server on port 8080 # nginx listens on port 8123 server { listen 8123; access_log off; location /static/ { # root /var/www/app/static/; alias /var/www/app/static/; autoindex off; } location / { proxy_pass http://127.0.0.1:8080; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } } 现在,使用此配置,一切正常。请注意,该root指令已被注释掉。 如果我启用root和停用alias--它将停止工作。但是,当我/static/从中删除尾迹时,root它将再次开始工作。 有人可以解释发生了什么。还请解释清楚和冗长之间有什么区别root和alias和它们的用途。
473 nginx 

15
* ngIf和* ngFor在同一元素上导致错误
我在与试图使用角度的问题*ngFor,并*ngIf在相同的元素。 当尝试遍历中的集合时*ngFor,该集合被视为null,因此在尝试访问其在模板中的属性时失败。 @Component({ selector: 'shell', template: ` <h3>Shell</h3><button (click)="toggle()">Toggle!</button> <div *ngIf="show" *ngFor="let thing of stuff"> {{log(thing)}} <span>{{thing.name}}</span> </div> ` }) export class ShellComponent implements OnInit { public stuff:any[] = []; public show:boolean = false; constructor() {} ngOnInit() { this.stuff = [ { name: 'abc', id: 1 }, { name: 'huo', …

25
“ git pull --all”可以更新我所有的本地分支吗?
我经常至少有3个远程分支机构:主分支,临时分支和生产分支。我有3个本地分支跟踪这些远程分支。 更新我所有的本地分支很乏味: git fetch --all git rebase origin/master git checkout staging git rebase origin/staging git checkout production git rebase origin/production 我很想能够做一个“ git pull -all”,但我一直无法使它工作。它似乎在执行“获取-全部”操作,然后更新(快进或合并)当前工作的分支,而不更新其他本地分支。 我仍然无法手动切换到每个本地分支并进行更新。
473 git 

18
轮廓半径?
反正是有得到的圆角的轮廓的div element,类似border-radius?
473 html  css 

8
调用loadurl时,Android Webview启动浏览器
我创建了一个Activity具有标题和Web视图的LinearLayout。在onResume()方法中调用webView.loadUrl(url)。问题在于活动首先显示标题,其余屏幕为空白,然后启动设备浏览器并显示URL页面。我想看到的是WebView标题下方显示的页面。可能是什么问题呢? 编辑:好的,做了一些进一步的搜索,找到了这个: 单击URL将打开默认浏览器 它指向此处的WebView教程。 只需实现Web客户端并进行设置即可。

8
Python3中的StringIO
我正在使用Python 3.2.1,但无法导入StringIO模块。我使用 io.StringIO和它的作品,但我不能使用它numpy的genfromtxt是这样的: x="1 3\n 4.5 8" numpy.genfromtxt(io.StringIO(x)) 我收到以下错误: TypeError: Can't convert 'bytes' object to str implicitly 当我写的import StringIO时候说 ImportError: No module named 'StringIO'
473 python  python-3.x  io 

22
查找列表的平均值
我必须在Python中找到列表的平均值。到目前为止,这是我的代码 l = [15, 18, 2, 36, 12, 78, 5, 6, 9] print reduce(lambda x, y: x + y, l) 我已经知道了,所以它可以将列表中的值加在一起,但是我不知道如何将其划分为它们?
473 python  list  lambda  average  reduce 

30
Docker无法连接到Docker守护程序
将Docker版本更新为后0.8.0,输入时出现错误消息sudo docker version: Client version: 0.8.0 Go version (client): go1.2 Git commit (client): cc3a8c8 2014/02/19 12:54:16 Can't connect to docker daemon. Is 'docker -d' running on this host? 我已经按照说明进行了操作,并输入了command sudo docker -d,我得到了: [/var/lib/docker|2462000b] +job initserver() [/var/lib/docker|2462000b.initserver()] Creating server open /var/lib/docker/aufs/layers/cf2414da53f9bcfaa48bc3d58360d7f1cfd3784e4fe51fbef95197709dfc285d: no such file or directory[/var/lib/docker|2462000b] -job initserver() = ERR (1) …
473 linux  docker 

15
从父级调用子级方法
我有两个组成部分。 父组件 子组件 我试图从父级调用孩子的方法,我尝试过这种方法,但没有得到结果 class Parent extends Component { render() { return ( <Child> <button onClick={Child.getAlert()}>Click</button> </Child> ); } } class Child extends Component { getAlert() { alert('clicked'); } render() { return ( <h1 ref="hello">Hello</h1> ); } } 有没有一种方法可以从父级调用子级的方法? 注意:子组件和父组件位于两个不同的文件中

11
降价:继续编号清单
在下面的markdown代码中,我想item 3从列表编号3开始。但是由于markdown之间的代码块,此列表项将作为新列表启动。有什么办法可以防止这种行为? 所需的输出: 1. item 1 2. item 2 ``` Code block ``` 3. item 3 产生的输出: 项目1 项目2 Code block 项目3
473 markdown 

10
git-diff忽略^ M
在某些文件包含^ M作为换行符的项目中。显然,不可能对这些文件进行区分,因为git-diff将其视为整个文件只是一行。 与以前的版本有何不同? 是否有类似“比较时将^ M作为换行符”的选项? prompt> git-diff "HEAD^" -- MyFile.as diff --git a/myproject/MyFile.as b/myproject/MyFile.as index be78321..a393ba3 100644 --- a/myproject/MyFile.cpp +++ b/myproject/MyFile.cpp @@ -1 +1 @@ -<U+FEFF>import flash.events.MouseEvent;^Mimport mx.controls.*;^Mimport mx.utils.Delegate \ No newline at end of file +<U+FEFF>import flash.events.MouseEvent;^Mimport mx.controls.*;^Mimport mx.utils.Delegate \ No newline at end of file prompt> 更新: 现在,我编写了一个Ruby脚本,该脚本签出了最新的10个修订并将CR转换为LF。 …
473 git  diff  newline  git-diff 


12
如何将UIButton的标题设置为左对齐?
我需要从的左侧显示电子邮件地址UIButton,但是它位于中间。 有什么方法可以将对齐方式设置为a的左侧UIButton吗? 这是我当前的代码: UIButton* emailBtn = [[UIButton alloc] initWithFrame:CGRectMake(5,30,250,height+15)]; emailBtn.backgroundColor = [UIColor clearColor]; [emailBtn setTitle:obj2.customerEmail forState:UIControlStateNormal]; emailBtn.titleLabel.font = [UIFont systemFontOfSize:12.5]; [emailBtn setTitleColor:[[[UIColor alloc]initWithRed:0.121 green:0.472 blue:0.823 alpha:1]autorelease] forState:UIControlStateNormal]; [emailBtn addTarget:self action:@selector(emailAction:) forControlEvents:UIControlEventTouchUpInside]; [elementView addSubview:emailBtn]; [emailBtn release];

10
角度ng-repeat错误“不允许在转发器中重复。”
我正在定义一个自定义过滤器,如下所示: <div class="idea item" ng-repeat="item in items" isoatom> <div class="section comment clearfix" ng-repeat="comment in item.comments | range:1:2"> .... </div> </div> 如您所见,使用过滤器的ng-repeat嵌套在另一个ng-repeat中 过滤器的定义如下: myapp.filter('range', function() { return function(input, min, max) { min = parseInt(min); //Make string input int max = parseInt(max); for (var i=min; i<max; i++) input.push(i); return input; }; }); …

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.