Skip to content

Instantly share code, notes, and snippets.

@dannvix
dannvix / shooter-subdl.py
Last active February 26, 2016 12:19
command-line downloader for shooter.cn subtitles
#!/usr/bin/env python
import os
import re
import md5
import sys
import json
import urllib
import urllib2
try:
@dannvix
dannvix / hamming.py
Last active August 29, 2015 14:10
Hamming distance implementation benchmark
#!/usr/bin/env python
# ref. https://medium.com/on-coding/shorter-code-is-inconsiderate-41cce917b51b
import timeit
setup = '''
def hamming_fp(a, b):
return sum(x != y for x, y in map(None, a, b))
def hamming(s1, s2):
hamming_number = 0
@dannvix
dannvix / PocketWebCustomization.user.js
Last active February 12, 2018 05:46
Customization/Simplification for Pocket Web
// ==UserScript==
// @name Pocket Web Customized
// @description Cusotmizations/Simplifications for Pocket Web
// @namespace http://getpocket.com
// @author Shao-Chung Chen
// @license MIT (http://opensource.org/licenses/MIT)
// @version 1.9.1
// @include http://getpocket.com/*
// @include https://getpocket.com/*
//
@dannvix
dannvix / PTTWebAutoAIDLink.user.js
Last active November 6, 2018 15:00
自動為 PTT 網頁版的文章代碼加上連結的 userscript
@dannvix
dannvix / BypassPTTOver18.user.js
Last active November 13, 2017 01:07
自動跳過 PTT 的分級檢查 (請謹慎使用)
// ==UserScript==
// @name Bypass PTT Over-18 Checking
// @description 自動跳過 PTT 的分級檢查 (請謹慎使用)
// @namespace https://www.ptt.cc/bbs
// @author Shao-Chung Chen
// @license MIT (http://opensource.org/licenses/MIT)
// @version 1.1.0
// @include http://www.ptt.cc/*
// @include https://www.ptt.cc/*
//
#include <iostream>
template <typename lhs_t, typename func_t>
inline func_t operator > (lhs_t const &lhs, func_t rhs) {
return rhs;
}
template <typename rhs_t, typename func_t>
inline auto operator < (func_t const &lhs, rhs_t const &rhs) -> decltype(lhs())
{
@dannvix
dannvix / ext_id.cpp
Last active August 29, 2015 14:15
Clang 3.3+ supports extended identifiers
// clang++ hello.cpp
#include <iostream>
template <typename lhs_t, typename rhs_t>
inline int operator, (lhs_t lhs, rhs_t b) {
std::cout << "飲冰室茶集" << std::endl;
return 0;
}
template <typename lhs_t, typename rhs_t>
@dannvix
dannvix / member_function_reflection.cpp
Last active August 29, 2015 14:16
SFINAE test for specific member function using C++11
#include <iostream>
#include <type_traits>
class Foo {
public:
int ToString();
};
class Bar {
public:
@dannvix
dannvix / bitset.js
Last active August 29, 2015 14:17
Very simple bitset operations in JavaScript
/* bitset.js
*
* bitset = new Bitset(64);
* bitset.toString(); // "0000000000000000000000000000000000000000000000000000000000000000"
* bitset.setBit(48, 1).setBit(23, 1).setBit(52, 1);
* bitset.toString(); // "0000000000010001000000000000000000000000100000000000000000000000"
* bitset.toInt(); // 4785074612469760
*
* bitset.fromInt(679642164705874);
* bitset.toString(); // "0000000000000010011010100010000110000101110011010011101001010010"
@dannvix
dannvix / screenshot.js
Created April 12, 2015 10:08
Simply capture web-page screenshot with PhantomJS
#!/usr/bin/env phantom
var webpage = require("webpage"),
system = require("system");
var args = system.args;
if (args.length < 3) {
system.stderr.writeLine("usage: " + args[0] + " <URL> <Filename.png> [delay] [viewWidth] [viewHeight]");
phantom.exit();
}