小编Apo*_*llo的帖子

在字符串Python中查找最后出现的字符

如何在字符串中找到字符的最后一次出现?

string = "abcd}def}"
string = string.find('}',last) # Want something like this
Run Code Online (Sandbox Code Playgroud)

python

30
推荐指数
1
解决办法
4万
查看次数

SVG到PNG服务器端 - 使用node.js

我正在尝试按照本教程将d3.js SVG Vis转换为PNG服务器端(使用Node.js)http://eng.wealthfront.com/2011/12/converting-dynamic-svg-to- PNG-with.html

链接到完整代码: https ://gist.github.com/1509145

但是,每当我尝试发出加载页面的请求时,我都会收到此错误

    /Users/me/Node/node_modules/jsdom/lib/jsdom.js:171
        features   = JSON.parse(JSON.stringify(window.document.implementation._fea
                                                              ^
    TypeError: Cannot read property 'implementation' of undefined
        at exports.env.exports.jsdom.env.processHTML (/Users/dereklo/Node/node_modules/jsdom/lib/jsdom.js:171:59)
        at Object.exports.env.exports.jsdom.env (/Users/dereklo/Node/node_modules/jsdom/lib/jsdom.js:262:5)
        at Server.<anonymous> (/Users/dereklo/Node/Pie/pie_serv.js:26:9)
        at Server.EventEmitter.emit (events.js:91:17)
        at HTTPParser.parser.onIncoming (http.js:1785:12)
        at HTTPParser.parserOnHeadersComplete [as onHeadersComplete] (http.js:111:23)
        at Socket.socket.ondata (http.
Run Code Online (Sandbox Code Playgroud)

有人知道为什么会这样吗?我已经安装了jsdom模块,所以我真的不知道是什么导致了这些问题...提前感谢.

编辑

这是我用来实现node.js服务器的代码.我的最新一期是在这个来源之下......

var http = require('http'),
    url = require('url'),
    jsdom = require('jsdom'),
    child_proc = require('child_process'),
    w = 400,
    h = 400,
    __dirname = "Users/dereklo/Node/pie/"

   scripts = ["/Users/dereklo/Node/pie/d3.min.js",
               "/Users/dereklo/Node/pie/d3.layout.min.js",
               "/Users/dereklo/Node/pie/pie.js"],
      //scripts = ["./d3.v2.js",
        // …
Run Code Online (Sandbox Code Playgroud)

node.js d3.js

24
推荐指数
1
解决办法
2万
查看次数

从标题的一部分删除粗体样式

有没有办法从标题的一部分删除粗体样式?

<h1>**This text should be bold**, but this text should not<h1>
Run Code Online (Sandbox Code Playgroud)

有没有办法实现这个目标?

html

22
推荐指数
2
解决办法
9万
查看次数

创建d3.js轴而不编号

有没有办法在没有任何编号的情况下创建d3.js轴?Tickmarks还可以,但根本没有数字.目前我正在使用下面的代码创建我的d3.js轴.提前致谢.

 // create Axis
  svg.selectAll("axis")
      .data(d3.range(angle.domain()[1]))
    .enter().append("g")
      .attr("class", "axis")
      .attr("transform", function(d) { return "rotate(" + angle(d) * 180 / Math.PI + ")"; })
    .call(d3.svg.axis()
      .scale(radius.copy().range([0,0]))
      .ticks(1)
      .orient("left"))
    .append("text")
    .style("color", "white") 
      .attr("y", 
        function (d) {
          if (window.innerWidth < 455){
            console.log("innerWidth less than 455: ",window.innerWidth);
            return -(0);
          }
          else{
            console.log("innerWidth greater than 455: ",window.innerWidth);
            return -(0);
          }
        })
      .attr("dy", "0em");
Run Code Online (Sandbox Code Playgroud)

javascript customization svg d3.js

19
推荐指数
1
解决办法
1万
查看次数

使用Core Motion和CMAccelerometer数据检测某人何时开始行走

我正在尝试检测三种动作:当用户开始步行,慢跑或跑步时.然后我想知道何时停止.我成功地检测到有人在走路,慢跑或跑步时使用以下代码:

- (void)update:(CMAccelerometerData *)accelData {

    [(id) self setAcceleration:accelData.acceleration];

    NSTimeInterval secondsSinceLastUpdate = -([self.lastUpdateTime timeIntervalSinceNow]);

    if (labs(_acceleration.x) >= 0.10000) {
        NSLog(@"walking: %f",_acceleration.x);
    }
    else if (labs(_acceleration.x) > 2.0) {
        NSLog(@"jogging: %f",_acceleration.x);
    }
    else if (labs(_acceleration.x) > 4.0) {
        NSLog(@"sprinting: %f",_acceleration.x);
    }
Run Code Online (Sandbox Code Playgroud)

我遇到的问题是双重的:

1)每次有动作时都会多次调用更新,这可能是因为它经常检查当用户开始行走时(即_acceleration.x> = .1000)它再次调用更新时仍然> = .1000.

示例日志:

    2014-02-22 12:14:20.728 myApp[5039:60b] walking: 1.029846
    2014-02-22 12:14:20.748 myApp[5039:60b] walking: 1.071777
    2014-02-22 12:14:20.768 myApp[5039:60b] walking: 1.067749
Run Code Online (Sandbox Code Playgroud)

2)我很难弄清楚如何检测用户何时停止.有没有人就如何实施"停止检测"提出建议

objective-c ios core-motion apple-m7

19
推荐指数
4
解决办法
2万
查看次数

UISearchBar Minimal Style在打字时使色调变黑

当我把我UISearchBarminimal style在iOS7,当我选择它的色调变成黑色,而文字是不可能的阅读,因为有黑色的黑色.

这不会产生预期的结果.选中时色调仍然是黑色的......

if(floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1)
{
    // set bar style
    _sendToSearchBar.barStyle = UIBarStyleDefault;
    // set bar transparancy
    _sendToSearchBar.translucent = NO;
    // set bar color
    _sendToSearchBar.barTintColor = [UIColor whiteColor];
    // set bar button color
    _sendToSearchBar.tintColor = [UIColor whiteColor];
    // set bar background color
    _sendToSearchBar.backgroundColor = [UIColor whiteColor];
}
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

objective-c uisearchbar ios

17
推荐指数
3
解决办法
1万
查看次数

删除UITableViewCell选择

目前我通过使用UITableViewSelectionStyleNone然后根据委托方法更改单元格的颜色来覆盖标准的UITableViewSelectionStyle :

- (void)tableView:(UITableView *)tableView 
      didHighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];                
    [cell setBackgroundColor:[UIColor yellowColor]];
}

- (void)tableView:(UITableView *)tableView 
    didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setBackgroundColor:[UIColor whiteColor]];
}

- (void)tableView:(UITableView *)tableView 
    didUnhighlightRowAtIndexPath:(NSIndexPath *)indexPath {
    NSLog(@"indexpath: %i",indexPath.row);
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setBackgroundColor:[UIColor whiteColor]];
}

- (void)tableView:(UITableView *)tableView 
    didDeselectRowAtIndexPath:(NSIndexPath *)indexPath {
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath];
    [cell setBackgroundColor:[UIColor whiteColor]];
}
Run Code Online (Sandbox Code Playgroud)

这几乎是有效的,除了每当我突出显示一个单元格,然后将其手指从它上面拖出而没有实际选择它时,颜色不会变为白色...如果我将其设置为[UIColor RedColor]它的工作完全正常.为什么是这样...

编辑:

不知何故,当我在didUnhlightRowAtIndexPath之后打印出indexPath.row时,我从我的NSLog获得"indexpath:2147483647"

objective-c uitableview ios

15
推荐指数
3
解决办法
2万
查看次数

如何检测用户何时更改键盘?

有没有办法检测用户何时更改键盘类型,特别是在这种情况下更改为表情符号键盘?

cocoa-touch uikeyboard ios emoji

13
推荐指数
1
解决办法
6891
查看次数

d3.js - 在堆积图表图表上移动y轴

我还在Google网上论坛https://groups.google.com/forum/?fromgroups#!topic/d3-js/DYiVeC544ws上发布了此问题,但看到它更喜欢此处提出的帮助问题.我只是将y轴移动到我的图形的左边,以便它不会妨碍第一列.我在Google群组中提供了一张图片,以便您可以看到我在说什么.

创建轴的代码如下:

   var MARGINS = {top: 20, right: 20, bottom: 20, left: 60}; // margins around the graph
var xRange = d3.scale.linear().range([MARGINS.left, width - MARGINS.right]), // x range function
    yRange = d3.scale.linear().range([height - MARGINS.top, MARGINS.bottom]), // y range function

    xAxis = d3.svg.axis().scale(xRange).tickSize(16).tickSubdivide(true), // x axis function
    yAxis = d3.svg.axis().scale(yRange).tickSize(10).orient("right").tickSubdivide(true); // y axis function


// create the visualization chart
var vis = d3.select("#chart")
   .append("svg")
    .attr("width", width)
    .attr("height", height + margin);


    // add in the x axis
  vis.append("svg:g") // container …
Run Code Online (Sandbox Code Playgroud)

javascript d3.js

12
推荐指数
1
解决办法
2万
查看次数

检测strtol失败

如何检测strtol()是否未转换数字?我在下面的简单案例中对它进行了测试并输出了0.现在显而易见的问题是如何区分非转换和0的转换?

long int li1;
li1 = strtol("some string with no numbers",NULL,10);
printf("li1: %ld\n",li1);

****
li1: 0
Run Code Online (Sandbox Code Playgroud)

c

12
推荐指数
1
解决办法
1万
查看次数