Skip to content

Instantly share code, notes, and snippets.

View scturtle's full-sized avatar
🐢

scturtle

🐢
View GitHub Profile
@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:
@scturtle
scturtle / primes.rs
Last active December 12, 2015 16:22
#![feature(step_by, iter_arith)]
fn main() {
let n = 100000000;
let mut isprime = vec![true; n];
isprime[0] = false;
isprime[1] = false;
for i in (4..n).step_by(2) {
isprime[i] = false;
}
@scturtle
scturtle / weibo.py
Last active November 24, 2015 09:55
weibo black magic api from blacklight
from pprint import pprint
import os
import requests
import webbrowser
class Weibo:
def login(self):
if os.path.exists('weibo.token'):
@scturtle
scturtle / gist:15685020c01e4c5a8072
Last active July 8, 2017 13:21
ffmpeg cheatsheet
# https://support.twitter.com/articles/20172128?lang=en#video-formats
# https://trac.ffmpeg.org/wiki/Encode/H.264
# gif to mp4 for twitter
ffmpeg -i in.gif -pix_fmt yuv420p -vf crop="floor(in_w/2)*2:floor(in_h/2)*2" out.mp4
# extract part of video (-t duration)
ffmpeg -i in.mp4 -ss 00:00:00.000 -to 00:00:15.000 -vcodec copy -acodec copy part.mp4
# convert to mp4 for twitter
@scturtle
scturtle / server.py
Created November 15, 2015 10:42
naive coroutine implementation stolen from https://youtu.be/MCs5OvhV9S4
import socket
from collections import deque
from select import select
from concurrent.futures import ThreadPoolExecutor as Pool
def fib(n):
if n <= 2:
return 1
else:
@scturtle
scturtle / queens.hs
Created November 14, 2015 17:31
n queens for fun
import System.Environment
import qualified Data.IntSet as S
queens :: Int -> Int
queens n = queens' 0 S.empty S.empty S.empty
where queens' i cols diag1 diag2 =
if i == n then 1
else sum [queens' (i+1) (S.insert j cols)
(S.insert (j+i) diag1)
(S.insert (j-i) diag2)
@scturtle
scturtle / gevent.py
Last active February 19, 2022 09:12
Let's go HTTPS!
from gevent import monkey
monkey.patch_all()
import bottle
class SSLWebServer(bottle.ServerAdapter):
def run(self, handler):
from gevent.pywsgi import WSGIServer
srv = WSGIServer((self.host, self.port), handler,
certfile='/etc/letsencrypt/live/XXX/fullchain.pem',
@scturtle
scturtle / upload.py
Created November 4, 2015 13:09
upload to Dropbox for backup
#!/usr/bin/env python3
import re
import sys
from pathlib import Path
import dropbox
app_key = ''
app_secret = ''
access_token = ''
open Core.Std
let test_list =
[["language";"architect" ;"first release"];
["Lisp" ;"John McCarthy" ;"1958"];
["C" ;"Dennis Ritchie";"1969"];
["ML" ;"Robin Milner" ;"1973"];
["OCaml" ;"Xavier Leroy" ;"1996"]]
let make_seperator (widths : int list) : string =