Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@rainyear
rainyear / hammerspoon.init.lua
Last active October 31, 2022 00:48
hammerspoon.init.lua
local hyper = {'shift', 'cmd'}
local hyper2 = {'ctrl', 'cmd'}
-- hyper + up maximize the current window
hs.hotkey.bind(hyper, 'up', function()
hs.grid.maximizeWindow()
end)
hs.hotkey.bind(hyper, "Left", function()
local win = hs.window.focusedWindow()
local f = win:frame()
@rainyear
rainyear / handy.py
Created July 3, 2015 10:09
Hand posture detection with OpenCV.
#!/usr/bin/env python
import cv2
import numpy as np
def main():
cap = cv2.VideoCapture(0)
while(cap.isOpened()):
ret, img = cap.read()
skinMask = HSVBin(img)
@rainyear
rainyear / miller-rabin.scm
Last active March 12, 2021 13:20
Miller-Rabin & RSA in Scheme.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Source codes of blog post: ;
; http://blog.rainy.im/2015/08/27/miller-rabin-rsa/ ;
; Scheme runtime: Calysto Scheme ;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; math procedures
(define (square x) (* x x))
(define (even? x) (= (remainder x 2) 0))
@rainyear
rainyear / .tmux.conf
Created September 26, 2019 02:47 — forked from tsl0922/.tmux.conf
vim style tmux config
# use C-a, since it's on the home row and easier to hit than C-b
set-option -g prefix C-a
unbind-key C-a
bind-key C-a send-prefix
set -g base-index 1
# Easy config reload
bind-key R source-file ~/.tmux.conf \; display-message "tmux.conf reloaded."
# vi is good
@rainyear
rainyear / sqlite_truncate_cmd.sql
Last active October 19, 2017 15:13
TRUNCATE TABLE for sqlite.
delete from `TABLE`;
select * from sqlite_sequence;
update sqlite_sequence set seq=0 where name=`TABLE`;

Keybase proof

I hereby claim:

  • I am rainyear on github.
  • I am yusheng (https://keybase.io/yusheng) on keybase.
  • I have a public key ASAkSGe1LXL2CRP8ZzWxzmwzsRxTuUQZwhgZlHaxAZqg9Ao

To claim this, I am signing this object:

@rainyear
rainyear / lispy.py
Last active August 4, 2017 17:51 — forked from mnicky/lispy.py
################ Scheme Interpreter in Python
## (c) Peter Norvig, 2010; See http://norvig.com/lispy2.html
################ Symbol, Procedure, classes
from __future__ import division
import re, sys, StringIO
class Symbol(str): pass
@rainyear
rainyear / countdown
Last active June 28, 2016 01:08
javascript countdown
// set the date we're counting down to
var target_date = new Date("Aug 15, 2019").getTime();
// variables for time units
var days, hours, minutes, seconds;
// get tag element
var countdown = document.getElementById("countdown");
// update the tag with id "countdown" every 1 second
@rainyear
rainyear / Mapwalk.py
Last active January 1, 2016 23:19
map a command(function) to all the files in current directory.
#!/usr/bin/env python
#-*- coding:utf-8 -*-
"""
Walking the destination directory(arg3) and using the command(arg2)
to process every file.
USAGE:
Mapwalk `function` /path/to/walk
"""
import sys
@rainyear
rainyear / extract_data.m
Created December 14, 2013 12:16
Using the Ci_up as the threshold, the diagnostic proportions ( >= Ci_up ) were replaced with 1 and the nondiagnostic proportions( < Ci_up ) were replaced with 0, and then I got a binary diagnosticPlane, and the antidiagnostiPlane were obtained by replacing the diagnostic proportions with 0, and nondiagnostic proportions with 1.
DEBUG = 1;
namePat = 'gender_backup-%d.mat';
numSubjects = 16;
nLevels = 5;
Ci_up = [0.6914 0.6855 0.6728 0.6404 0.6228]; % upper confidence internal for 5 scale
allProportion = zeros(256,256,5,numSubjects);