Skip to content

Instantly share code, notes, and snippets.

View justincampbell's full-sized avatar
🌯
🍩

Justin Campbell justincampbell

🌯
🍩
View GitHub Profile
# Return nested hash element, or nil if hash structure does not match
# no checking
def find_third(id)
input = find_input(id)
input['first']['second']['third']
end
# begin/rescue/end
def find_third(id)
Thing = Struct.new(:name)
things = [
Thing.new("PlayStation"),
Thing.new("Xbox")
] # => [#<struct Thing name="PlayStation">, #<struct Thing name="Xbox">]
things.find { |thing| thing.name == "PlayStation" } # => #<struct Thing name="PlayStation">
people = [
class Cat
def make_sound
'meow'
end
end
# Anonymous classes assigned to a constant get the name of that constant
klass = Class.new do
def make_sound
'woof'
$ ruby pairs-using-pairs.rb
Jeff & Dan
Jason & Dotcom
Mox & Jearvon
Mike & Matt
Justin
package main
import (
"fmt"
"time"
)
var noTime time.Time
func main() {
require 'benchmark'
require 'redis'
class Redis
def del(*keys)
synchronize do |client|
client.call([:del] + keys)
end
end
require 'benchmark'
require 'redis'
class Redis
def del(*keys)
synchronize do |client|
client.call([:del] + keys)
end
end
import org.specs._
import dispatch.classic.Http
import dispatch.classic.Request
import dispatch.StatusCode
object AppSpec extends Specification with unfiltered.spec.jetty.Served {
def setup = _.filter(new App)
val http = new Http
prefixes = [
"Code",
"Software"
]
nouns = [
"Artisans",
"Codesmiths",
"Crafters",
"Craftspeople",

Charged

Now drawing from 'AC Power'
 -InternalBattery-0     100%; charged; 0:00 remaining

Discharging

Now drawing from 'Battery Power'
 -InternalBattery-0     100%; discharging; (no estimate)