Skip to content

Instantly share code, notes, and snippets.

@vishesh
vishesh / cleanaur.sh
Last active December 15, 2015 14:39
Clean files downloaded and compiled by makepkg, at depth of one directory. Each package takes a folder in given directory.
#!/bin/sh
# clean pkg and src
for x in $(ls); do
if [ -d "$x/src" ]; then
rm -rf $x/src;
fi;
if [ -d "$x/pkg" ]; then
@vishesh
vishesh / fibs.clj
Created May 2, 2013 08:27
Generate a lazy sequence of fibonacci numbers
(defn fibs []
"Generate a lazy sequence of fibonacci numbers"
(lazy-cat '(0 1)
(map + (fibs ) (rest (fibs )))))
(println (take 20 (fibs )))
@vishesh
vishesh / subsets.ss
Created June 7, 2013 19:08
Scheme: Subsets of given list
(define (subsets s)
(if (null? s)
(list null)
(let ((rest (subsets (cdr s))))
(append rest (map (lambda (x)
(cons (car s) x))
rest)))))
(subsets '(1 2 3))
@vishesh
vishesh / tryton_shell
Last active December 20, 2015 17:59
A simple Tryton shell environment that initializes one database and config file for you. I intend to use to interact with models.
#!/bin/env python
""" tryton_shell: A dirty shell for Tryton to quickly interact with it
usage: tryton_shell.py [-h] --config CONFIG --database DATABASE
arguments:
--config CONFIG Tryton config file.
--database DATABASE Tryton database.
@vishesh
vishesh / dropalldb.sh
Created August 13, 2013 09:37
Drop all test_* databases in Postgres
# Drop all test_* databases in Postgres
function dropalldb()
{
for db in `psql -l | cat | egrep -o "test_[0-9]*"`; do
echo "Dropping " $db
dropdb $db;
done;
}
@vishesh
vishesh / synchronization.py
Last active December 22, 2015 09:58
Python synchronization helpers.
import threading
def threadify(func):
"A decorator to run a function asynchronously"
def run(*fargs, **fkwargs):
threading.Thread(target=func, args=fargs, kwargs=fkwargs).start()
return run
@vishesh
vishesh / test_sale.py
Created January 18, 2014 13:04
Test to demonstrate failing sale https://bugs.tryton.org/issue3602
# -*- coding: utf-8 -*-
"""
test_sale
Test Sale
:copyright: (c) 2013-2014 by Openlabs Technologies & Consulting (P) Limited
:license: BSD, see LICENSE for more details.
"""
import unittest
@vishesh
vishesh / set.rkt
Last active August 29, 2015 14:13
; Purely functional implementation of Set data structure
(define set-init
(lambda (x) #false))
(define (set-add set x)
(lambda (y)
(if (= x y)
#true
(set y))))
@vishesh
vishesh / lis.ss
Created March 17, 2015 01:39
longest increasing subsequence
(define (seq lst last)
(if (empty? lst)
0
(if (< last (first lst))
(max (add1 (seq (rest lst) (first lst)))
(seq (rest lst) last))
(seq (rest lst) last))))
@vishesh
vishesh / largest_bst.ml
Last active November 28, 2015 05:04
Largest BST subtree in a given Binary Tree
open Core.Std
type tree = Empty | Node of int * tree * tree
let rec largest_bst t =
let min_exn (lst:int list) : int =
Option.value_exn (List.min_elt lst ~cmp:Int.compare)
and max_exn (lst:int list) : int =
Option.value_exn (List.max_elt lst ~cmp:Int.compare)
in