Skip to content

Instantly share code, notes, and snippets.

View arschles's full-sized avatar
🎯
Focusing

Aaron Schlesinger arschles

🎯
Focusing
View GitHub Profile
@arschles
arschles / stackmob.py
Created May 31, 2012 06:55
StackMob with Python
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):
@arschles
arschles / typesafeEquals.scala
Created June 20, 2012 20:54
How to use === in scalaz
//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)
}
@arschles
arschles / HttpRequestSignerAPI.java
Created July 5, 2012 19:07
OAuth Signing with StackMob Custom Code's HttpService
//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 {
@arschles
arschles / registerIOS.java
Created July 11, 2012 18:49
Registering an iOS push token from the stackmob-java-client-sdk
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);
@arschles
arschles / tmpl_bench.go
Last active October 11, 2015 05:48
golang html/template Parse benchmark
package tmplbench
import (
"testing"
"html/template"
)
func BenchmarkTemplate(b *testing.B) {
tmpl := template.New("test")
b.ResetTimer()
@arschles
arschles / wrapAndTransform.scala
Created October 18, 2012 22:34
wrapping a container purely in a FlowState, and transforming it in a ResT
/**
* 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] = {
@arschles
arschles / reqRespStateCreators.scala
Created October 18, 2012 23:07
creating ReqRespState[Res[T]] values
/**
* 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]
}
@arschles
arschles / stateMap.scala
Created November 13, 2012 02:09
Map Over a State[ReqRespData, Res[A]]
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)
}
@arschles
arschles / mapRes.scala
Created November 13, 2012 02:10
build a mapRes for any State[ReqRespData, Res[T]]
//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]
}
}
}
@arschles
arschles / resTExample.scala
Created November 13, 2012 02:11
example scalamachine usage of ResT
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)
}