Skip to content

Instantly share code, notes, and snippets.

View softprops's full-sized avatar
®️
Rustling

Doug Tangren softprops

®️
Rustling
View GitHub Profile
import scala.language.implicitConversions
class Mult[A, B] {
def commute: Mult[B, A] = new Mult[B, A]
def associate[C, D](implicit ev: B =:= Mult[C, D]): Mult[Mult[A, C], D] = new Mult[Mult[A, C], D]
}
object Simplify {
implicit def commute[A, B, M <% Mult[A, B]](m: M): Mult[B, A] = m.commute
implicit def associate[A, B, C, M <% Mult[A, Mult[B, C]]](m: M): Mult[Mult[A, B], C] = m.associate
@jmhodges
jmhodges / welp.scala
Last active August 29, 2015 13:56
The catch statement doesn't print the text. Seen with scala 2.8.1, 2.9.2 and now 2.10.x.
object Welp {
def foobar(a: Int, b: Int, c:Int) { throw new IllegalArgumentException }
def main(args: Array[String]) {
List(3) map {
try {
foobar(1, 2, _)
} catch {
case e: Throwable => { // This set of braces is optional. Problem remains when removed.
println("won't be printed")
@daggerrz
daggerrz / gist:9310425
Created March 2, 2014 17:41
GraphiteReporter
package com.tapad.common.metrics
import java.net.Socket
import java.io._
import com.tapad.common.log.Logging
import com.twitter.ostrich.stats._
import java.util.TimerTask
object GraphiteReporter {
def apply(prefix: String, host: String, port: Int, reportInterval: Long) = {
@non
non / build.sbt
Last active August 29, 2015 13:57
Fun little program to display N digits of Pi in any base (2-36) using Spire.
// this is the build file used to compile piday.scala
name := "piday"
scalaVersion := "2.10.3"
libraryDependencies += "org.spire-math" %% "spire" % "0.7.3"
#!/bin/sh
function copy_if_changed {
local path_from="$2/$1"
local path_to="$3/$1"
local md5_from=$(md5 -q $path_from)
if [ -e $path_to ]
then
@chrislewis
chrislewis / Foo.scala
Last active August 29, 2015 14:02
Not so sealed
sealed trait Foo
case class Bar(x: Int) extends Foo
case class Baz(name: String) extends Foo
object Foo {
def show(f: Foo) =
f match {
case Bar(x) => x.toString // Quux, a subtype of Bar in a different file, will be matched as a Bar
case Baz(name) => name
}
<?php
/*
* This is a simple example of using PHP's OAuth extension to fetch a valid
* token for a given member. The process is a typical OAuth 1.0a flow, which
* includes requesting a member's authorization to act on her behalf and then
* fetching the actual token once authorized. This token can then be stored
* and used to make API calls on the member's behalf. For an example of making
* such a call once you have retriefed an authorized token, see:
*
import scala.language.higherKinds
trait Bifunctor[BF[_, _]] {
def bimap[A, B, C, D](bf: BF[A, C], fab: A => B, fcd: C => D): BF[B, D]
/* Mapping over one of the sides is convenient and can be implemented easily
in terms of `bimap`. */
/** Map over the "first" side, transforming the type and potentially the value
(if the BF instance is of the "first" type, natrually.) */
object Fλip {
val tParams = (1 to 23).map { i =>
(i + 'A' - 1).toChar
}
def getParams(arity: Int): IndexedSeq[Char] =
(0 to arity).map(tParams(_))
def getTypeSig(seq: IndexedSeq[Char]) =
s"""(${seq.init.mkString(",")}) => ${seq.last}"""
ubuntu@ip-10-74-149-134:~$ mkdir rust-buildbox
ubuntu@ip-10-74-149-134:~$ cd rust-buildbox/
ubuntu@ip-10-74-149-134:~/rust-buildbox$ vim Dockerfile
ubuntu@ip-10-74-149-134:~/rust-buildbox$ docker build -t rust-buildbox .
ubuntu@ip-10-74-149-134:~/rust-buildbox$ docker images
REPOSITORY TAG IMAGE ID CREATED VIRTUAL SIZE
rust-buildbox latest be231641cce2 18 seconds ago 1.277 GB
ubuntu 14.04 c4ff7513909d 11 days ago 213 MB
ubuntu@ip-10-74-149-134:~/rust-buildbox$ docker run -t -i rust-buildbox /bin/bash
root@45ac8578f983:/# cd /home/rust/