Skip to content

Instantly share code, notes, and snippets.

View shiyanhui's full-sized avatar
:octocat:
Happy Coding!

Lime shiyanhui

:octocat:
Happy Coding!
  • Beijing, China
View GitHub Profile
def gen_func1(n):
for i in range(n):
callback = lambda i=i: i
yield callback
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"])]
@shiyanhui
shiyanhui / http.go
Last active December 14, 2016 11:53
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()
// Router implements http router.
type Router struct {
//...
}
// RegisterHandler registers handler to the router.
func (router *Router) RegisterHandler(method, path string, handler http.HandlerFunc) {
}
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
// index.html
<html>
<head>
</head>
<body>
<%@ body { %>
<% } %>
</body>
</html>
package main
import (
"time"
)
type InfohashIPType [2]uint64
func main() {
table := make(map[InfohashIPType]struct{}, 100000000)
package main
import (
"time"
)
type InfohashIPType uint64
func main() {
table := make(map[InfohashIPType]struct{}, 100000000)
#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) {
@shiyanhui
shiyanhui / oa.py
Last active December 9, 2020 04:58
# 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])