Skip to content

Instantly share code, notes, and snippets.

View theCrab's full-sized avatar
💭
What happens when you take a long holiday from work? Shit happens

The Crab theCrab

💭
What happens when you take a long holiday from work? Shit happens
View GitHub Profile
@theCrab
theCrab / ruby-2.3.0.rb
Created May 3, 2017 22:24 — forked from fightingtheboss/ruby-2.3.0.rb
Examples of new features in Ruby 2.3.0
# These are examples of new features in Ruby 2.3.0
#---------------------------------------------------------------------------
## Did You Mean?
"Typos suck less now".revers
# NoMethodError: undefined method `revers' for "Typos suck less now":String
# Did you mean? reverse
# reverse!
@theCrab
theCrab / Rakefile
Created April 28, 2016 16:46 — forked from dblandin/Rakefile
RubyMotion Configuration and Deploy/Release
# -*- coding: utf-8 -*-
$:.unshift('/Library/RubyMotion/lib')
require 'motion/project/template/ios'
require 'bundler'
Dir.glob('./config/*.rb').each { |file| require file }
if ARGV.join(' ') =~ /spec/
Bundler.require :default, :development, :spec
elsif ARGV.join(' ') =~ /testflight/
@theCrab
theCrab / puma.rb
Last active August 29, 2015 14:26 — forked from yamaaki/puma.rb
# Start Puma with next command:
# RAILS_ENV=production bundle exec puma -C ./config/puma.rb
# uncomment and customize to run in non-root path
# note that config/puma.yml web path should also be changed
application_path = "#{File.expand_path("../..", __FILE__)}"
# The directory to operate out of.
#
# The default is the current directory.
worker_processes 1;
user nobody nogroup;
pid /tmp/nginx.pid;
error_log /tmp/nginx.error.log;
events {
worker_connections 1024;
accept_mutex off;
}
http {
default_type application/octet-stream;
class Friendship < ActiveRecord::Base
attr_accessible :friend_id, :user_id, :status
belongs_to :user
belongs_to :friend, :class_name => 'User', :counter_cache => :friends_count
def self.request(user, friend)
unless user == friend or Friendship.where(:user_id => user, :friend_id => friend).exists?
transaction do
create({:user => user, :friend => friend, :status => 'pending'}, :without_protection => true)
create({:user => friend, :friend => user, :status => 'requested'}, :without_protection => true)