Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@scturtle
scturtle / horspool.rs
Created July 13, 2016 07:27
horspool search algorithm in rust
fn horspool<T: Eq+Hash>(haystack: &[T], needle: &[T]) -> isize {
let hlen = haystack.len();
let nlen = needle.len();
if nlen == 0 { return 0 }
// jump table
let jmp: HashMap<&T, usize> = needle.iter().zip((1..nlen).rev()).collect();
let last = nlen - 1;
let mut j = 0;
while j <= hlen - nlen {
// search backward
@scturtle
scturtle / conda-leaves.py
Last active May 7, 2016 11:18
python packages which is not required by others (like `brew leaves`)
#!/usr/bin/env python3
import os
import json
import glob
import subprocess
files = glob.glob(os.path.expanduser('~/miniconda3/pkgs/cache/*.json'))
deps = {}
for f in files:
j = json.load(open(f))
@scturtle
scturtle / proxy.py
Last active June 22, 2020 21:51
use opera's built-in VPN as proxy
#!/usr/bin/env python3
import asyncio
from vpn import get_proxy
proxy = port = auth = None
pool = asyncio.Queue(5)
psize = 0
async def process_client(client_reader, client_writer, *, CHUNK=4096):
global psize
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@scturtle
scturtle / depoly.py
Created April 7, 2016 04:13
auto depolyment and monitor based on github webhook
#!/usr/bin/env python3
import os
import time
import shlex
import bottle
import pprint
import subprocess
from threading import Thread
blue = lambda s: '\033[94m%s\033[0m' % s
@scturtle
scturtle / pygments.hs
Created March 31, 2016 11:21
hakyll use external pygments
customPandocCompiler :: Compiler (Item String)
customPandocCompiler =
let extraExtensions =
[ Ext_east_asian_line_breaks
, Ext_tex_math_double_backslash
]
customExtensions = foldr S.insert pandocExtensions extraExtensions
writerOptions = defaultHakyllWriterOptions {
writerExtensions = customExtensions
@scturtle
scturtle / tf.ipynb
Created February 19, 2016 11:35
multiclass classification using tensorflow
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@scturtle
scturtle / ContT.hs
Created January 26, 2016 15:37
Control.Monad.Trans.Cont
newtype ContT r m a = ContT { runContT :: (a -> m r) -> m r }
instance Functor (ContT r m) where
-- :: (a -> b) -> ContT r m a -> ContT r m b
fmap a2b ca = ContT $ \b2r -> runContT ca (b2r . a2b)
instance Applicative (ContT r m) where
-- :: a -> ContT r m a
pure a = ContT $ \a2r -> a2r a
-- :: ContT r m (a -> b) -> ContT r m a -> ContT r m b
@scturtle
scturtle / surfingkeys.js
Last active January 8, 2018 00:27
surfingkeys sucks
map('F', 'af');
map('gt', 'R');
map('gT', 'E');
map('<Ctrl-n>', 'R');
map('<Ctrl-p>', 'E');
mapkey('H', '#4Go back in history', function() { history.go(-1); }, {repeatIgnore: true});
mapkey('L', '#4Go forward in history', function() { history.go(1); }, {repeatIgnore: true});
map('d', 'x');
map('u', 'X');
map('I', '<Alt-s>');
@scturtle
scturtle / xfdown.py
Created December 21, 2015 07:08
QQDownload to aria2c
import sys
import json
import xmlrpc.client
import requests
from requests.utils import cookiejar_from_dict
def get_aria2(speed_limit=None):
aria2 = xmlrpc.client.ServerProxy('http://127.0.0.1:6800/rpc').aria2
while 1: