Skip to content

Instantly share code, notes, and snippets.

View ShaneDelmore's full-sized avatar

Shane Delmore ShaneDelmore

View GitHub Profile
def self.title
self.name.gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').gsub(/([a-zA-Z\d])([A-Z])/,'\1-\2').downcase
end
attr_reader :title
def initialize(title=self.class.title)
@title = title
end
@ShaneDelmore
ShaneDelmore / gist:6015634
Created July 16, 2013 22:11
Verifying my symlink.
➜ lib git:(cask-strategy) ✗ ls -l /usr/local/Library/Taps/phinze-cask/lib
lrwxr-xr-x 1 Shane rvm 52 Jul 16 14:51 /usr/local/Library/Taps/phinze-cask/lib -> /Users/Shane/Dropbox/Projects/ruby/homebrew-cask/lib
@ShaneDelmore
ShaneDelmore / gist:6059868
Last active December 20, 2015 02:59
Playing around with enumerable.
#Make a grid_location class to make it easier to address grid coordinates.
class Cell
attr_reader :column, :row, :letter
def initialize(row, column, letter='')
@column = column
@row = row
@letter = letter
end
def move(direction)
@ShaneDelmore
ShaneDelmore / gist:6081560
Created July 25, 2013 16:42
tmux dot file
# Ring the bell if any background window rang a bell
set -g bell-action any
# Default termtype. If the rcfile sets $TERM, that overrides this value.
set -g default-terminal screen-256color
# set -g default-terminal "screen-256color"
#
set-option -g default-command "reattach-to-user-namespace -l $SHELL -l"
# Keep your finger on ctrl, or don't
@ShaneDelmore
ShaneDelmore / gist:a4a6560e5952b20d2e33
Created September 17, 2014 20:28
sum and max in scala, tail recursive without an inner helper method
//If we have a list with at least two elements sum them and add them to the rest of the list
//else return the head of the list
@tailrec
def sum(xs: List[Int]): Int = xs match {
case h :: i :: rest => sum(h + i :: rest) //we have a list with at least two elements
case _ => xs.head
}
//If we have a list with at least two elements, remove the smallest and recurse
//else return the head of the list/We have
@ShaneDelmore
ShaneDelmore / scalaj-http.scala
Last active December 4, 2015 23:28
scalaj-http with ammonite
//I put this in my ammonite predef.scala
load.ivy("org.scalaj" %% "scalaj-http" % "2.1.0")
import scalaj.http._
//Then in ammonite I can make blocking http calls which works well in the repl
Http("https://wtfismyip.com/text").asString.body
sealed trait List2[+A] // `List` data type, parameterized on a type, `A`
case object Nil2 extends List2[Nothing] // A `List` data constructor representing the empty list
/* Another data constructor, representing nonempty lists. Note that `tail` is another `List[A]`,
which may be `Nil` or another `Cons`.
*/
case class Cons2[+A](head: A, tail: List2[A]) extends List2[A]
object List2 { // `List` companion object. Contains functions for creating and working with lists.
def sum(ints: List2[Int]): Int = ints match { // A function that uses pattern matching to add up a list of integers
case Nil2 => 0 // The sum of the empty list is 0.
case Cons2(x,xs) => x + sum(xs) // The sum of a list starting with `x` is `x` plus the sum of the rest of the list.
@ShaneDelmore
ShaneDelmore / predef.scala
Created December 8, 2015 23:05
Ammonite predef
load.ivy("com.lihaoyi" %% "ammonite-shell" % ammonite.Constants.version)
load.ivy("org.scalaj" %% "scalaj-http" % "2.1.0")
@
val sess = ammonite.shell.ShellSession()
import sess._
import ammonite.ops._
import ammonite.shell._
import scalaj.http._
ammonite.shell.Configure(repl, wd)
@ShaneDelmore
ShaneDelmore / ScalaMock.scala
Created March 2, 2016 23:36
Stateful mocking, useful for mocking database calls and other stateful things with ScalaMock
//Paste into a scala worksheet to run
import org.scalatest.FlatSpec
import org.scalatest.ShouldMatchers
import org.scalamock.scalatest.MockFactory
trait Foo {
def getFoo: Int
}
@ShaneDelmore
ShaneDelmore / TheLogger.scala
Created August 5, 2016 04:58
Singleton logger instead of extending ClassLogging everywhere you log
//Depends on https://github.com/nestorpersist/logging
import java.net.InetAddress
import akka.actor.ActorSystem
import com.persist.logging.{ ClassLogging, Logger, LoggingSystem }
/**
* The purpose of this object is to provide a shared logger for use throughout the program
* To use instead of mixing ClassLogging into a class use the following import:
* import TheLogger.{ logInstance => log }