Skip to content

Instantly share code, notes, and snippets.

View MnO2's full-sized avatar

Paul Meng MnO2

View GitHub Profile
@MnO2
MnO2 / project_line_num.sh
Created May 4, 2011 08:17
How many lines in your C project?
#1
shopt -s globstar && wc -l **/*.[ch]
#2
find -name *.\[c\|h\] | xargs wc -l
@MnO2
MnO2 / sqlite3_tricks.sql
Created May 5, 2011 06:53
SQLite Tricks
-- insert a record if it doesn't exist, ignore if it does exist
-- if EventTypeName column is unique
INSERT OR IGNORE INTO EVENTTYPE (EventTypeName) VALUES 'ANI Received'
-- otherwise
INSERT INTO EVENTTYPE (EventTypeName)
SELECT 'ANI Received'
WHERE NOT EXISTS (SELECT 1 FROM EVENTTYPE WHERE EventTypeName = 'ANI Received');
@MnO2
MnO2 / rvm-install.sh
Created September 14, 2011 08:53
rvm installation
sudo apt-get install ruby1.9.1
sudo ln -s /usr/bin/ruby1.9.1 /usr/bin/ruby
bash < <( curl https://rvm.beginrescueend.com/releases/rvm-install-head )
sudo /usr/bin/apt-get install build-essential bison openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-0 libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev ncurses-dev automake
rvm install 1.9.2-head
@MnO2
MnO2 / Makefile
Created November 19, 2011 15:10
iteratee implementation to print firstlines of files
.PHONY: clean test
test: allfirstlines_iteratee allfirstlines_naive gen_nuclear_test
bash run_test.sh
allfirstlines_naive: allfirstlines_naive.hs
ghc --make -rtsopts -O2 $@
allfirstlines_iteratee: allfirstlines_iteratee.hs
ghc --make -rtsopts -O2 $@
@MnO2
MnO2 / sol01.hs
Created December 3, 2011 09:14
dynamic programming in haskell
import qualified Data.MemoCombinators as Memo
coins = [1,2,5,10,20,50,100,200]
sol1 = f
where f :: Int -> Int -> Int
f = Memo.memo2 Memo.integral (Memo.arrayRange (0,7)) mf
where mf :: Int -> Int -> Int
mf n k | (k >= 8) || (n < 0) = 0
| n == 0 = 1
@MnO2
MnO2 / test01.hs
Created December 7, 2011 09:20
Haskell Instance Definition Gotcha
class C a where
toString :: a -> String
instance C String where
toString = id
main = do
putStrLn $ toString "Hello World"
@MnO2
MnO2 / data_dynamic.hs
Created December 24, 2011 16:12
Typeable and Dynamic
import Data.Dynamic
import Data.Maybe
hlist :: [Dynamic]
hlist = [toDyn "string",
toDyn (7::Int),
toDyn (pi :: Double),
toDyn 'x',
toDyn ((), Just "foo")]
@MnO2
MnO2 / filter-O1.core
Created January 18, 2012 16:11
Eta Expansion
f2_rbu
:: forall a_ase. GHC.Real.Integral a_ase => GHC.Types.Int -> a_ase
[GblId, Arity=2]
f2_rbu =
\ (@ a_ase)
($dIntegral_asf :: GHC.Real.Integral a_ase)
(eta_B1 :: GHC.Types.Int) ->
GHC.List.!!
@ a_ase
(GHC.List.filter
@MnO2
MnO2 / Word.hs
Created February 25, 2012 07:02
haskell word calculation
{-# LANGUAGE BangPatterns #-}
import Data.Word
import Data.List
sum_word :: Word -> Word
sum_word n = k n 0
where k 0 s = s
k !n !s = k (n-1) (s+1)
main = do
{-# LANGUAGE DeriveDataTypeable #-}
module Main where
import System.Console.CmdArgs.Implicit
import System.IO
import System.Environment
import System.Exit
import Data.Maybe