Skip to content

Instantly share code, notes, and snippets.

Avatar

Jordan West jrwest

View GitHub Profile
View gist:6662948
{'EXIT',{{assertEqual_failed,[{module,hashtree_eqc},
{line,207},
{expression,"Res"},
{expected,ok},
{value,precondition_failed}]},
[{hashtree_eqc,'-prop_correct/0-fun-1-',2,
[{file,"test/hashtree_eqc.erl"},{line,207}]},
{hashtree_eqc,'-prop_correct/0-fun-3-',2,
[{file,"test/hashtree_eqc.erl"},{line,207}]}]}}
{{call,erlang,'*',[32,256]},256,4}
View traverse.scala
scala> type Validated[X] = Option[X]
defined type alias Validated
scala> badData.traverse[Validated,Int](i => if (i < 0) none[Int] else i.point[Validated])
res3: Validated[List[Int]] = None
scala> goodData.traverse[Validated,Int](i => if (i < 0) none[Int] else i.point[Validated])
res4: Validated[List[Int]] = Some(List(4, 5, 123, 6, 7))
scala> import scalaz.syntax.validation._; import scalaz.Validation; import Validation._; import scalaz.std.string._
View acceptheaderparser.scala
case class MediaInfo(mediaRangeType: String, mediaRangeParams: List[(String,String)], qVal: Option[Double], acceptParams: List[(String,String)])
object AcceptHeaderParsers extends JavaTokenParsers {
def acceptHeader: Parser[List[MediaInfo]] = repsep(mediaInfo, ",")
def mediaInfo: Parser[MediaInfo] = (mediaRange ~ opt(qParam ~ rep(params))) ^^ {
case range~None => MediaInfo(range._1,range._2,None,Nil)
case range~Some(q~ap) => MediaInfo(range._1,range._2,Some(q),ap)
}
View lenses-1-11.scala
def updateCondition(toyBox: ToyBox, name: String, newCondition: ToyCondition): ToyBox = {
toyBox.toys.get(name)
.map(t => toys.mod(toyBox, _ + (name -> condition.set(t, newCondition)))
.getOrElse(toyBox)
}
View lenses-1-1.scala
// https://github.com/scalaz/scalaz/blob/master/core/src/main/scala/scalaz/Lens.scala
case class Lens[A,B](get: A => B, set: (A,B) => A) {
def apply(a: A) = get(a)
// ...
}
@jrwest
jrwest / stackmob.hs
Created Jan 23, 2012
Call StackMob API from Haskell
View stackmob.hs
-- requires hoauth http://hackage.haskell.org/package/hoauth
import Network.OAuth.Consumer
import Network.OAuth.Http.CurlHttpClient
import Network.OAuth.Http.Request (parseURL)
import Network.OAuth.Http.Response
import Data.Maybe (fromJust)
reqUrl = fromJust . parseURL $ "http://SUBDOMAIN.stackmob.com/api/0/APPNAME/listapi"
app = Application "public key" "private key" OOB
response :: IO Response
@jrwest
jrwest / ToyBoxLenses.scala
Created Jan 18, 2012
Scalaz Lenses Example
View ToyBoxLenses.scala
import scalaz._
import Scalaz._
case class ConditionalMapLens[A, K, V](lens: Lens[A, Map[K,V]]) {
def +=?(elem: (K, Option[V])) = lens.mods(m => elem._2.cata(v => m + (elem._1 -> v), m))
def +=?(elem: (K, V), bool: Boolean) = lens.mods(m => if (bool) m + elem else m)
def -=?(k: K, bool: Boolean) = lens.mods(m => if (bool) (m - k) else m)
}
@jrwest
jrwest / dodelete.scala
Created Dec 21, 2011
Scalaz Functional IO Post Gist Files
View dodelete.scala
val deleteSomeKey: DeleteObject = bucket.delete("some-key")
deleteSomeKey.execute() // actually makes the request to delete the key
View gist:1402820
[ERROR] error: java.lang.Error: no-symbol does not have owner
[INFO] at scala.tools.nsc.symtab.SymbolTable.abort(SymbolTable.scala:34)
[INFO] at scala.tools.nsc.symtab.Symbols$NoSymbol$.owner(Symbols.scala:2150)
[INFO] at scala.tools.nsc.symtab.Symbols$Symbol.logicallyEnclosingMember(Symbols.scala:1248)
[INFO] at scala.tools.nsc.transform.LambdaLift$LambdaLifter.searchIn$1(LambdaLift.scala:234)
[INFO] at scala.tools.nsc.transform.LambdaLift$LambdaLifter.proxy(LambdaLift.scala:243)
[INFO] at scala.tools.nsc.transform.LambdaLift$LambdaLifter.scala$tools$nsc$transform$LambdaLift$LambdaLifter$$proxyRef(LambdaLift.scala:259)
[INFO] at scala.tools.nsc.transform.LambdaLift$LambdaLifter.postTransform(LambdaLift.scala:389)
[INFO] at scala.tools.nsc.transform.LambdaLift$LambdaLifter.transform(LambdaLift.scala:412)
[INFO] at scala.tools.nsc.ast.Trees$Transformer$$anonfun$transform$4.apply(Trees.scala:777)
@jrwest
jrwest / accessing_snapshot.rb
Created May 26, 2011 — forked from jsmestad/accessing_snapshot.rb
Proposed changes for Mongomatic 0.9.0 (Jordan's Edits)
View accessing_snapshot.rb
@snapshot = Snapshot.first
-----
{
:stats => {
'accounts' => { 'count' => 8, 'a' => 1 },
'subscriptions' => { 'count' => 16, 'b' => 1 }
},
:activity => [ {'ns' => 'accounts.users', ...}, {'ns' => 'subscriptions.users' =>, ...} ]
}
-----
You can’t perform that action at this time.