Skip to content

Instantly share code, notes, and snippets.

View softprops's full-sized avatar
🏕️
Just gopher it

Doug Tangren softprops

🏕️
Just gopher it
View GitHub Profile
@kmcallister
kmcallister / rust-backtrace
Last active January 16, 2016 05:47
Run a Rust program and print a stack backtrace on failure (old)
#!/bin/bash
### NOTE ### You probably don't need this anymore!
# Just set RUST_BACKTRACE=1
# Usage: rust-backtrace ./my-rust-prog args...
exec gdb -batch -n -x /dev/fd/3 --args "$@" 3<<ENDGDB
set height 0
set breakpoint pending on
@waxzce
waxzce / AController.scala
Created September 23, 2013 04:24
this is the code example from my talks at scala user group of Tokyo
package controllers
import play.api._
import play.api.mvc._
import play.api.libs.iteratee.Iteratee
import play.api.libs.iteratee.Input
import play.api.libs.iteratee.Done
import play.api.libs.iteratee.Cont
import scalax.file.Path
import views.html.defaultpages.badRequest
@agleyzer
agleyzer / gist:6616242
Created September 18, 2013 21:48
a script to log http connections...
#!/bin/bash
ts=$(date +%Y%m%d-%H%M%S)
tcpdump -A -s 1492 -l \
'host blahblah and tcp port 80 and (((ip[2:2] - ((ip[0]&0xf)<<2)) - ((tcp[12]&0xf0)>>2)) != 0)' \
| grep HTTP -C 10 > httpdump-${ts}.log 2>&1 &
disown %1
@jrudolph
jrudolph / ListBufferTest.scala
Last active July 27, 2019 13:14
ListBuffer / List mutability fail
import scala.collection.mutable.ListBuffer
object ListBufferTest extends App {
new X().runTest()
}
class X extends Runnable {
var x: List[String] = List("", "")
def run() {
@johnynek
johnynek / twophase.scala
Last active October 2, 2020 22:36
A two-phase commit Transaction Monad. See: http://en.wikipedia.org/wiki/Two-phase_commit_protocol
// Run this with scala <filename>
/**
* A Two-phase commit Monad
*/
trait Transaction[+T] {
def map[U](fn: T => U): Transaction[U] = flatMap { t => Constant(fn(t)) }
def flatMap[U](fn: T => Transaction[U]): Transaction[U] =
FlatMapped(this, fn)
import scalaz.{LensFamily, Lens}
import Lens.{lensg, lensFamilyg}
object LensFns {
/**
* A lens that requires a key be provided to extract B from A.
*
* @tparam A The record type.
* @tparam K The field key type.
@johnynek
johnynek / hdfsio.scala
Created August 25, 2013 05:34
IO Monad for the HDFS FileSystem: http://hadoop.apache.org/docs/r1.0.4/api/org/apache/hadoop/fs/FileSystem.html Make your HdfsIO[T] object (for example op), set an implicit FileSystem, then call HdfsIO.run(op) TOTALLY UNTESTED! (but it does compile)
import java.io.{FileNotFoundException, IOException}
import org.apache.hadoop.fs.{
FileSystem,
FileStatus,
FSDataInputStream,
FSDataOutputStream,
Path
}
@softprops
softprops / console.js
Created August 24, 2013 23:55
rhino shim for console logging
var console = {
log: function (msg) {
java.lang.System.out.println(msg);
}
};
@timperrett
timperrett / gist:6224373
Created August 13, 2013 18:49
Shapeless typed element selection
Welcome to Scala version 2.9.2 (Java HotSpot(TM) 64-Bit Server VM, Java 1.7.0_25).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._, HList._
import shapeless._
import HList._
scala> "foo" :: 124 :: HNil
res0: shapeless.::[java.lang.String,shapeless.::[Int,shapeless.HNil]] = foo :: 124 :: HNil

http://dl.dropboxusercontent.com/u/42561/Screenshots/i60w-q0t2ybn.png

I've learned more about orbital mechanics in six hours with this game than in my entire physics undergrad, haha. Lost an astronaut during an EVA last night, and didn't know how to use his little RCS jetpack, so he orbited the earth independently. Sent a rescue mission to pick him up, but it ran out of fuel. Sent another rescue mission, finally picked up the guy, but didn't have enough fuel to deorbit so now I've got seven astronauts in orbit. And no parachutes.

https://pbs.twimg.com/media/BQeyq5dCUAAlP1f.jpg:large

Decided to dock with one of them to form a small space station. Here's my three-stage launch vehicle almost snapping in half due to an uncontrolled SAS control-plane feedback loop:

https://pbs.twimg.com/media/BQfs3wxCQAMkb0g.jpg:large