Skip to content

Instantly share code, notes, and snippets.

View sadache's full-sized avatar

Sadek Drobi sadache

View GitHub Profile
simpleGet uri error ok =
do resp <- simpleHTTP req
either error
(\r ->
case rspCode r of
(2,_,_) -> ok (rspBody r))
resp
where req=request urii
urii =fromJust $ parseURI uri
main = do resp <- simpleHTTP request
case resp of
Left x -> print ("Error connecting: " ++ show x)
Right r ->
case rspCode r of
(2,_,_) ->
print $ ( valFromObj "statuses_count"
=<< decode (rspBody r) :: Result Int)
where
request=Request {rqURI = uriSadache,
@sadache
sadache / fibs.hs
Created May 5, 2010 15:16
my favourite piece of code ever
let fibs@(h:tfibs)= 1:2:zipWith (+) fibs tfibs
@sadache
sadache / lazy.scala
Created May 5, 2010 15:05
Scala lazy val? not really.
lazy val xxxx={ println("initializing xxxx");1}
def getOne(x:Int):Int= 1
println(getOne(xxxx));
@sadache
sadache / scala-functions.scala
Created April 20, 2010 09:53
What is/is_not a function in Scala
object looksLikeAFunction{
def apply(s:String):Int=1
}
object nowAFunction extends Function[String,Int]{
def apply(s:String):Int=1
}
object TestMethods {
implicit def functionToAnother(f:Function[String,Int]):Function[Int,String] =
(i:Int)=> f(i.toString()).toString()
type 'a SimpleType= F of (int ->'a-> 'a)
let get a = F(fun req -> id)
[<GeneralizableValue>]
let oops2<'T> : SimpleType<'T> = get ""
-----------------------------------------------------------------------------
--
-- Module : RegexLang
-- Copyright :
-- License : AllRightsReserved
--
-- Maintainer :
-- Stability :
-- Portability :
--
module Randexp
#r "..//Dependencies//FSharp.PowerPack.dll"
open System
open LazyList
type Lang = LazyList<String>
let (.|.) (h:Lazy<_>) (t:Lazy<_>)= LazyList.delayed <| fun()-> LazyList.consDelayed (h.Value) <| fun () -> t.Value
let rec alt (xs:Lang) (ys:Lang) :Lang=
match (xs,ys) with
LazyList.Cons(x,xt) ,LazyList.Cons(y,yt) -> match compare (String.length x, x) (String.length y, y) with
-1 -> lazy(x) .|. lazy(alt xt ys)
module UrlPatterns
open System.Text.RegularExpressions
let t2 a b=(a,b)
let matchUrl pattern:string->(Map<string,string>* string ) Option=
let regex=(new Regex(pattern))
let names= regex. GetGroupNames()
in fun url -> let m=regex.Match(url)
if not(m.Success) then None
else let groups= m.Groups in
let paramMap=[for i in 0..groups.Count do
Sandwiches:
* Jay's Cheesesteaks (many seitan flavors)
* Ike's Place (tons of amazing veggie sandwiches)
* Toaster Oven (Potbelly's clone)
Mexican:
* Papalote (their house salsa is the best IN THE WORLD)
* El Buen Sabor (my favorite super veggie burrito)
* Taqueria Cancún (classic mission burrito; open till 2am on fri/sat, 1am other days, I think)