Skip to content

Instantly share code, notes, and snippets.

@iNamik
iNamik / llrb.go
Created June 23, 2013 07:25
A base implementation of Robert Sedgewick's Left-Leaning Red-Black Tree (LLRB), written in Go (GOLANG). LLRB Trees are a variant of red-black trees with the aim of reducing the complexity of Insert and Delete functionality. They are self-balancing, maintaining the balance characteristics of a 2-3 tree, while retaining the Get(Key) performance of…
/*
package llrb implements a Left-Leaning Red-Black Tree (2-3 Variant),
as described by Robert Sedgewick:
* http://www.cs.princeton.edu/~rs/talks/LLRB/RedBlack.pdf
* http://en.wikipedia.org/wiki/Left-leaning_red%E2%80%93black_tree
The goal of this implementation is a one-to-one correlation to the ideas
@tonyhb
tonyhb / main.go
Created June 20, 2013 00:19
Golang: Converting a struct to a map (to a url.Values string map)
package main
import (
"fmt"
"net/url"
"reflect"
"strconv"
)
type Person struct {
@luv2code
luv2code / ReadingChunked.go
Created June 18, 2013 17:37
resp.Body.Read(buf) always reads in spurts of 4K characters. I need it to be much smaller. so that the chunks come through immediately
resp, err := http.Get(url)
log.Printf("stream started: %s", url)
defer func () {
log.Printf("stream closing: %s", url)
resp.Body.Close()
}()
if err != nil {
panic(err)
}
@achun
achun / rpn.go
Last active December 6, 2019 11:06
Go 四则运算词法解析相关 由中缀表达式构建AST 逆波兰序列生成
//ReversePolishnotation,RPN
//逆波兰表达式相关
//lexer 是一个中缀数学四则计算表达式词法解析器
package rpn
import (
"errors"
)
type Token int
@epicserve
epicserve / redis_key_sizes.sh
Last active February 21, 2025 22:37
A simple script to print the size of all your Redis keys.
#!/usr/bin/env bash
# This script prints out all of your Redis keys and their size in a human readable format
# Copyright 2013 Brent O'Connor
# License: http://www.apache.org/licenses/LICENSE-2.0
human_size() {
awk -v sum="$1" ' BEGIN {hum[1024^3]="Gb"; hum[1024^2]="Mb"; hum[1024]="Kb"; for (x=1024^3; x>=1024; x/=1024) { if (sum>=x) { printf "%.2f %s\n",sum/x,hum[x]; break; } } if (sum<1024) print "1kb"; } '
}
@almeidap
almeidap / BaseDAO.scala
Last active March 25, 2023 12:26
DAO design for ReactiveMongo using JSONCollection and Play2 Scala JSON API (work in progress).
package core.dao
import scala.concurrent.Future
import play.api.Logger
import reactivemongo.core.commands.LastError
import reactivemongo.core.errors.DatabaseException
import core.db.MongoHelper
@ju-popov
ju-popov / timestamp.py
Last active April 7, 2021 16:09
Python DateTime / Timestamp Convertion
######################################################################
# CURRENT AWARE LOCAL DATETIME
######################################################################
from datetime import datetime
from tzlocal import get_localzone
local_tz = get_localzone()
local_dt = datetime.now(local_tz)
@rcrowley
rcrowley / grace.go
Last active March 1, 2023 16:06
Graceful stop in Go
package main
import (
"log"
"net"
"os"
"os/signal"
"sync"
"syscall"
"time"
@Homlean
Homlean / sso.js
Last active January 29, 2019 08:31
新浪sso登陆
/**
* ssologin.js
*/
function SSOController() {
var me = this; // use in private function
var updateCookieTimer = null;
var updateCookieTimeHardLimit = 1800; // 在该时间内不允许更新cookie,默认30分钟
var cookieExpireTimeLength = 3600 * 24; // cookie过期时间为24小时
var crossDomainForward = null ; // 广播操作完成后执行的动作
@wenLiangcan
wenLiangcan / M.bmp.py
Last active August 1, 2019 16:43
来自网络: 先将这个代码复制,粘帖为文本,然后改名字,文件后缀为 M.bmp 然后在终端执行$python M.bmp 不要关闭终端,他会根据你的机器配置在你的主文件夹里生成m.bmp(1500x1000)图片。
_ = (
255,
lambda
V ,B,c
:c and Y(V*V+B,B, c
-1)if(abs(V)<6)else
( 2+c-4*abs(V)**-0.4)/i
) ;v, x=1500,1000;C=range(v*x
);import struct;P=struct.pack;M,\
j ='<QIIHHHH',open('M.bmp','wb').write