Skip to content

Instantly share code, notes, and snippets.

View gdevanla's full-sized avatar

Guru Devanla gdevanla

View GitHub Profile
#Command to list matching files in 2 folders.
find unittests -name *.java | xargs -L1 basename $1 | -xargs find ../../../Applications/iTrust/unittests/edu/ncsu/csc/itrust/ -name $1
@gdevanla
gdevanla / gist:5443840
Last active December 16, 2015 13:48
Rename files with substring found in original file names.
for i in `ls`; do x=`echo $i | sed "s/doku.php.*s:uc\([1-9]*\).*/uc\1/g"`; mv $i $x.txt ; done;
@gdevanla
gdevanla / gist:5444061
Created April 23, 2013 14:34
Replace text in file inline and create a backup up old file.
for i in `ls uc*`;do `sed -i .bckp -e '/textarea/,/textarea/!d' $i` ; done;
@gdevanla
gdevanla / gist:5521489
Created May 5, 2013 17:30
Command line to help filter stopwords.
tr -cs 'A-Za-z0-9' '\n' < allwords.txt | sort | uniq -c | sort -n
;; Counting Coins
;; problem from "Coding for Interviews" news letter.
;; notes: switching to vector from raw list gave a tremendous performance boost
;; uses memoize as variant of Y-combinator.
(let
[coins (map read-string (clojure.string/split (read-line) #","))
amt (read-string (read-line))
change3 (fn [rec amt coins]
(cond
import pyodbc
# This will be the query to run
sql = 'SELECT * FROM AAF_IS_USER'
# conn_str = Here repace USER with treussard and YOUR_PASSWORD with the actual password
import unittest
def foo(x, y, z):
return (x != y and x != z or x and z)
def get_test_args():
x = y = z = [True, False]
from itertools import product, repeat
input_args = list(product(x, y, z))
expected_args = [
-- Adapted from http://chrisdone.com/posts/data-typeable
recordShow :: Data a => a -> ShowS
recordShow = render `extQ` (shows :: String -> ShowS) where
render t
| isTuple = drop 1 . tupleSlots
|
-- sequence a state monad
import Control.Monad.Trans.State
-- Example 1
let y = do { z <- get; let a = (Prelude.last z) + 1 in put (z Prelude.++ [a]);return $ (Prelude.last z) + 1} :: State [Int] Int
runState (sequenceA [y,y,y]) $ [1]
-- Example: 2
type X = State (M.Map String Int) Int
let y s s1 = do { z <- get; let a = z M.! s + 1 in put (M.insert s1 a z) ; let a = z M.! s + 1 in return $ a } :: X
@gdevanla
gdevanla / mvar_as_closure.hs
Last active January 30, 2017 04:02
Using MVar as a closure value
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE OverloadedStrings #-}
import Control.Concurrent.MVar