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
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char *argv[]) {
// 看起来你是在x86_64上来跑的, int为4-bytes, 此时内存布局为:
//
// a[0]
// ↓
// 96000000 fa000000 5e010000 c2010000
int a[4] = {150, 250, 350, 450};
@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])
#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) {
package main
import (
"time"
)
type InfohashIPType uint64
func main() {
table := make(map[InfohashIPType]struct{}, 100000000)
package main
import (
"time"
)
type InfohashIPType [2]uint64
func main() {
table := make(map[InfohashIPType]struct{}, 100000000)
// index.html
<html>
<head>
</head>
<body>
<%@ body { %>
<% } %>
</body>
</html>
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
// Router implements http router.
type Router struct {
//...
}
// RegisterHandler registers handler to the router.
func (router *Router) RegisterHandler(method, path string, handler http.HandlerFunc) {
}
@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()
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"])]