Skip to content

Instantly share code, notes, and snippets.

View abachman's full-sized avatar
🙌
good times

Adam Bachman abachman

🙌
good times
View GitHub Profile
@abachman
abachman / treelike.rb
Created June 18, 2010 00:40
livecoding practice 2010-06-17
# Treelike
# livecoding practice, 2010-06-17, 40min
# going for something like a tree. This isn't exactly what I
# saw in my brain when I started, but it's interesting.
# especially when the @d value starts getting very small.
# image at http://www.flickr.com/photos/16913236@N04/4710032223/
class Treelike < Processing::App
class Leaf
@abachman
abachman / pom.rb
Created June 18, 2010 16:55 — forked from ngauthier/pom.rb
pomodoro timer
#!/usr/bin/env ruby
def notify(msg)
puts "[#{ Time.now.strftime "%H:%M:%S" }]: #{msg}"
`notify-send -i /home/adam/Documents/images/icons/pomodoro.png "Pomodoro" "#{msg}"`
end
POMODORO = ARGV.size > 0 ? ARGV[0].to_i : 25
REST = ARGV.size > 1 ? ARGV[1].to_i : 5
if ARGV.length > 2
# Circle Grid
# https://picasaweb.google.com/adam.bachman/LivecodePractice20100618
require 'ostruct'
class CircleGrid < Processing::App
def setup
background 255
ellipse_mode CENTER
stroke_width 20
frame_rate 30
@abachman
abachman / better-ruby-idioms.rb
Created July 28, 2010 15:32
Simpler, idiomatic Ruby for extending Rails
# Simpler, idiomatic Ruby for extending Rails.
#
# http://yehudakatz.com/2009/11/12/better-ruby-idioms/
#
module Yaffle
# any method placed here will apply to classes, like Hickwall
def acts_as_yaffle
send :include, InstanceMethods
end
@abachman
abachman / scoped_javascript_function_definitions.js
Created August 12, 2010 17:54
The Practical Difference Between Function Statements and Function Expressions
/*
2010-08-12 #standup
The Practical Difference Between Function Statements and Function Expressions
jslint tells me this is illegal:
*/
$(function () {
- form_for @screen do |f|
- Asset.all.each do |asset|
%label
= check_box_tag 'screen[asset_ids][]', asset.id, @screen.asset_ids.include?(asset.id)
= asset.name
= f.submit
@abachman
abachman / functions-are-not-closures.js
Created August 24, 2010 19:22
javascript functions are not closures.
// javascript functions are not closures. They do not behave in the way I would expect.
var funcs = [];
for (var i=0; i < 10; i++) {
funcs.push(function() { document.writeln(i); });
}
for (var n=0; n < 10; n++) {
funcs[n]();
}
@abachman
abachman / quickerclip.rb
Created October 7, 2010 17:57
avoid relying on slow image magick commands while testing
module Paperclip
class FixtureFile
def self.load(path)
@@spec_file_helper_file_descriptors ||= {}
@@spec_file_helper_file_descriptors[path] ||=
File.new(File.join(Rails.root, 'spec', 'fixtures', path))
@@spec_file_helper_file_descriptors[path].rewind
return @@spec_file_helper_file_descriptors[path]
end
@abachman
abachman / conditional_chaining_with_tap.rb
Created October 12, 2010 04:01
Conditional query chaining in Rails 3
# I want a list of 6 non-administrators who are not the
# current user only if someone is logged in. Otherwise,
# don't check current_user's id.
# instead of this:
if user_signed_in?
@other_users = User.non_admin.limit(6).where("name IS NOT NULL")
else
@other_users = User.non_admin.limit(6).where(['id != ?', @user.id]).where("name IS NOT NULL")
/9j/4AAQSkZJRgABAgAAZABkAAD/7AARRHVja3kAAQAEAAAAPAAA/+4ADkFkb2JlAGTAAAAAAf/b
AIQABgQEBAUEBgUFBgkGBQYJCwgGBggLDAoKCwoKDBAMDAwMDAwQDA4PEA8ODBMTFBQTExwbGxsc
Hx8fHx8fHx8fHwEHBwcNDA0YEBAYGhURFRofHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8f
Hx8fHx8fHx8fHx8fHx8fHx8f/8AAEQgCbgMvAwERAAIRAQMRAf/EAMkAAAICAwEBAQAAAAAAAAAA
AAECAAMEBQYHCAkBAQEBAQEBAQEAAAAAAAAAAAACAQMEBQYHEAABAwIEAwQGBAcMBwUFBwUCAAED
EQQhMRIFQSIGUTITB2FxQlJiFIEjMwiRcoKyQ1MVobGS0iQ0dLQ1dRY3waLCY3OzJfBElNQY0fKD
01fik6MmNlYXVGSExFURAQEAAwACAQMBBgQEBAcBAAABEQIDEgQh8DEFE0FR0eEyFHGx8SKBkaFS
YZIjM8FCYnIkNBVT/9oADAMBAAIRAxEAPwDil7HkMGeCC93wUsQdSCwlgj4sgHKyERGq9VXWKUSl
mi2NxRquTvOglv8AbB61z3+xXqPTfe+Ki+V3+7lXQSPivE5ViF3kQrkyRqnXR0Ad65KQDLClUFCw
FAh5IpXUu1A4v6UCPmgxpnoNFTdVBlSiO+rSdS6ntmp2r3cVObFiX0Nfsio+p1Si6C4IJpKqJB9V