Skip to content

Instantly share code, notes, and snippets.

View agibralter's full-sized avatar
:shipit:

Aaron Gibralter agibralter

:shipit:
View GitHub Profile
class User < ActiveRecord::Base
has_many :posts do
def find_or_create
first || create
end
end
end
class Post < ActiveRecord::Base
belongs_to :user
# app/models/question_picker/base.rb
module QuestionPicker
class Base
end
end
# WTF?
# Expected .../app/models/question_picker/base.rb to define Base (LoadError)
@agibralter
agibralter / gist:1199092
Created September 6, 2011 21:54
This used to work in rails 2.3.x and now doesn't work in rails 3.1...
# .../activesupport-3.1.0/lib/active_support/dependencies.rb:490:in `load_missing_constant': Expected .../app/models/user/stuff.rb to define User::Stuff (LoadError)
# ---
# config/application.rb:
# Add model subdirectories.
config.autoload_paths += Dir[
File.join(Rails.root, 'app', 'models', '**')
].reject { |f| !File.directory?(f) }
# ---
@agibralter
agibralter / asset_fingerprints.rb
Created August 24, 2011 22:34
This file lives in lib/ and I have `require 'asset_fingerprints'` in my config/environment.rb. Note this is for Rails 2.3.x.
# Same as deployment nginx configuration.
# No font/woff because it is already compressed:
# http://www.pixelastic.com/blog/87:gzipping-your-font-files
AssetHash::Base.gzip_types = %w(
application/javascript
application/json
application/xml
application/rss+xml
application/vnd.ms-fontobject
@agibralter
agibralter / foo.rb
Created June 11, 2011 20:33
I would like to compile a stylesheet from a combination of dynamic scss stored in the DB and a file.
class Foo < ActiveRecord::Base
# extra_scss stored in DB
@@foo = File.join(
Rails.root,
'app',
'stylesheets',
'foo.scss'
)
environment = {
"HOME" => "/root",
"PATH" => node.app[:path]
}
bash "kill almighty GOD!" do
user "root"
cwd "#{node.app[:deploy_to]}/current"
code "bin/god terminate; sleep 10"
environment environment
@agibralter
agibralter / poiter-events.js
Created June 5, 2011 18:02
Testing for real pointer-events:none support with javascript.
var midoverlay = $("#middle-overlay").hide();
if ("pointerEvents" in document.createElement("div").style) {
midoverlay.show();
// Some browsers think they support it, but really do not... (Opera, I'm looking at you)
setTimeout(function () {
var offset, test;
offset = midoverlay.offset();
test = document.elementFromPoint(offset.left + 1, offset.top + 1);
if (!test || test.id === "middle-overlay") {
midoverlay.hide();
server {
listen 443;
ssl on;
server_name foo.com;
root /home/app/public;
location / {
# 503s from haproxy do not display /errors/503.html...
proxy_pass http://haproxy;
@agibralter
agibralter / asset_fingerprints.rb
Created May 25, 2011 19:39
Using Jammit and asset_hash with Rails 2.3.11 (Also, using my fork of asset_hash to avoid a Rails 3.x `require` conflict: https://github.com/agibralter/asset_hash)
# lib/asset_fingerprints.rb -- A hack to get asset_hash to play nice with Rails 2.3.11 (since there is no ActionController::Base.asset_path configuration option).
# Same as deployment nginx configuration.
# No font/woff because it is already compressed:
# http://www.pixelastic.com/blog/87:gzipping-your-font-files
AssetHash::Base.gzip_types = %w(
application/javascript
application/json
application/xml
location ~* -[0-9a-f]{32}\.(ico|css|js|gif|jpe?g|png|eot|ttf|otf|woff|svg)(\.gz)?$ {
expires max;
}
#=> nginx: [emerg] unknown directive "32}\.(ico|css|js|gif|jpe?g|png|eot|ttf|otf|woff|svg)(\.gz)?$
# ahh of course... have to escape the brackets for nginx's parser:
location ~* "-[0-9a-f]{32}\.(ico|css|js|gif|jpe?g|png|eot|ttf|otf|woff|svg)(\.gz)?$" {
expires max;