Skip to content

Instantly share code, notes, and snippets.

View samstarling's full-sized avatar

Sam Starling samstarling

View GitHub Profile
id name favourite_number
1 Sam 40
2 Foo 12
3 Bar

Keybase proof

I hereby claim:

  • I am samstarling on github.
  • I am samstarling (https://keybase.io/samstarling) on keybase.
  • I have a public key ASAbCz8NP9AUlQvj5wngqAgkVDCt75RvHXctk8X6nvjbgAo

To claim this, I am signing this object:

Keybase proof

I hereby claim:

  • I am samstarling on github.
  • I am samstarling (https://keybase.io/samstarling) on keybase.
  • I have a public key whose fingerprint is A72B 8BEA CE58 9EC2 0C73 B8B0 C39D 1F80 D7AD 8B1B

To claim this, I am signing this object:

package com.samstarling.futures
import com.twitter.util.{Future, Await}
import com.samstarling.util.time
object ConcurrentComposition extends App {
def slowTask(time: Int): Future[String] = Future {
Thread.sleep(time)
"Hello"
package com.samstarling.futures
import com.twitter.util.Future
object SequentialComposition extends App {
case class User(name: String)
def authenticate(credentials: String) = Future { Some(User("sam")) }
package com.distributed
object Helpers {
def maybe(chance: Double)(success: => Any)(failure: => Any) = {
if(scala.util.Random.nextFloat() < chance) {
success
} else {
failure
}
}
@samstarling
samstarling / safe_json.rb
Last active December 18, 2015 21:09
Safe access of a nested hash from JSON in Ruby.
require 'json'
class Hash
def dig(*path)
path.inject(self) do |location, key|
location.respond_to?(:keys) ? location[key] : nil
end
end
end
@samstarling
samstarling / gist:3749581
Created September 19, 2012 13:11
Expand/Shrink Form Input
$(document).ready(function(){
$("#search").bind({
focus: function() {
$(this).animate({ width:200 }, 300);
},
blur: function() {
$(this).animate({ width:90 }, 300);
}
});
});
<?php
// Generate a random number.
$random = rand(0, 2);
// Set up messages, and fetch a random one.
$messages = array(
array("heading" => "foo", "body" => "123"),
array("heading" => "bar", "body" => "456"),
array("heading" => "bad", "body" => "789")
bbcpasswd () {
smbpasswd -U <name> -r `host -t srv _ldap._tcp.pdc._msdcs.national.core.bbc.co.uk | cut -d" " -f8 | head -c -2`
}