Skip to content

Instantly share code, notes, and snippets.

View jlogsdon's full-sized avatar

James Logsdon jlogsdon

View GitHub Profile
#!/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
var Neave = Neave || {};
(function (e) {
var d = false,
g = 0,
b = 0,
i = 0;
function h() {
d = true;
$("#lang").show();
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
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
@jlogsdon
jlogsdon / solution.rb
Created May 1, 2012 20:35 — forked from isa/gist:2571012
Convert in less than 30 lines
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
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?
@jlogsdon
jlogsdon / gist:2331111
Created April 7, 2012 18:20
Small test script to test table generation with more than a few rows and columns.
<?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);
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
@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}]
foo = Hash.new("Hello")
foo[:bar] << ' World'
foo[:baz] == "Hello World"