Skip to content

Instantly share code, notes, and snippets.

@jemygraw
jemygraw / go_load_test.go
Last active May 9, 2016 04:02
load test for server
package main
import (
"flag"
"fmt"
"io"
"net/http"
"os"
"runtime"
"sync"
@jemygraw
jemygraw / qiniu_pfop.go
Created June 23, 2015 06:41
qiniu pfop command line tool
package main
import (
"flag"
"fmt"
"github.com/qiniu/api/auth/digest"
"github.com/qiniu/rpc"
"net/http"
)
@jemygraw
jemygraw / qetag_multi_cpu_usage.go
Created June 21, 2015 07:33
qetag multi cpu usage
package main
//THE ALGORITHM IS FROM HERE: https://github.com/qiniu/qetag
import (
"bytes"
"crypto/sha1"
"encoding/base64"
"fmt"
"io"
"os"
@jemygraw
jemygraw / swift_learn_06.swift
Created June 14, 2015 08:47
learn the iteration of the enum and basic struct knowledge
//struct is copied by value
enum Rank :Int{
case Ace = 1
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
case Jack, Queen, King
func desc() -> String{
switch self{
case .Ace:
@jemygraw
jemygraw / swift_learn_05.swift
Created June 14, 2015 08:31
learn about the swift type enum and its usage, hash value, raw value
//enum
enum Rank :Int{
case Ace = 1
case Two, Three, Four, Five, Six, Seven, Eight, Nine, Ten
case Jack, Queen, King
func desc() -> String{
switch self{
case .Ace:
@jemygraw
jemygraw / swift_learn_04.swift
Created June 14, 2015 07:54
learn about willSet and didSet, explore the class methods parameters usage
//willSet and didSet
class Shape{
var oldName :String
var newName :String
var name :String{
willSet{
self.oldName=name
self.newName=newValue
println("WillSet: old values is \(name), new values is \(newValue)")
}
@jemygraw
jemygraw / swift_learn_03.swift
Created June 14, 2015 07:13
basic class definition and function override
//define a class
class Shape{
var name :String
var numberOfSlides = 0
let pi :Float = 3.14
init(name :String){
self.name=name
}
@jemygraw
jemygraw / swift_learn_02.swift
Created June 14, 2015 06:41
learn about swift functions and closures
//overload of functions
func greet(name :String, day :String) -> String{
return "hello \(name), today is \(day)"
}
func greet(name :String) -> String{
return greet(name, "fuckday")
}
@jemygraw
jemygraw / swift_learn_01.swift
Last active August 29, 2015 14:23
swift learn example 01
//: Playground - noun: a place where people can play
import UIKit
let myWeight: Float = 4
println(myWeight)
var myWeight2 = 4
println(myWeight2)
@jemygraw
jemygraw / calc_sum_lines_of_int.c
Last active August 29, 2015 14:22
calculate the sum of lines of int in a file
#include<stdio.h>
#include<string.h>
int main(int argc, char *argv[])
{
long sum=0;
int num=0;
char *option;
while(scanf("%d",&num)!=EOF)
{
sum+=num;