Skip to content

Instantly share code, notes, and snippets.

View amalkov's full-sized avatar

Alex Malkov amalkov

View GitHub Profile
@amalkov
amalkov / shoulda_cheatsheet.rb
Created February 25, 2013 23:47
Shoulda activemodel cheatsheet
# Shoulda activemodel cheatsheet
# DB
should have_db_column(:title).of_type(:string).with_options(default: 'Untitled', null: false)
should have_db_index(:email).unique(:true)
# Associations
should belong_to :company
should have_one(:profile).dependent(:destroy)
should have_many(:posts).dependent(:nullify)
@amalkov
amalkov / hack.sh
Created April 17, 2012 09:35
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@amalkov
amalkov / gist:1322010
Created October 28, 2011 10:03
Triggers
DELIMITER $$
DROP TRIGGER IF EXISTS hotel_au_trg$$
CREATE TRIGGER hotel_au_trg AFTER UPDATE ON hotels
FOR EACH ROW
BEGIN
IF (OLD.name != NEW.name OR (OLD.name IS NULL AND NEW.name IS NOT NULL)) THEN
REPLACE INTO audits values ('',NEW.id,'name',NOW(),NULL,NULL);
END IF;
IF (OLD.latitude != NEW.latitude OR (OLD.latitude IS NULL AND NEW.latitude IS NOT NULL)) THEN
REPLACE INTO audits values ('',NEW.id,'latitude',NOW(),NULL,NULL);