Skip to content

Instantly share code, notes, and snippets.

View cableray's full-sized avatar

Garrett cableray

View GitHub Profile
import time
print "..."
time.sleep(1)
print "..."
print "..."
print "..."
print "..."
time.sleep(1)
print "..."
@cableray
cableray / apple_record.rb
Last active July 8, 2017 19:05 — forked from sj26/apple_record.rb
How to do STI without separate controller per child: Utilize descendent tracking and override model_name so they use the same URL helpers and parameters as their base class. Makes things like responders and form_for work as expected, while preserving things like to_partial_path.
class AppleRecord < Record
end

Constant lookup in Ruby can happen lexically or through the ancestry tree of the receiver(a class or module). You can identify which lookup rules are being applied by the context you're in or by the syntax being used to define a class or module.

A class body that is defined as class A::B::C; …; end will lookup constants through the ancestry tree when a constant is evaluated in its class body. Anytime you see A::B::C being used as syntax to define a class or lookup the value of a constant the ancestry tree is being used for the lookup.

@willurd
willurd / web-servers.md
Last active May 9, 2024 05:48
Big list of http static server one-liners

Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.

Discussion on reddit.

Python 2.x

$ python -m SimpleHTTPServer 8000
@jvatic
jvatic / pre-commit.rb
Created May 16, 2012 16:00
Git pre-commit hook to block committing Spec files with :focus => true on test blocks
#!/usr/bin/env ruby
# vim: set syntax=ruby
flag = false
files = `git diff --cached --name-only --diff-filter=ACM | grep "_spec\.rb$"`.split("\n")
files.each do |file|
results = `git diff --cached #{file} | grep "^\+[^+]" | grep ":focus => true"`.split("\n").map { |r| r.sub(/^\+[\s\t]*/, '') }
if $? == 0