Skip to content

Instantly share code, notes, and snippets.

View nbfritz's full-sized avatar

Nathan Fritz nbfritz

  • Spring Hill, TN
View GitHub Profile
#!/bin/sh
# requires graphicsmagick (brew install graphicsmagick)
for i in 1 2 3 4 5
do
gm convert \
-size 200x200 \
xc:black \
-gravity center \
-fill white \
require "test/unit"
require "./at-and-at-at-class"
class TestAtAtVariables < Test::Unit::TestCase
def test_direct_assignment
SampleClass.c = 1
assert_equal(1, SampleClass.c)
refute_equal(1, SampleSubClassA.c)
refute_equal(1, SampleSubClassB.c)
end
require "test/unit"
require "./at-and-at-at-class"
class TestAtAtVariables < Test::Unit::TestCase
def test_direct_assignment
SampleClass.b = 1
assert_equal(1, SampleClass.b)
refute_equal(1, SampleSubClassA.b)
refute_equal(1, SampleSubClassB.b)
end
require "test/unit"
require "./at-and-at-at-class"
class TestAtAtVariables < Test::Unit::TestCase
def test_direct_assignment
SampleClass.a = 1
assert_equal(1, SampleClass.a)
assert_equal(1, SampleSubClassA.a)
assert_equal(1, SampleSubClassB.a)
end
@nbfritz
nbfritz / at-and-at-at-class.rb
Last active September 28, 2015 14:56
@ and @@ blog
class SampleClass
# (#1) class-level setter and getter for a
def self.a=(value)
@@a = value
end
def self.a
@@a
end
# (#2) instance-level setter and getter for a
@nbfritz
nbfritz / Vagrantfile
Last active August 29, 2015 14:24
Rails Dev Environment vagrant file
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure(2) do |config|
config.vm.box = "ubuntu/vivid64"
config.vm.network "forwarded_port", guest: 3000, host: 3000
config.vm.provider "virtualbox" do |vb|
vb.memory = "1024"
end
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@nbfritz
nbfritz / string_timings.rb
Created September 4, 2014 12:22
Using + to spread strings across multiple lines is slower than using \
def timer
start_time = Time.now
1_000_000.times do
yield
end
Time.now - start_time
end
time_a = timer do
x = "this this this this this this this this this this this this this this this " +
@nbfritz
nbfritz / metaclass_instance_variables.rb
Last active August 29, 2015 14:04
Interesting experimentation with ruby metaclasses
require 'minitest/autorun'
class Monkey
@@m1 = "monkey"
class << self
attr_accessor :m2
end
def self.m1=(m)
#!/usr/bin/env ruby
require "thor"
require "yaml"
require "open3"
class App < Thor
MAILLOG_REGEX = /^.+:(?<timestamp>\w+\s+\d+ \d\d+:\d\d:\d\d) (?<server>[^\s]+) .+ to=<(?<to>[^>]+)>.+ relay=(?<relay>[^,]+),.+status=(?<status>.+)$/
# other mail analysis-type stuff...