Skip to content

Instantly share code, notes, and snippets.

@1000copy
1000copy / btree.py
Created February 26, 2014 06:47 — forked from teepark/btree.py
import bisect
import itertools
import operator
class _BNode(object):
__slots__ = ["tree", "contents", "children"]
def __init__(self, tree, contents=None, children=None):
self.tree = tree
@1000copy
1000copy / testing_test.go
Last active August 29, 2015 13:59
基于约定,优美,简洁的 go testing framework吗。
package main
import (
"testing"
"time"
)
func sum(n ...int) int {
var c int
for _, i := range n {
c += i
}
@1000copy
1000copy / go_oo_demo.go
Last active August 29, 2015 13:59
go oo 。一点肥肉也没有的骨干。作者显然是一个喜欢手打代码,不用ide的人。
// Why so thin ?
//
// function - func
// semicolor no required
// struct new easy : o := Owner{id:1,name:"lcj"}
// define var so easy :o := Owner{id:1,name:"lcj"}
// if () ,() no required
// type cast with (type),.(int) etc
// go 的struct,传值,在函数内修改的,只是堆栈上的副本,改了是无法影响函数之外的。
// 不容易发生深层嵌套。就像c# 那么,namespace / class /function ,至少三层。而go,member function 总是一层
import (
"time"
)
// 时间格式化字符串(奇葩的设置)
const TimeFormat = "2006-01-02 15:04:05"
const TimeFormat1 = "2006-01-02"
func TestXYZ(t *testing.T) {
r1,_:=time.Parse(TimeFormat1,"2014-04-11")
package main
/*
#include <stdlib.h>
*/
import "C"
import ("fmt")
func Random() int {
return int(C.random())
}
package main
import (
"fmt" ; "container/list"
"time"
"errors"
)
type rect struct {
width, height int
}
package main
import ("fmt"
// "math"
)
const max =8
func main(){
q := Queen{sum:0}
q.put(0)
/* Code by Slyar
http://www.slyar.com/blog/eight-queen-c-program.html*/
#include <stdio.h>
#include <stdlib.h>
#define max 8
int queen[max], sum=0; /* max为棋盘最大坐标 */
@1000copy
1000copy / cyrillic.html
Created April 27, 2014 13:15
cyrillic char c
<!DOCTYPE html>
<html>
<body>
<p id="demo">Click the button to decode a URI after encoding it.</p>
<button onclick="myFunction()">Try it</button>
<script>
function myFunction()
@1000copy
1000copy / uri.js
Last active August 29, 2015 14:00
//外部可见的函数 "encodeURI", 内部实现为URIEncode,对应关系在最后一个函数内
// Copyright 2006-2008 the V8 project authors. All rights reserved.
// -------------------------------------------------------------------
// This file contains support for URI manipulations written in
// JavaScript.
// Lazily initialized.
var hexCharArray = 0;
var hexCharCodeArray = 0;