Skip to content

Instantly share code, notes, and snippets.

@dannvix
dannvix / PTTWebAutoAIDLink.user.js
Last active November 6, 2018 15:00
自動為 PTT 網頁版的文章代碼加上連結的 userscript
@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 / 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 / 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 / cpp11-type-traits.cpp
Last active August 29, 2015 14:09
Playing with C++11 type traits and templates
#include <iostream>
#include <iterator>
#include <vector>
#include <set>
// overload for all STL containers
template <
typename T,
typename = typename std::enable_if <
std::is_convertible<
@dannvix
dannvix / dmhy-magdl.py
Last active March 19, 2018 14:59
Command-line downloader (via magnet link) for share.dmhy.org
#!/usr/bin/env python
# encoding: utf-8
# dmhy-magdl.py -- command-downloader for share.dmhy.org
import sys
import urllib
import urllib2
from datetime import datetime, timedelta
import webbrowser
import xml.etree.ElementTree as ElementTree
@dannvix
dannvix / list-more-than-2-files.sh
Last active August 29, 2015 14:07
List all directories that contain >= 2 files/directories
#!/bin/sh
# dependencies: find, grep, sort, uniq, awk
echo 'List all files...'
find $1
# output:
# a
# a/b
# a/b/c
# a/b/c/d
@dannvix
dannvix / yyets-subdl.py
Last active November 6, 2022 09:24
YYeTs (人人影视) 雙語字幕下載器
# Moved to https://github.com/dannvix/yyets-subdl
import webbrowser
webbrowser.open('https://github.com/dannvix/yyets-subdl')
@dannvix
dannvix / django-JsonResponse.py
Last active March 31, 2022 06:44
Custom Django JsonResponse which supports datetime.datetime serialization
# project/forum/views.py
import json
from datetime import datetime
from django.http import HttpResponse
from django.shortcuts import get_object_or_404
from django.forms.models import model_to_dict
from forum.models import Post
@dannvix
dannvix / django-models-record-status-history-mixin.py
Last active August 29, 2015 14:04
Django models RecordStatusHistoryMixin (pre_save hook)
from django.db import models
from jsonfield import JSONField
from dirtyfields import DirtyFieldsMixin
import time
class RecordStatusHistoryMixin(DirtyFieldsMixin):
def save(self, *args, **kwargs):
if not self.pk:
# first create
current_time = int(time.time())