小编Ger*_*ens的帖子

为什么地址大小不同?(0x206a10 - 0x104382e0)

http://play.golang.org/p/BgnHN-GikU

var p1 = new(int)
var p2 *int = new(int)
var p3 = 0
var p4 *int

func main() {
    fmt.Println(*p1, &p1, p1)
    fmt.Println()
    fmt.Println(*p2, &p2, p2)
    fmt.Println()
    fmt.Println(p3, &p3)
    fmt.Println()
    fmt.Println(p4, &p4)
}
Run Code Online (Sandbox Code Playgroud)

0 0x206a10 0x104382e0

0 0x206a14 0x104382f0

0 0x21ccc0

<nil> 0x206a18

go

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

python webbrowser.open(url)

httpd = make_server('', 80, server)
webbrowser.open(url)
httpd.serve_forever()
Run Code Online (Sandbox Code Playgroud)

这是跨平台工作,除非我在putty ssh终端上启动它.如何在一个单独的进程中欺骗控制台打开w3m浏览器,以便它可以继续启动服务器?

或者,如果在没有x的shell上运行时无法跳过webbrowser.open?

python

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

片上无效的内存地址或无指针取消引用

为什么invalid memory address or nil pointer dereference跑步时问候给我?

type Response struct {
  Message string `json:"message"`
}

type ResponseList struct {
  Items []*Response `json:"items"`
}

func (gs *GreetingService) List(r *http.Request, req *Request, resp *ResponseList) error {
  greets := make([]*Response,2,2)
  greets[0].Message="hello"
  greets[1].Message="goodbye"
  resp.Items = greets
  return nil
}
Run Code Online (Sandbox Code Playgroud)

google-app-engine go google-cloud-endpoints

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

如何使用时间与js Date兼容

当我在js中定义这样的时间时

{expiry:new Date()}
Run Code Online (Sandbox Code Playgroud)

并像这样在go端点中创建一个struct

{Expiry time.Time `json:"expiry"`}
Run Code Online (Sandbox Code Playgroud)

我得到一个解析错误

"parsing time \"\"2006-01-02T15:04:05Z07:00\"\" as \"\"2006-01-02T15:04:05Z07:00\"\": cannot parse \"07:00\"\" as \"\"\""
Run Code Online (Sandbox Code Playgroud)

有什么建议?

javascript google-app-engine go google-cloud-endpoints

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

indexedDB openCursor 事务成功返回空数组

            req = db.openCursor();
            req.customerData=new Array() //[{a:1}]
            req.onsuccess = function(e) {
                var cursor = e.currentTarget.result;
                if (cursor) {
                    //console.log(cursor.value);
                    e.currentTarget.customerData.push(cursor.value);
                    e.currentTarget.customerData.push("hello?");         
                    cursor.continue()
                }
                else {
                    console.log(e.currentTarget.customerData) //this always correct
                }
            }

     console.log(req.customerData); //outside the onsuccess everything is gone?
Run Code Online (Sandbox Code Playgroud)

console.log(req);

当我在 chrome 控制台中打开对象时,我可以看到 customerData

console.log(req.customerData);

但是当我执行上述操作时它是空的?

替换new Array()[{a:1}]

console.log(req.customerData);

我可以看到a其他物体

但后来又

console.log(req.customerData[0].a);

工作,其他对象消失了。

如何保存客户数据?我尝试只推送数字或文本,但在交易完成后同样如此。我不能把数据取出来只能在交易过程中在 console.log() 上显示?

我知道它一定是通过引用过去的,但是我输入的每个变量都消失了?

在下面添加了完整示例,只需在控制台中键入 write() 和 read()

    <script>
        var iDB
        ready=function(){
            var request = indexedDB.open("my-database",1);
            request.onupgradeneeded = function(e) {
                var db = e.currentTarget.result …
Run Code Online (Sandbox Code Playgroud)

javascript indexeddb

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

为什么http.Get导致两个请求而不是一个?

创建一个测试文件./bower_components/index.html,并运行go test./.

为什么以下打印两行而不是第一行?

./bower_components/index.html                                                  
./bower_components/
Run Code Online (Sandbox Code Playgroud)

输出:

=== RUN   TestRootHandler                                                      
./bower_components/index.html                                                  
./bower_components/             ???                                            
--- PASS: TestRootHandler (0.00s)                                              
        main_test.go:32: 200 - ./bower_components/Hello World.html             
PASS                                                                           
ok
Run Code Online (Sandbox Code Playgroud)

码:

// RootHandler for HTTP
func RootHandler(root string, h http.Handler) http.Handler {
    return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
        _, err := os.Open(root + r.URL.Path)
        if err != nil {
            fmt.Println(err.Error())
            h.ServeHTTP(w, r)
            return
        }
        fmt.Println(root + r.URL.Path)
        r.URL.Path = root + r.URL.Path
        h.ServeHTTP(w, r)
    })
}

// TestRootHandler
func TestRootHandler(t *testing.T) …
Run Code Online (Sandbox Code Playgroud)

testing http go server

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

派生实例Eq(Sink p)

class  Eq a  where
    (==), (/=)           :: a -> a -> Bool
    x /= y               = not (x == y)
    x == y               = not (x /= y)

deriving instance Eq Bool
Run Code Online (Sandbox Code Playgroud)

我认为它会产生

instance Eq Bool where
    True == True = True
    False == False = True
Run Code Online (Sandbox Code Playgroud)

但是如何从类似的东西创建一个实例

newtype Sink p = Sink {unSink :: MVar (E.Iteratee (Message p) IO ())}

instance Eq (Sink p) where
 ?==? = True
Run Code Online (Sandbox Code Playgroud)

我只是使用派生而ghc会弄清楚自己吗?

deriving instance Eq (Sink p)
Run Code Online (Sandbox Code Playgroud)

http://hackage.haskell.org/packages/archive/websockets/0.7.0.0/doc/html/src/Network-WebSockets-Monad.html#Sink

PS我读过这篇文章,但它超出了我的理解能力 http://www.haskell.org/ghc/docs/7.6.1/html/users_guide/deriving.html

haskell

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

PreferenceFragment NullPointerException

public class MyPrefs extends PreferenceActivity {

    public static class MyPreferenceFragment extends PreferenceFragment
    {
        @Override
        public void onCreate(final Bundle savedInstanceState)
        {
            super.onCreate(savedInstanceState);
            addPreferencesFromResource(R.xml.preferences);
        }
    }

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MyPreferenceFragment frag =  new MyPreferenceFragment();

        getFragmentManager().beginTransaction().replace(android.R.id.content, frag).commit();

        Preference pref;
        pref = frag.findPreference("pref_gps_updates");

        pref.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {
            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                return true;
            }
        });

    }
}
Run Code Online (Sandbox Code Playgroud)

Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.preference.Preference.setOnPreferenceChangeListener(android.preference.Preference$OnPreferenceChangeListener)' on a null object reference

我不明白为什么会发生此崩溃或我做错了什么?

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen …
Run Code Online (Sandbox Code Playgroud)

java android

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