Skip to content

Instantly share code, notes, and snippets.

Avatar

John Murray JohnMurray

View GitHub Profile
@JohnMurray
JohnMurray / .travis.yml
Last active Aug 29, 2015
Code snippets for scala-project blog post on www.johnmurray.io
View .travis.yml
language: scala
scala:
- 2.10.3
script:
- sbt compile test:compile
- sbt scalastyle
- sbt test
jdk:
- oraclejdk7
- openjdk7
@JohnMurray
JohnMurray / set.scala
Created Oct 28, 2014
Extract from BuiltinCommands object in SBT
View set.scala
def set = Command(SetCommand, setBrief, setDetailed)(setParser) {
case (s, (all, arg)) =>
val extracted = Project extract s
import extracted._
val dslVals = extracted.currentUnit.unit.definitions.dslDefinitions
// TODO - This is possibly inefficient (or stupid). We should try to only attach the
// classloader + imports NEEDED to compile the set command, rather than
// just ALL of them.
val ims = (imports(extracted) ++ dslVals.imports.map(i => (i, -1)))
val cl = dslVals.classloader(currentLoader)
@JohnMurray
JohnMurray / load-keyboard
Created Feb 20, 2012
Enable Mac OS X Keyboard (built-in only)
View load-keyboard
#!/bin/bash
# Load the keyboard back. (Should probably do this
# while the external one is still attached.)
sudo kextload /System/Library/Extensions/AppleUSBTopCase.kext/Contents/PlugIns/AppleUSBTCKeyboard.kext/
View trees.scala
package trees
object Main extends App {
trait Node
case class InnerTreeNode ( left:Node, right:Node, value:Int ) extends Node
case object StopNode extends Node
def leaf(x: Int): Node = InnerTreeNode(StopNode, StopNode, x)
@JohnMurray
JohnMurray / repetitive_pry_session.rb
Created May 31, 2012
An example of what a repetitive Pry session _might_ look like
View repetitive_pry_session.rb
require 'bundler/setup'
bundler.require(:development, :test, :console)
$: << File.expand_path('../src', __FILE__)
require 'app'
require 'models/user_account'
require 'models/car'
# Load config and connect to DB
App.init()
@JohnMurray
JohnMurray / console.rb
Created May 31, 2012
An example console from my geofence-server-example project
View console.rb
#!/usr/bin/env ruby
# require all the necessary files
$: << ::File.expand_path('../src', __FILE__)
require 'app'
require 'geofence'
# at this point bundler should be setup and the :development group
# should have been included. However, just to be sure, I'm going to
# include bundler again and require the console group.
@JohnMurray
JohnMurray / Dictionary.ToJson.cs
Created Jun 1, 2012
Code descriptions for log-entry on API Anti-Patterns (johnmurray.io)
View Dictionary.ToJson.cs
public static class IDictionaryExtension
{
public static JsonDictionary<K, V> ToJsonDictionary<K,V>(this IDictionary<K, V> dict)
{
if (dict == null)
return null;
var jsonDict = new JsonDictionary<K, V>();
foreach (var key in dict.Keys)
{
jsonDict[key] = dict[key];
@JohnMurray
JohnMurray / CheckResponse.cs
Created Jun 4, 2012
Code descriptions for log-entry on API Anti-Patterns (johnmurray.io)
View CheckResponse.cs
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
var statusCode = response.StatusCode;
return statusCode == HttpStatusCode.OK;
@JohnMurray
JohnMurray / how_to.md
Created Jun 12, 2012
A getting started guide to making requests to my sample geofence-server
View how_to.md

John Murray's Sample Geofence Server

Hey, you ran the project! Good for you! You're probably wondering how the heck to use this thing. Well, keep reading and maybe you'll find out.

Pre-Requisites

  1. Install and run Mongo (on default port w/o a password)
  2. Install Gemset with Bundler
  3. Get the server running. (Hey look! You're ahead of the game!)

That's it... keep reading.

@JohnMurray
JohnMurray / ex.sql
Created Jul 5, 2012
Link Multi-Where
View ex.sql
select *
from (
select *
from carModels as t1,
carMakes as t2
where t1.somePKId = t2.someFKId
and (
t1.Name like '%c%'
or t2.Name like '%c%'
)