Skip to content

Instantly share code, notes, and snippets.

@vishakvkt
vishakvkt / run_mocha.js
Last active March 27, 2016 09:52
Mocha Debug launch.json for Visual studio Code on OS X
{
// Name of configuration; appears in the launch configuration drop down menu.
"name": "Run mocha",
// Type of configuration. Possible values: "node", "mono".
"type": "node",
// Workspace relative or absolute path to the program.
"program": "/usr/local/lib/node_modules/mocha/bin/_mocha",
// Automatically stop program after launch.
"stopOnEntry": false,
// Command line arguments passed to the program.
@vishakvkt
vishakvkt / read-file.js
Last active February 22, 2016 23:36
Read file line by line
var fs = require('fs');
var readline = require('readline');
var reader = readline.createInterface({
input: fs.createReadStream('data.txt')
});
reader.on('line', (line) => {
console.log(line);
});
@vishakvkt
vishakvkt / converters.go
Last active April 25, 2018 05:53
gorilla schema - convert html date
import(
"reflect"
"time"
"github.com/gorilla/schema"
)
func ConvertFormDate(value string) reflect.Value {
s, _ := time.Parse("2006-01-_2", value)
return reflect.ValueOf(s)
}
var Future = require('fibers/future');
var fs_f = Future.wrap(require('fs'));
if(process.argv.length < 3) {
console.log("format filestat <path>");
process.exit();
}
function processFileStats(stat) {
console.log(stat);
@vishakvkt
vishakvkt / pav_bhaji
Last active August 29, 2015 14:05
my custom recipes - pav bhaji
boil any vegetables you like until very tender (till they can be mashed easily)
(tradtional version always contains potatoes, cauliflower and green peas).
Add 1-2 table spoons of oil.
Add cumin seeds.
Add 1-2 red onions and fry till golden.
Add 1 table spoon of ground ginger.
Add 1 table spoon of ground garlic.
Add 1-2 green chilies.
Add 1 teaspoon of cumin powder.
@echo off
SET st2Path=C:\Program Files\Sublime Text 2\sublime_text.exe
rem add it for all file types
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2" /t REG_EXPAND_SZ /v "Icon" /d "%st2Path%,0" /f
@reg add "HKEY_CLASSES_ROOT\*\shell\Open with Sublime Text 2\command" /t REG_SZ /v "" /d "%st2Path% \"%%1\"" /f
rem add it for folders
@reg add "HKEY_CLASSES_ROOT\Folder\shell\Open with Sublime Text 2" /t REG_SZ /v "" /d "Open with Sublime Text 2" /f
@vishakvkt
vishakvkt / my_sambhar
Last active August 29, 2015 14:01
my custom recipes - sambhar
sambhar powder
lentils
salt
chilli powder
onions tomatoes
fenugreek seeds - 1 tablespoon
mustard seeds - 1 tablespoon
cumin seeds - 1 tablespoon
curry leaves
let factors n =
let rec factorizer i n res =
if i > int(n/2) then n::res
else
if n % i = 0 then
factorizer (i+1) n (i::res)
else
factorizer (i+1) n res
factorizer 2 n []
let is_prime n =
match n with
|n when n < 2 -> false
|n when n = 2 || n = 3 -> true
|n when n % 2 = 0 || n % 3 = 0 -> false
|n ->
let rec check i rootn n =
if i > rootn then true
else
if n % i = 0 then false
let sieve upperbound =
let ar = Array.create (upperbound+1) 1
for i in 2.. (ar.Length - 1) do
let endi = int (floor (float (upperbound/i)))
for j in i..endi do
ar.[i * j] <- 0
seq{for i in 2..(ar.Length - 1) do if ar.[i] = 1 then yield i}