This file contains hidden or 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
#!/usr/bin/env ruby | |
rrd_out = `rrdtool fetch ./switch01_traffic.rrd AVERAGE` | |
rrd_out.each do |line| | |
puts "Some Prefix #{line}" | |
end | |
# Outputs: | |
# Some Prefix Line 1 | |
# Some Prefix Line 2 |
This file contains hidden or 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
var Neave = Neave || {}; | |
(function (e) { | |
var d = false, | |
g = 0, | |
b = 0, | |
i = 0; | |
function h() { | |
d = true; | |
$("#lang").show(); |
This file contains hidden or 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
describe '#valid_ip' do | |
it 'returns true given a valid IP address' do | |
subject.valid_ip('192.168.1.1').should be_true | |
# Throw several valid IPs here | |
end | |
it 'returns false given an invalid IP address' do | |
subject.valid_ip('fake').should be_false | |
# Throw several invalid IPs here | |
end |
This file contains hidden or 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
c = Configuration.new | |
c[:foo][:bar][:baz] = [1,2,3] | |
c['foo']['bar']['baz'] # => [1,2,3] | |
c[:foo] = {bar: :baz} | |
c[:foo][:another][:brick][:in][:the] = :wall | |
c # => {:foo => {:bar => :baz, :another => {:brick => {:in => {:the => :wall}}}}} | |
class Configuration < ::Hash |
This file contains hidden or 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
Question: Convert following into the latter data structure in less than 30 lines: | |
List: | |
A, B, C | |
A, C, E | |
E, F, D | |
D, A, J | |
E, D, J | |
List |
This file contains hidden or 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
class TwitterBootstrapFormFor::FormControls < ActionView::Helpers::FormBuilder | |
# Truncated! Full file is at https://github.com/jlogsdon/twitter_bootstrap_form_for/blob/master/lib/twitter_bootstrap_form_for/form_builder.rb | |
def check_box(attribute, text, options = {}, checked_value = 1, unchecked_value = 0) | |
klasses = _merge_classes 'checkbox', options.delete(:inline) && 'inline' | |
self.label(attribute, :class => klasses) do | |
template.concat super(attribute, options, checked_value, unchecked_value) | |
template.concat text | |
yield if block_given? |
This file contains hidden or 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
<?php | |
if (php_sapi_name() != 'cli') { | |
die('Must run from command line'); | |
} | |
error_reporting(E_ALL | E_STRICT); | |
ini_set('display_errors', 1); | |
ini_set('log_errors', 0); | |
ini_set('html_errors', 0); |
This file contains hidden or 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
class Mineral < ActiveRecord::Base | |
has_many :ore_contents | |
has_many :ores, :through => :ore_contents | |
end | |
class Ore < ActiveRecord::Base | |
has_many :ore_contents | |
has_many :minerals, :through => :ore_contents | |
validates_presence_of :batch_size |
This file contains hidden or 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
@ores = [ | |
{name: 'foo', cost: 100}, | |
{name: 'bar', cost: 100}, | |
{name: 'foo', cost: 100}, | |
{name: 'baz', cost: 100}, | |
{name: 'bar', cost: 100} | |
] | |
@ores.select { |o| o['name'] == 'foo' } => [{name: 'foo', cost: 100}, {name: 'foo', cost: 100}] |
This file contains hidden or 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
foo = Hash.new("Hello") | |
foo[:bar] << ' World' | |
foo[:baz] == "Hello World" |