Skip to content

Instantly share code, notes, and snippets.

@adparadise
adparadise / typography1.css
Created July 27, 2012 20:08
Typography example
body {
font: normal 100% Helvetica, Arial, sans-serif;
}
@adparadise
adparadise / responsive_layout.css
Created July 27, 2012 20:05
Responsive Layout example
/*Mobile first:*/
.container { width: 16em; }
/*Tablet in Portrait Orientation:*/
.container { width: 32em; }
@media (max-width: 33em) {
.container { width: 16em; }
}
/*Full Experience:*/
@adparadise
adparadise / fluid_grid_example.css
Created July 27, 2012 20:03
Fluid Grid example
div.page {
width: 90%;
margin: auto;
}
div.left_column {
width: 58.333333%
}
div.right_column {
@adparadise
adparadise / colorize.rb
Created December 9, 2011 01:36
A simple script to colorize logs piped through it.
#!/usr/bin/env ruby
require 'rubygems'
require 'term/ansicolor'
ARGF.each_line do |line|
color = case line
when /^ERROR/ then Term::ANSIColor.red
when /^WARN/ then Term::ANSIColor.yellow
when /^INFO/ then Term::ANSIColor.green
else ""
@adparadise
adparadise / interleave.rb
Created December 9, 2011 01:35
A simple script to interleave several files, which may be very large
#!/usr/bin/env ruby
filenames = ARGV
usage = "USAGE: interleave.rb <filename> ..."
unless filenames.length > 0
STDERR.write(usage + "\n")
exit(1)
end
@adparadise
adparadise / commandline.rb
Created December 9, 2011 01:34
Boilerplate for ruby command line utilities
#!/usr/bin/env ruby
filename = ARGV[0]
usage = "USAGE: commandline.rb <filename>"
unless filename
STDERR.write(usage + "\n")
exit(1)
end
@adparadise
adparadise / gist:1447917
Created December 8, 2011 18:21
Replace a file with altered contents
file = File.new(filename)
contents = file.read
newfile = Tempfile.new(filename)
begin
contents.each do |line|
newfile.write("// " + line)
end
newfile.flush
@adparadise
adparadise / gist:1447798
Created December 8, 2011 17:49
Simple directory recursion for pathnames
require 'pathname'
def each_recursive(dirpath, &block)
dirpath.each_entry do |entry|
next if "." == entry.to_s || ".." == entry.to_s
entry_path = dirpath + entry
if entry_path.directory?
each_recursive(entry_path, &block)
else
@adparadise
adparadise / user_input.rb
Created December 8, 2011 04:59
Simple class to prompt a user on the command line for a response.
class UserInput
# Prompt for confirmation, exiting if not an affirmative.
def self.confirm!(message)
unless confirm(message)
STDERR.write("cancelling...\n")
exit
end
end
# Prompt for confirmation, returning a boolean indicating user's preference.
@adparadise
adparadise / largefile.rb
Created December 8, 2011 04:56
Trivial example of traversing a large file via command line.
#!/usr/bin/env ruby
filename = ARGV[0]
usage = "USAGE: largefile.rb <filename>"
unless filename
STDERR.write(usage + "\n")
exit(1)
end