This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
➜ 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//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 } |
OlderNewer