对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
)转换为未定义的字节数量?这是正确的方法吗?
我对终端脚本世界非常陌生.这就是我想要做的事情:
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
以便我可以将该变量用于下一个命令? 我知道如何创建我指定的变量...而不是动态制作的变量.
我正在尝试动态创建一个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) 我想用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)
基本上,正则表达式将如何?
在代码中是否有一种方法可以向UITableViewCell添加一些隐藏信息?
使用案例:
(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
调用并且每个单元格都有一个活动.每个都有自己独特的"activityId".我对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 ×1
go ×1
ios ×1
jquery ×1
json ×1
macos ×1
objective-c ×1
php ×1
regex ×1
terminal ×1
uitableview ×1