Skip to content

Instantly share code, notes, and snippets.

View jamilbk's full-sized avatar
🔥
Everything's fine

Jamil jamilbk

🔥
Everything's fine
View GitHub Profile
#### image_map_coordinate.rb ####
class ImageMapCoordinate < ActiveRecord::Base
belongs_to :image_map
# FIXME: validation bug?
%w(w h x y).each do |v|
validates_numericality_of eval ":#{v}"
end
validate :href_validator
@jamilbk
jamilbk / schedule.rb
Created May 3, 2012 08:02
example showing possible Rufus production env quirks
# Example of how I'm using Rufus. I'm basically starting a scheduler, then
# using my backend to persist the job_id for the option to cancel it later.
# config/initializers/schedule.rb
SCHEDULER = Rufus::Scheduler.start_new
@jamilbk
jamilbk / gist:3861162
Created October 9, 2012 20:17
Clean Install – Mountain Lion OS X 10.8 DP3 Update 4
@jamilbk
jamilbk / nestedform
Created December 1, 2012 02:58 — forked from robertwclark/nestedform
Nested Form Build
class Organization < ActiveRecord::Base
attr_accessible :name, :employee_number, :country, :postal_code, :sic_code, :primary_url, :social_entities_attributes, :social_channels_attributes
has_one :user
has_one :social_score, :through => :social_entities
has_many :social_entities
has_many :social_channels, :through => :social_entities
accepts_nested_attributes_for :social_entities, :social_channels
end
@jamilbk
jamilbk / stuffed_table_columns.rb
Last active December 11, 2015 06:19
Implement status states in code using an integer column in the DB.
# Implement status states in code using an integer column in the DB
# Written by Jamil Bou Kheir, 2012
#
# Include this module at the top of your model and use the stuffed_table_columns
# method to assign the mappings. Requires a matching integer column present.
# Ex:
#
# class StirFry < ActiveRecord::Base
# include StuffedTableColumns
# stuffed_column :status, 'cold', 'hot', 'pickled', 'spicy', 'no_msg', 'noodling'
# Fixes OS X clipboard under tmux
set-option -g default-command "reattach-to-user-namespace -l zsh"
# Allows for faster key repetition
set -s escape-time 0
# Rather than constraining window size to the maximum size of any client
# connected to the *session*, constrain window size to the maximum size of any
# client connected to *that window*. Much more reasonable.
setw -g aggressive-resize on
@jamilbk
jamilbk / gist:5629254
Created May 22, 2013 17:17
git ignore
.DS_Store
*.tmproj
log/*.lck
log/*.log
public/uploads
*.*.sw*
.notes
@jamilbk
jamilbk / jshintrc
Created June 11, 2013 00:37
jshintrc
{
// See http://www.jshint.com/options/ for in-depth explanations
// Predefined globals that JSHint ignores
"browser" : true, // standard globals like 'window'
"devel" : true, // development globals, e.g. 'console'
"nonstandard" : true, // widely-adopted globals, e.g. 'escape'
"node" : true,
"jquery" : true,
@jamilbk
jamilbk / message.js
Last active December 26, 2015 02:19
example of encrypted pgp-style message sending involving two recipients
// handle signed numbers
var toHex = function(decimalInt) {
if (decimalInt < 0) {
decimalInt += 0xFFFFFFFF + 1;
}
return decimalInt.toString(16).toUpperCase();
};
var set1, set2, set3, pair1, pair2, sym_key='';
@jamilbk
jamilbk / stuffed_table_columns.rb
Created February 27, 2015 21:24
Stuffed Table Columns
# Represent states such as 'active', 'disabled', etc in the DB as an int
#
# Use like so:
#
# class MyModel < ActiveRecord::Base
# include StuffedTableColumns
# stuffed_column :status, *(%w(active inactive blocked disabled banned))
# end
# TODO: use method_missing to match the column name