Skip to content

Instantly share code, notes, and snippets.

View bjeanes's full-sized avatar
🕊️

Bo Jeanes bjeanes

🕊️
View GitHub Profile
module BlahPlugin
VERSION = '1.0.0'
class << self
# add plugin to AR only if it hasn't been included before,
# which may cause stack-level-too-deep errors if you're aliasing methods
#
def enable_activerecord
return if ActiveRecord::Base.respond_to? :acts_as_blah
ActiveRecord::Base.extend BlahPlugin::Macro
@bjeanes
bjeanes / snippet.sh
Created January 16, 2009 23:29 — forked from drnic/snippet.sh
function parse_git_deleted {
[[ $(git status | grep deleted:) != "" ]] && echo "-"
}
function parse_git_added {
[[ $(git status | grep "Untracked files:") != "" ]] && echo '+'
}
function parse_git_modified {
[[ $(git status | grep modified:) != "" ]] && echo "*"
}
function parse_git_dirty {
(1..1325).to_a.each do |num|
link = "http://www.questionablecontent.net/comics/#{num}.png"
`curl #{link} > ~/Pictures/QC/#{num}.png &2>1`
puts "#{num} downloaded..."
end
controller_name, action_name = page.split(" ")
controller.controller_name.should == controller_name
controller.action_name.should == action_name
set :application, "TODO"
set :scm_username, "TODO"
set :user, application # assumes you create 1 user per app
set :domain, "#{application}.com" # this can be changed
set :use_sudo, false # everything is owned by user
role :app, domain # These options are fine for most cases
role :web, domain
<VirtualHost *:80>
ServerName sub.domain.com
ProxyPass / http://192.168.1.253:8080/
ProxyPassReverse / http://192.168.1.253:8080/
# The endpoint has a mandatory password that I want to avoid requiring users to type
# I.e. something like this would be nice (but does not work)
# ProxyPass / http://username:password@192.168.1.253:8080/
There are many like it.
>> (1..10).map(&:object_id)
=> [3, 5, 7, 9, 11, 13, 15, 17, 19, 21]
>> (-10..-1).map(&:object_id)
=> [-19, -17, -15, -13, -11, -9, -7, -5, -3, -1]
>> ObjectSpace._id2ref(-1)
=> -1
>> ObjectSpace._id2ref(-5)
=> -3
>> ObjectSpace._id2ref(-2) # if -2 = 0xfffffffe, then -1 == 0xffffffff
RangeError: 0xfffffffe is not id value
class Abc
def self.~@
puts "WTF"
end
end
~Abc # => "WTF"
class Point
attr_reader :x, :y
def initialize(x, y)
@x, @y = x, y
end
def ~ point
Math.sqrt((point.x - self.x) ** 2 +
(point.y - self.y) ** 2)