Skip to content

Instantly share code, notes, and snippets.

@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

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 / 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 / ghost_foot.html
Last active November 15, 2015 05:37
http://blog.rainy.im is using ghost, {{ghost_foot}} injection was used to append donate button to every article.
<script type='tmpl' class='donation'>
<pre>
<code class="language-javascript">
if(post.content.isHelpful){
$("button#donate").click();
};
</code>
</pre>
<button
type="button"
@rainyear
rainyear / Hspell.hs
Last active November 7, 2015 08:19
Spell corrector
import Data.Char (toLower)
import qualified Data.Map as Map -- (insertWith, empty, member)
import qualified Data.Set as Set -- (fromList, toList, union, unions)
main :: IO ()
main = do
fileStr <- readFile "big.txt"
let training = words $ toLower <$> fileStr
let knowledge = foldl (\m word -> Map.insertWith (+) word 1 m) Map.empty training
@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 / 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 / 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 / ang2pix.js
Last active August 29, 2015 14:22
Visual Angle.
// cal Pix size with given visual angle and screen info.
var scr = {
xpixels: 1024,
ypixels: 768,
width: 360, //mm
height: 270, //mm
}
var ang2pix = function(screen, angle, distense){
var targetWidth = angle.h * distense / (180 / 3.14);
@rainyear
rainyear / cropBottomByX.m
Last active August 29, 2015 14:20
processing all jpg images from path <src> , crop <x> pixels from bottom, save to <dest>.
function cropBottomByX(src, dest, x)
srcImgs = [dir([src filesep '*.jpg'])];
for i = 1:length(srcImgs)
imgLocation = [src filesep srcImgs(i).name];
img = imread(imgLocation);
[h, w, d] = size(img);
disp(sprintf('Resizing image %s from %d to %d ...\n', srcImgs(i).name, h, h-x));
img2 = img(1:h-x, :, :);
imwrite(img2, [dest filesep srcImgs(i).name]);