This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import oauth.oauth as oauth | |
import httplib | |
import json | |
import sys | |
PUBLIC_KEY = "68023efc-6b09-42d0-9b43-18c531d79a98" | |
PRIVATE_KEY = "f41c5002-64c0-46c1-b249-b667866ba305" | |
class Client: | |
def __init__(self, url, key, secret): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//declare the data structure and the Equal instance | |
import scalaz._ | |
import Scalaz._ | |
case class MyThing(thing1: String, thing2: String) | |
object MyThing { | |
implicit def MyThingEqual = new Equal[MyThing] { | |
override def equal(t1: MyThing, t2: MyThing) = (t1.thing1 === t2.thing1) && (t1.thing2 === t2.thing2) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//goes in src/main/java/com/stackmob/oauthhttpservice | |
package com.stackmob.oauthhttpservice; | |
import org.scribe.services.TimestampService; | |
import org.scribe.services.TimestampServiceImpl; | |
import org.scribe.model.Token; | |
import org.scribe.builder.api.DefaultApi10a; | |
class HttpRequestSignerAPI extends DefaultApi10a { | |
public static class TimeService extends TimestampServiceImpl { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
StackMob.RegistrationIDAndUser json = new StackMob.RegistrationIDAndUser("a88fqsdg8as87rgq87wrg8as8dg78zDf8a98sdf98asd8fa7sdf", "johnsmith", "ios"); | |
stackmob.postPush("register_device_token_universal", json, newStackMobCallback() { | |
@Override public void success(String responseBody) { | |
//responseBody will be a list of MyObject instances | |
//do something with your objects | |
Logger.debug("stackmob success"); | |
} | |
@Override public void failure(StackMobException e) { | |
//handle the failure | |
Logger.debug("stackmob fail" + e); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package tmplbench | |
import ( | |
"testing" | |
"html/template" | |
) | |
func BenchmarkTemplate(b *testing.B) { | |
tmpl := template.New("test") | |
b.ResetTimer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* wrap a container purely (ie: with no effects) in a FlowState and transform it in a ResT | |
* @param container the container to wrap | |
* @param transformer the function to transform the container into a Res[U] | |
* @tparam M the container | |
* @tparam T the type inside the container | |
* @tparam U the type inside the resulting Res | |
* @return the Res[U] returned by the transformer wrapped purely in a FlowState and transformed by a ResT | |
*/ | |
private def wrapPure[M[_], T, U](container: M[T])(transformer: M[T] => Res[U]): ResT[FlowState, U] = { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* transform a type purely (no effects) into a ReqRespState[T]. | |
* note that a ReqRespState[T] is the same as a scalaz.State[ReqRespData, T] | |
* @param t the type to transform | |
* @tparam T the type | |
* @return the resulting ReqRespState[T] | |
*/ | |
protected def reqRespStatePure[T](t: T): ReqRespState[T] = { | |
t.pure[ReqRespState] | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
import Scalaz._ | |
import Probably.A.Lot.More.Shit | |
//this is how you construct a State manually by the way | |
val myState: State[ReqRespData, Res[String]] = state { d: ReqRespData => | |
val myRes: Res[String] = ValueRes("hello world") | |
(d, myRes) | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//build an extension to any State[ReqRespData, Res[Something]] | |
trait StateResW[T] { | |
protected def state: State[ReqRespData, Res[T]] | |
def mapRes[U](f: T => U): State[ReqRespData, Res[U]] = state.map { res: Res[T] => | |
res match { | |
case ValueRes(t) => ValueRes(f(t)) | |
case other => other: Res[U] | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import scalaz._ | |
import Scalaz._ | |
import scalamachine.core._ | |
import scalamachine.scalaz._ | |
val myState: State[ReqRespData, Res[String]] = state { d: ReqRespData => | |
val myRes: Res[String] = ValueRes("hello world") | |
(d, myRes) | |
} |