Skip to content

Instantly share code, notes, and snippets.

View hghwng's full-sized avatar

Hugh Wang hghwng

  • Beijing, China
  • 08:16 (UTC +08:00)
View GitHub Profile
@hghwng
hghwng / dnuke.c
Created April 11, 2015 14:40
Darwin Nuke PoC
/*
* Darwin Nuke PoC
* (C) 2015 Hugh Wang
* Licence: MIT
*
* Original research: https://sourceware.org/ml/ecos-discuss/2009-04/msg00031.html
* With the help from Kaspersky: https://securelist.com/blog/69462/darwin-nuke/
*
*/
@hghwng
hghwng / shapley-shubik.cc
Created June 9, 2015 04:47
Shapley-Shubik Power Index Calculator
#include <iostream>
#include <sstream>
#include <vector>
#include <algorithm>
using namespace std;
using Num = long long;
using Array = vector<Num>;
Num math_combination(Num total, Num select)
{
@hghwng
hghwng / fsa.py
Created June 9, 2015 04:49
FSA for Speech and Language Processing 2, 2-3
#!/bin/env python3
g_dbg = False
g_rule = {}
def print_state(state, text):
print('\t[', end='')
for i in state['pre']:
print('{} -> '.format(i), end='')
print('{}] '.format(state['tag']), end='')
@hghwng
hghwng / Booth.cc
Created November 30, 2015 11:30
Booth's Algorithm Step by Step
#include <iostream>
using namespace std;
using uint = unsigned int;
constexpr uint kLength = 6;
constexpr uint kHighBit = 1 << (kLength - 1);
constexpr uint kTrim = ((1 << (kLength)) - 1);
inline void print_binary(uint v) {
for (uint i = 1 << (kLength - 1); i != 0; i >>= 1) {
cout << ((v & i) ? 1 : 0);
@hghwng
hghwng / coroutine.cc
Created December 15, 2015 09:34
Coroutine lib and demo
#include <iostream>
#include <algorithm>
#include <string>
#include <stack>
using namespace std;
// coroutine start
#define _cr_cntr_start constexpr int _counter_start_val = __COUNTER__
#define _cr_cntr_next (__COUNTER__ - _counter_start_val)
@hghwng
hghwng / pocket.pentadactylrc
Created February 23, 2016 01:22
Add page to Pocket in Pentadactyl.
"" Pocket
map a :pocket<CR>
js <<EOF
group.commands.add(["pocket"],
"Add to Pocket",
function(args) {
let url = args.length === 0 ? buffer.uri.spec : args[0];
@hghwng
hghwng / nowander.js
Last active April 16, 2016 12:21
No Wiki Wandering
// ==UserScript==
// @name No Wiki Wandering
// @name:zh-CN 阻止维基漫游
// @namespace hghwng
// @version 1
// @grant none
// @include *.wikipedia.org/wiki/*
// @description Prevent Wikipedia wandering. Show a dialog when you try to visit a new page, and the action is prevented. No wandering, more productivity!
// @description:zh-CN 防止维基百科漫游。在尝试访问新页面时弹框报警,并阻止加载。离开漫游,拥抱效率!
// ==/UserScript==
@hghwng
hghwng / convert_mobile_qq_stickers.py
Created June 2, 2016 10:43
Reconstruct GIF header from mobile QQ's stickers.
#!/usr/bin/env python3
from sys import argv
"""
Reconstruct GIF header from mobile QQ's stickers.
Get the stickers in /sdcard/Tencent/QQ*/.emotionsm/
"""
def convert_bytes(data):
@hghwng
hghwng / opmlconv.py
Created August 7, 2016 12:21
Convert Dynalist flavored OPML to Org Mode
#!/usr/bin/env python
import bs4
def convert_element(lines, level=1):
result = ''
for line in lines:
if not isinstance(line, bs4.element.Tag) or \
line.name != 'outline':
continue
@hghwng
hghwng / parse-week.el
Created September 6, 2016 03:07
Org mode: parse week with customizable start of week number
(with-eval-after-load 'org
(setq start-week 37)
(advice-add 'org-read-date-analyze :around
(lambda (original-fun ans org-def org-defdecode)
(funcall original-fun
(if (string-match "^s\\([0-9]+\\)\\(.*\\)" ans)
(concat "w"
(number-to-string (+ start-week
(string-to-number (match-string 1 ans))))
(match-string 2 ans))