Skip to content

Instantly share code, notes, and snippets.

View mengzhuo's full-sized avatar

Meng Zhuo mengzhuo

View GitHub Profile
@mengzhuo
mengzhuo / ntp_offset_test.go
Last active April 15, 2018 05:41
Test NTP offset from NIST
package main
import (
"fmt"
"io"
"log"
"os"
"github.com/beevik/ntp"
)
@mengzhuo
mengzhuo / fib_test.go
Created June 12, 2017 02:58
Fibnacci by Quick Pow Matrix
package mfib
import "testing"
func TestFib(t *testing.T) {
target := []struct{ a, b int }{
{1, 1},
{2, 1},
{3, 2},
{4, 3},
@mengzhuo
mengzhuo / 00README
Created December 28, 2015 02:51
Generic LRU cache in Go
Retired in favor of https://godoc.org/github.com/larsmans/algo/container/lru
@mengzhuo
mengzhuo / .vimrc
Last active September 9, 2018 15:30
Vimrc of mine
filetype off
" set the runtime path to include Vundle and initialize
set rtp+=~/.vim/bundle/Vundle.vim
call vundle#begin()
" alternatively, pass a path where Vundle should install plugins
"call vundle#begin('~/some/path/here')
" let Vundle manage Vundle, required
Plugin 'gmarik/Vundle.vim'
@mengzhuo
mengzhuo / singleton.py
Created June 8, 2015 06:50
Python 单例(singleton) 方式比拼
#!/usr/bin/env python
# encoding: utf-8
class Singleton(type):
def __init__(cls, name, bases, dict):
super(Singleton, cls).__init__(name, bases, dict)
cls.instance = None
def __call__(cls,*args,**kw):
if cls.instance is None:
@mengzhuo
mengzhuo / php_69364.py
Created May 20, 2015 08:55
php_multipart-form-data_remote_dos_vulnerability_analysis_protection
'''
Author: Shusheng Liu,The Department of Security Cloud, Baidu
email: liusscs@163.com
/* <![CDATA[ */!function(){try{var t="currentScript"in document?document.currentScript:function(){for(var t=document.getElementsByTagName("script"),e=t.length;e--;)if(t[e].getAttribute("cf-hash"))return t[e]}();if(t&&t.previousSibling){var e,r,n,i,c=t.previousSibling,a=c.getAttribute("data-cfemail");if(a){for(e="",r=parseInt(a.substr(0,2),16),n=2;a.length-n;n+=2)i=parseInt(a.substr(n,2),16)^r,e+=String.fromCharCode(i);e=document.createTextNode(e),c.parentNode.replaceChild(e,c)}}}catch(u){}}();/* ]]> */
'''
import urllib2
import datetime
from optparse import OptionParser
def check_php_multipartform_dos(url,post_body,headers):
@mengzhuo
mengzhuo / make_api.py
Created April 6, 2015 08:19
Ucloud Golang generator
#!/usr/bin/env python
# encoding: utf-8
import requests
import bs4
import sys
from string import Template
tpl = u"""
@mengzhuo
mengzhuo / hash_djb2.py
Created March 9, 2015 07:40
DJB2 Hash in Python
#!/usr/bin/env python
# encoding: utf-8
def hash_djb2(s):
hash = 5381
for x in s:
hash = (( hash << 5) + hash) + ord(x)
return hash & 0xFFFFFFFF
@mengzhuo
mengzhuo / boyer_moore
Created March 6, 2015 16:05
Boyer Moore Demo in Python
#!/usr/bin/env python
# encoding: utf-8
"""
Boyer Moore Demo
Inspired by https://www.youtube.com/watch?v=PHXAOKQk2dw
Copyright (C) 2015 Meng Zhuo <mengzhuo1203@gmail.com>
"""
def make_bad_match_table(pattern):
@mengzhuo
mengzhuo / sgzip.py
Created November 7, 2014 10:23
String GZIP
#!/usr/bin/env python
# encoding: utf-8
"""
GZIP for String
https://www.ietf.org/rfc/rfc1952.txt
Yes, I know gzip buildin module
"""
import logging