Skip to content

Instantly share code, notes, and snippets.

View harryhare's full-sized avatar

harryhare harryhare

View GitHub Profile
@harryhare
harryhare / file_lock.cpp
Created November 8, 2018 04:13
use fcntl to lock file interactively
#include <iostream>
#include <dirent.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/file.h>
#include <errno.h>
#include "util.h"
#include <vector>
@harryhare
harryhare / mooncake.js
Created November 6, 2018 10:26
传说中的抢月饼代码
/*
作者:leon lee
链接:https://zhuanlan.zhihu.com/p/22644277
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
*/
setInterval(function() {
if(Date.now() >= new Date("2016-09-12 15:59:00")) {
$("#seckillQuantity").val(1);//1盒
$(".buyButtons.J_buyButtons").click();//抢购按钮
@harryhare
harryhare / time.py
Created August 1, 2018 07:15
time function in python practice
import time
target=int("1530608884")
now=int(time.time())
print(target-now)
@harryhare
harryhare / entropy_huffman.py
Created July 22, 2018 05:15
entropy and length of huffman coding
import math
def entropy(a):
s=sum(a)
e=0
for x in a:
p=x/s
e+=(p)*math.log2(p)
return -e
@harryhare
harryhare / delete_unfinished_multipart_upload.py
Last active August 1, 2018 07:16
Multipart API of AWS S3
#!/bin/python
import os
import json
bucket_name="your_bucket_name"
output = os.popen('aws s3api list-multipart-uploads --bucket %s'%(bucket_name))
package main
import (
"golang.org/x/tour/pic"
"image"
"image/color"
)
type Image struct{}
func (i Image)Bounds() image.Rectangle{
package main
import (
"golang.org/x/tour/tree"
"fmt"
)
// Walk walks the tree t sending all values
// from the tree to the channel ch.
func Walk(t *tree.Tree, ch chan int){
@harryhare
harryhare / exercise-web-crawler.go
Last active September 5, 2024 19:39
Solution to Exercise: Web Crawler https://tour.golang.org/concurrency/10
package main
import (
"fmt"
"time"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and