Skip to content

Instantly share code, notes, and snippets.

# db/migrate/XXXXXXXXXXXXX_add_authentication_token_to_users.rb
class AddAuthenticationTokenToUsers < ActiveRecord::Migration
def change
add_column :users, :authentication_token, :string
add_index :users, :authentication_token, :unique => true
end
end
@ybart
ybart / DB Evolutions
Last active December 30, 2015 17:49 — forked from larste/DB Evelutions
Add support for db evolutions:
Download the sqlite-dialect from here: https://github.com/gwenn/sqlite-dialect
Compile it to a jar file.
Add the jar file the app/lib folder.
@ybart
ybart / ruby-deb.sh
Last active December 24, 2015 16:19
Generate a Ruby 2.0 deb package for Ubuntu 12.04 LTS Taken from https://github.com/hemanth/futhark/blob/master/ruby-deb.sh
#!/bin/bash
apt-get install ruby rubygems
gem1.8 install fpm --no-ri --no-rdoc
apt-get install build-essential openssl libreadline6 libreadline6-dev \
zlib1g zlib1g-dev libssl-dev ncurses-dev libyaml-dev
wget http://ftp.ruby-lang.org/pub/ruby/ruby-2.0-stable.tar.gz
App.AuthenticatedRoute = Ember.Route.extend
redirect: ->
controller = App.__container__.lookup('controller:user')
unless controller.get 'isSignedIn'
App.application.set('nextRoute', @routeName)
App.application.set('nextContext', @context)
@transitionTo 'index' # this is the login page
deserialize: (params) ->
context = @_super(params)
fastcgi_cache_path /tmp/nginx-cache levels=1:2 keys_zone=wordpress:20m inactive=1d max_size=512M;
upstream php-fpm {
server localhost:9000;
}
server {
listen 1.2.3.4:80;
listen [1:2:3:4::5]:80;
server_name blog.example.com
module Associations # :nodoc:
extend ActiveSupport::Concern
module ClassMethods
def has_many(name, options = {}, &extension)
Builder::HasMany.build(self, name, options, &extension)
end
end
end
applications_licenses GET /licenses/applications(.:format) {:action=>"applications", :controller=>"licenses"}
GET /licenses(.:format) {:action=>"index", :controller=>"licenses"}
POST /licenses(.:format) {:action=>"create", :controller=>"licenses"}
GET /licenses/new(.:format) {:action=>"new", :controller=>"licenses"}
GET /licenses/:id/edit(.:format) {:action=>"edit", :controller=>"licenses"}
GET /licenses/:id(.:format) {:action=>"show", :controller=>"licenses"}
PUT /licenses/:id(.:format) {:action=>"update", :controller=>"licenses"}
DELETE /licenses/:id(.:format) {:action=>"destroy", :controller=>"licenses"}
@ybart
ybart / radio.rb
Created August 17, 2011 08:34
Wrong Relationship
> ActiveRecord::Base.logger = Logger.new(STDOUT)
> Infrastructure::Radio.first
Infrastructure::Radio Load (0.8ms) SELECT "radio_channels".* FROM "radio_channels" LIMIT 1
+----+------------+
| id | ut_id_name |
+----+------------+
| 1 | 245 |
+----+------------+
> counter = 0; Infrastructure::Radio.first.foo.each {counter += 1}; puts counter
module ActiveRecord
class Base
class << self
alias_method :old_method_missing, :method_missing
def method_missing(method_id, *arguments, &block)
if /^find_or_build_by_([_a-zA-Z]\w*)$/ =~ method_id.to_s
names = $1.split('_and_')
relation.find_or_build_by(names, *arguments)
else
@ybart
ybart / gist:1070803
Created July 7, 2011 23:42
Google +1 Bookmarklet (Bottom Right)
javascript:(function(){div=document.createElement('div');e=document.createElement('g:plusone');div.style.position='fixed';div.style.bottom='8px';div.style.right='8px';div.appendChild(e);document.body.appendChild(div);e=window.document.createElement('script');e.setAttribute('src','https://apis.google.com/js/plusone.js');document.body.appendChild(e);})();