This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gen_func1(n): | |
for i in range(n): | |
callback = lambda i=i: i | |
yield callback |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import itertools | |
t1 = [{"id": 1, "abc": "2"}, {"id": 1, "abc": "3"}, {"id": 2, "abc": "2"}] | |
print [{"id": k, "abc": (lambda v: [item["abc"] for item in v] if len(v) > 1 else v[0]["abc"])(list(group))} for k, group in itertools.groupby(t1, lambda item: item["id"])] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
// how we start a http server | |
http.HandleFunc("/user", handler) | |
http.ListenAndServe(":8080", nil) | |
} | |
// src/net/http/server.go | |
func ListenAndServe(addr string, handler Handler) error { | |
server := &Server{Addr: addr, Handler: handler} | |
return server.ListenAndServe() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Router implements http router. | |
type Router struct { | |
//... | |
} | |
// RegisterHandler registers handler to the router. | |
func (router *Router) RegisterHandler(method, path string, handler http.HandlerFunc) { | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type ServeMux struct { | |
mu sync.RWMutex | |
m map[string]muxEntry | |
hosts bool // whether any patterns contain hostnames | |
} | |
type muxEntry struct { | |
explicit bool | |
h Handler | |
pattern string |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// index.html | |
<html> | |
<head> | |
</head> | |
<body> | |
<%@ body { %> | |
<% } %> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"time" | |
) | |
type InfohashIPType [2]uint64 | |
func main() { | |
table := make(map[InfohashIPType]struct{}, 100000000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"time" | |
) | |
type InfohashIPType uint64 | |
func main() { | |
table := make(map[InfohashIPType]struct{}, 100000000) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define csp_without_prefix | |
#include <stdio.h> | |
#include <libcsp/csp.h> | |
chan_declare(mm, int, int); | |
chan_define(mm, int, int); | |
proc void select1(chan_t(int) *chn, chan_t(int) *chn2) { | |
while (true) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Time: O(max(len(arr), max(arr))) | |
# Space: O(N) | |
import collections | |
def common(arr1, arr2): | |
if not arr1 or not arr2: | |
return [] | |
c1, c2 = map(collections.Counter, [arr1, arr2]) |
OlderNewer