Skip to content

Instantly share code, notes, and snippets.

@jokaye
jokaye / singleflight.go
Created May 9, 2019 07:38
#singleflight
package main
import "sync"
type call struct {
wg sync.WaitGroup
val interface{}
err error
result []chan
func shrinkstack(gp *g) {
gstatus := readgstatus(gp)
if gstatus&^_Gscan == _Gdead {
if gp.stack.lo != 0 {
// Free whole stack - it will get reallocated
// if G is used again.
stackfree(gp.stack, gp.stackAlloc)
gp.stack.lo = 0
gp.stack.hi = 0
gp.stkbar = nil
// Called from runtime·morestack when more stack is needed.
// Allocate larger stack and relocate to new stack.
// Stack growth is multiplicative, for constant amortized cost.
//
// g->atomicstatus will be Grunning or Gscanrunning upon entry.
// If the GC is trying to stop this g then it will set preemptscan to true.
//
// ctxt is the value of the context register on morestack. newstack
// will write it to g.sched.ctxt.
func newstack(ctxt unsafe.Pointer) {
/*
Copyright 2013 Google Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
package sign
import (
"crypto/hmac"
"crypto/sha1"
"encoding/base64"
"net/http"
"strings"
"time"
)
func XmlToMap(r io.Reader, root string) map[string]string {
// result
m := make(map[string]string)
// the current value stack
values := make([]string, 0)
// parser
p := xml.NewDecoder(r)
for token, err := p.Token(); err == nil; token, err = p.Token() {
switch t := token.(type) {
case xml.CharData:
// An implementation of Consistent Hashing and
// Consistent Hashing With Bounded Loads.
//
// https://en.wikipedia.org/wiki/Consistent_hashing
//
// https://research.googleblog.com/2017/04/consistent-hashing-with-bounded-loads.html
package consistent
import (
"errors"
@jokaye
jokaye / golang_job_queue.md
Created April 27, 2017 07:23 — forked from harlow/golang_job_queue.md
Job queues in Golang
from django.contrib.auth.models import User
from django.contrib.auth.hashers import make_password
from tastypie.authentication import (
Authentication, ApiKeyAuthentication, BasicAuthentication,
MultiAuthentication)
from tastypie.authorization import Authorization
from tastypie.resources import ModelResource
from tastypie import fields
#!/usr/bin/env python
#coding=utf-8
import random
import Image, ImageDraw, ImageFont, ImageFilter
  
_letter_cases = "abcdefghjkmnpqrstuvwxy" # 小写字母,去除可能干扰的i,l,o,z
_upper_cases = _letter_cases.upper() # 大写字母
_numbers = ''.join(map(str, range(3, 10))) # 数字
init_chars = ''.join((_letter_cases, _upper_cases, _numbers))
fontType="/usr/share/fonts/truetype/freefont/FreeSans.ttf"