Skip to content

Instantly share code, notes, and snippets.

View coalwater's full-sized avatar

Mohammad AbuShady coalwater

  • Amsterdam, Netherlands
  • 15:25 (UTC +02:00)
View GitHub Profile
@coalwater
coalwater / basic_models.rb
Created March 2, 2015 18:25
Using active record's #merge to separate concerns
class User < ActiveRecord::Base
has_many :dvds
end
class Dvd < ActiveRecord::Base
belongs_to :user
end
@coalwater
coalwater / delegate_with_allow_nil.rb
Last active August 29, 2015 14:16
law of demeter and rails delegation
class Order < ActiveRecord::Base
delegate :name, :price, to: :item, prefix: true, allow_nil: true
delegate :number, to: :invoice, prefix: true, allow_nil: true
end
@coalwater
coalwater / puma.conf
Last active August 29, 2015 14:14
nginx config for puma
upstream puma_upstream { # rename this to be unique
server unix://path/to/sock;
}
server {
listen 80;
client_max_body_size 4G;
keepalive_timeout 10;
server_name example.com;
@coalwater
coalwater / .gitignore
Created January 24, 2015 15:02
My global .gitignore
*.swp
*.orig
/.idea
/tags
@coalwater
coalwater / Gemfile
Created January 24, 2015 12:34
Some rails gems that I often use, just to keep track
# app server
gem 'puma'
# Factories for testing https://github.com/thoughtbot/factory_girl
gem 'factory_girl'
# Random data https://github.com/stympy/faker
gem 'faker'
# easy breadcrumbs
@coalwater
coalwater / dnsmasq.conf
Last active August 29, 2015 14:08
dnsmasq config
listen-address=127.0.0.1
address=/.dev/127.0.0.1
@coalwater
coalwater / multiple-hosts.config
Last active August 29, 2015 14:08
Using different ssh keys for different hosts
Host vps1
IdentityFile ~/.ssh/vps1
Port 5432
Hostname 11.22.33.44
User root
Host vps2
IdentityFile ~/.ssh/vps2
Port 22
Hostname 12.34.56.78
@coalwater
coalwater / rater_controller.patch
Created August 31, 2014 12:15
Fix security vulnerability in letsrate rater_controller
From 49344cfeb2f57347a09f0b5764c25792a2768d71 Mon Sep 17 00:00:00 2001
From: Mohammad AbuShady <coalwater5@gmail.com>
Date: Sun, 31 Aug 2014 14:34:58 +0300
Subject: [PATCH] Fix security vulnerability in rater_controller
---
app/controllers/rater_controller.rb | 21 ++++++++-------------
1 file changed, 8 insertions(+), 13 deletions(-)
diff --git a/app/controllers/rater_controller.rb b/app/controllers/rater_controller.rb
@coalwater
coalwater / collect-example.rb
Last active August 29, 2015 14:05
Select, Reject, Collect, Detect, Inject
y = [1,2,3,4].collect {|number| number ** 2 }
# y will equal [1, 4, 9, 16]