Skip to content

Instantly share code, notes, and snippets.

@dbalan
dbalan / grab_pre_ics.sh
Created July 7, 2016 06:58
Get screenshot from a pre ICS android.
#!/bin/bash
# works only with linux, depends on ffmpeg and android-tools installed.
# both `which ffmpeg` and `which adb` should return 0
set -e -x
if [[ $# != 1 ]]; then
echo "Usage: $0 filename.png"
exit 0
fi
module Expression where
import Text.ParserCombinators.Parsec
import Text.Parsec.Token
import Control.Monad.Error
data Expr = LispInt Integer |
LispSym String |
LispLi [Expr]
@dbalan
dbalan / xmonad.hs
Created June 3, 2016 09:23
Config for xmonad to play nice with gnome.
import XMonad
import XMonad.Config.Gnome
import XMonad.Util.Run
import XMonad.Util.EZConfig
-- rewrite the start progs
startProgs prgs = mapM_ (\(cmd,args) -> safeSpawn cmd args) prgs
initProgs = [ ("setxkbmap", ["-option", "ctrl:nocaps"])
, ("emacs", ["--daemon"])
import Data.List
longest :: [Int] -> Int
longest ns = maybe 0 id $ elemIndex m zeroCount
where
zeroCount = tail $ scanl (\x y -> if (y == 0) then x+1 else 0) 1 ns
m = maximum zeroCount
cycleAtPoint :: [Int] -> [Int]
cycleAtPoint ns = take (length ns) $ drop (1 + longest ns) $ cycle ns
@dbalan
dbalan / eroset.hs
Created March 13, 2016 12:28
sieve of erasotenese in haskell
import Control.Monad
series :: [Int]
series = [2..]
filterMulti :: Int -> [Int] -> [Int]
filterMulti n = filter (\x -> x `mod` n /= 0)
sieve :: [Int] -> [Int]
sieve s = p:sieve ps
@dbalan
dbalan / open_weather.py
Last active January 12, 2016 09:01
Gets local weather values from bangalore open weather project.
#!/usr/local/bin/python
# -*- coding: utf-8 -*-
# this uses bangalore open weather api to query the temparature near you.
# the api is documented here: http://www.yuktix.com/m/aws/media/yuktix-public-api.pdf
# This is a standalone script, eventhough I run this as a https://github.com/matryer/bitbar plugin.
API_ENDPOINT = "http://api1.yuktix.com:8080/sensordb/v1"
API_KEY = ""
SERIAL_NUMBER = "" # serial number of the weather station you are interested in.
CACHE_FILE="/tmp/weather_cache" # store recent data and display it while offline.
@dbalan
dbalan / infix.py
Created December 13, 2015 07:30
infix evaluation
# infix calculation
# infix -> postfix -> eval
NUMS = map(lambda x: str(x), range(10))
def toponlist(l):
return l[len(l)-1]
def dop(op, arg1, arg2):
if op == '-':
@dbalan
dbalan / simdatabase.go
Created September 2, 2015 19:49
Simple KV API in golang
package main
import (
"fmt"
"net/http"
"sync"
)
var (
KeyMap = map[string]string{}
@dbalan
dbalan / add.c
Created March 29, 2015 05:51
cgo sample code
#include "add.h"
int add_two_numbers(int x, int y) {
return x + y;
}
int add_fzed_two_numbers(int x, int y) {
return add_two_numbers(FuzzNumber(x),
FuzzNumber(y));
}
@dbalan
dbalan / iTerm.md
Last active January 13, 2021 12:55
iterm cheetsheet

iTERM2 Cheetsheet

Fancy Utilities

  1. Paste history: ⌘ + Shift + h
  2. Instant Replay: ⌘ + Opt + b
  3. Mouseless selection: ⌘ + f; Tab
  4. Smart select: Quad-Click
  5. Rectangle Select: ⌘ + Opt + Select
  6. Open link (URL/File): ⌘ + Click