Skip to content

Instantly share code, notes, and snippets.

@jemygraw
jemygraw / convert_qiniu_puttime_to_datetime_in_csharp
Created June 10, 2015 01:56
convert qiniu stat putTime to DateTime in c# code
public static DateTime putTime2DateTime(long putTime)
{
DateTime toDate = new DateTime(1970, 1, 1, 0, 0, 0, 0, System.DateTimeKind.Utc);
toDate = toDate.AddMilliseconds(putTime / 10000);
return toDate;
}
static void Main(string[] args)
{
DateTime d = putTime2DateTime(14334065462000336);
Console.WriteLine(d.ToLocalTime());
@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;
@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 / 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_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_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_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_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 / 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 / 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"
)