Skip to content

Instantly share code, notes, and snippets.

View naveensrinivasan's full-sized avatar

Naveen naveensrinivasan

View GitHub Profile
@naveensrinivasan
naveensrinivasan / SelectManyinClojure
Created August 25, 2011 21:50
C# SelectMany in Clojure
(def x `(1 2 3))
(def y `(4 5 6))
(def z `(7 8 9))
(println (mapcat list x y z))
//perfect number
//http://4clojure.com/problem/80
let perfectnumber x =
let rec divisor x counter l=
match counter < x with
|true when x % counter < 1-> divisor x (counter + 1) (counter::l)
|true -> divisor x (counter + 1) l
|_ -> (l |> List.fold (+) 0) = x
divisor x 1 []
@naveensrinivasan
naveensrinivasan / sublist
Created September 20, 2011 17:15
Pack consecutive duplicates of list elements into sublists.
//P09 Pack consecutive duplicates of list elements into sublists.
// https://sites.google.com/site/prologsite/prolog-problems/1
let packDups l =
let result = List.foldBack (
fun ele (flist,(mainlist:List<List<_>>)) ->
match (flist,mainlist) with
|([],_) -> (ele::flist,mainlist)
|(h::_,_) when ele = h -> ((ele::flist),mainlist)
|(_::_,[]) -> ([ele], [flist])
|(_::_,_) -> ([ele],flist::mainlist)
@naveensrinivasan
naveensrinivasan / Readromannumerals
Created September 22, 2011 18:57
Read roman numerals in F#
(*
http://4clojure.com/problem/92
Roman numerals are easy to recognize, but not everyone knows all the rules necessary to work with them.
Write a function to parse a Roman-numeral string and return the number it represents.
You can assume that the input will be well-formed, in upper-case, and follow the subtractive principle.
You don't need to handle any numbers greater than MMMCMXCIX (3999), the largest number representable with ordinary letters.
(= 14 (__ "XIV"))
@naveensrinivasan
naveensrinivasan / PrimeFactors.fs
Created November 16, 2012 21:02
Prime and Prime factors
let isprime i =
List.filter(fun x -> i%x = 0) [1..i]
|> List.length = 2
let primefactor x =
let rec innerprime number divisor l=
let intermedidate = number /divisor
match (not(isprime intermedidate ),number > divisor) with
|true,true when number % divisor = 0 -> innerprime intermedidate divisor (divisor::l)
|_,true when number % divisor = 0 -> intermedidate::divisor::l
@naveensrinivasan
naveensrinivasan / downloadextractlinqpad
Created February 28, 2013 21:14
Script to download and extract beta linqpad
#! /bin/sh
curl -O http://download.linqpad.net/preview/LINQPad4.zip
unzip -q -o -d /cygdrive/c/tools/ LINQPad4.zip
rm LINQPad4.zip
@naveensrinivasan
naveensrinivasan / conditionalbp
Created March 20, 2013 19:06
Conditional breakpoint in windbg.
as /c stack !CLRStack;
.if ($spat("${stack}","*Foo*"))
{ $$ do the evaluation}
0:000> !do @esi
Name: System.Data.SqlClient.SqlCommand
MethodTable: 60b9fcb0
EEClass: 60ac8eac
Size: 132(0x84) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll
Fields:
MT Field Offset Type VT Attr Value Name
6897f638 40001cf 4 System.Object 0 instance 00000000 __identity
662a2480 40001ae 8 ...ponentModel.ISite 0 instance 00000000 site
.foreach ( $obj {$$>a<"d:\Debuggersx86\dumplist.txt" poi(poi(poi(@esi+18)+8)+4)}) { !do poi(${$obj}+38)}
Name: System.Data.SqlClient.SqlParameter
MethodTable: 60ba012c
EEClass: 60ac8ef0
Size: 100(0x64) bytes
File: C:\Windows\Microsoft.Net\assembly\GAC_32\System.Data\v4.0_4.0.0.0__b77a5c561934e089\System.Data.dll
Fields:
MT Field Offset Type VT Attr Value Name
6897f638 40001cf 4 System.Object 0 instance 00000000 __identity
60ba1e18 400195f 8 ...qlClient.MetaType 0 instance 00000000 _metaType
60ba3cac 4001960 c ...ient.SqlCollation 0 instance 00000000 _collation