小编Jac*_*anz的帖子

将图像从url保存到文件

对Go来说很新(我正在做的第一个简单项目).

问题:如何从URL获取图像然后将其保存到计算机中?

这是我到目前为止所拥有的:

package main

import (
"fmt"
"net/http"
"image"
"io/ioutil"
)

func main() {
        url := "http://i.imgur.com/m1UIjW1.jpg"
        // don't worry about errors
    response, _ := http.Get(url);

    defer response.Body.Close()
    m, _, err := image.Decode(response.Body)

    error := ioutil.WriteFile("/images/asdf.jpg", m, 0644)
}
Run Code Online (Sandbox Code Playgroud)

但是,当我运行此代码时,我得到了 cannot use m (type image.Image) as type []byte in function argument

我假设我必须将image.Image(变量m)转换为未定义的字节数量?这是正确的方法吗?

go

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

如何从上一个命令的输出中分配终端变量

我对终端脚本世界非常陌生.这就是我想要做的事情:

1) Find out the process that's using a given port (8000 in this case)
2) Kill that process
Run Code Online (Sandbox Code Playgroud)

很简单.我可以手动使用:

lsof -i tcp:8000 -- get the PID of what's using the port
kill -9 $PID -- terminate the app using the port
Run Code Online (Sandbox Code Playgroud)

作为参考,这里正是使用lsof -i tcp:8000时返回的内容

COMMAND   PID       USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
php     94735     MyUser    5u  IPv6 0x9fbd127eb623aacf      0t0  TCP localhost:irdmi (LISTEN)
Run Code Online (Sandbox Code Playgroud)

这是我的问题:如何捕获PID值,lsof -i tcp:8000以便我可以将该变量用于下一个命令? 我知道如何创建我指定的变量...而不是动态制作的变量.

macos terminal

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

使用.each()动态创建JSON数组

我正在尝试动态创建一个JSON数组.在网站中,有一个动态数量的<div id ="#selected">,我需要获取所有值并创建一个JSON数组.

我遇到过.push()功能,但我无法弄明白.

<!-- there could be a million of these, or only one... each value is unique though -->
<div id="selected" value="5|3"></div>
<div id="selected" value="3|65"></div>


function json_array_selected() {

var JSon = {};
$('div#selected').each(function() {
        // let's first split the given values
        var Split = $(this).attr('value');
        Split = Split.split('|');
        var Type = Split[0];
        Value = Split[1];

        // now let's set up our Json array... using the value = type way, there should never be
        // any repeating 
        JSon.Value = …
Run Code Online (Sandbox Code Playgroud)

jquery json

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

php preg_replace电话号码

我想用html字符串替换给定的电话号码,例如

<a>click here now! (123) -456-789</a>
Run Code Online (Sandbox Code Playgroud)

我认为接近它的最佳方法是找到看起来像电话号码的所有不同情况,例如:

$pattern = *any 3 numbers* *any characters up to 3 characters long* 
$pattern .= *any 3 numbers* *any characters up to 3 characters long* 
$pattern .= *any numbers up to 4 numbers long*

// $pattern maybe something like [0-9]{3}\.?([0-9]{3})\.?([0-9]{4})

$array = preg_match_all($pattern, $string);

foreach($array)
{
    // replace the string with the the new phone number
}
Run Code Online (Sandbox Code Playgroud)

基本上,正则表达式将如何?

php regex

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

将隐藏信息添加到UITableViewCell

在代码中是否有一种方法可以向UITableViewCell添加一些隐藏信息?

使用案例:

  • 在活动源中,(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath调用并且每个单元格都有一个活动.每个都有自己独特的"activityId".
  • 每个单元格中都有一些按钮(带有唯一标签),按下时,给定的活动是"喜欢"
  • 每个按钮都有一个IBOutlet,然后调用模型然后处理类似的东西

我对IBOutlet的代码是:

- (IBAction)buttonUp:(UIButton *)sender {

UIButton *btn = (UIButton *) sender;
UITableViewCell *cell = (UITableViewCell *) [[btn superview] superview];

UIView *cellView = [cell.contentView viewWithTag: ..myUniqueButtonTag.. ];

NSLog(@"activityId is: %@", ...);
}
Run Code Online (Sandbox Code Playgroud)

cocoa-touch objective-c uitableview ios

0
推荐指数
1
解决办法
294
查看次数

标签 统计

cocoa-touch ×1

go ×1

ios ×1

jquery ×1

json ×1

macos ×1

objective-c ×1

php ×1

regex ×1

terminal ×1

uitableview ×1