Skip to content

Instantly share code, notes, and snippets.

View krasio's full-sized avatar
🎣
Gone fishing

Krasimir Angelov krasio

🎣
Gone fishing
View GitHub Profile
if [ "\$(type -t __git_ps1)" ]; then
PS1="\$(__git_ps1 '[%s]')$PS1"
fi
[alias]
c = commit -m
a = add
di = diff
dic = diff --cached
pl = pull
ps = push
plre = pull --rebase
st = status
out = log origin..HEAD
# config/environment.rb
# setting default timezone for your app when firing up Rails
config.time_zone = 'UTC'
# app/controllers/application_controller.rb
# changing timezone to one selected by user if logged in
before_filter :set_time_zone
def set_time_zone
Time.zone = current_user.time_zone if logged_in?
end
# app/models/user.rb
class User
include Mongoid::Document
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable, :lockable and :timeoutable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
end
# features/support/configuration.rb
Before do
Neo4j::Transaction.run do
Neo4j._all_nodes.each { |n| n.del unless n.neo_id == 0 }
end
end
# spec/support/configuration.rb
def delete_all
Neo4j::Transaction.run do
module Resque
class Job
alias_method :original_perform, :perform
def perform
original_perform
rescue ActiveRecord::StatementInvalid => e
if e.message =~ /server has gone away/i
ActiveRecord::Base.verify_active_connections!
retry
module Inspector
def self.analyze(data)
registered_plugins.each do |name, block|
puts "Report: #{name}"
block.call(data)
end
end
def self.registered_plugins
@registered_plugins ||= {}
@krasio
krasio / authentication_macros.rb
Created November 18, 2011 08:38
Rails controller specs with Devise
# spec/support/macros/authentication_macros.rb
module AuthenticationMacros
def sign_in_user
let(:current_user) { Factory.stub(:user) }
before do
sign_in current_user
warden.stub(:authenticate => current_user)
warden.stub(:authenticate! => current_user)
end
@krasio
krasio / passenger_process.rb
Created December 2, 2011 14:31 — forked from leejones/passenger_process.rb
Remove orphaned passenger processes.
require 'chronic'
class PassengerProcess
attr_accessor :pid, :uptime
def initialize(passenger_status_line)
values = passenger_status_line.match(/PID:\s(\d*).*Uptime:\s*(.*)$/)
@pid = values[1].to_i
@uptime = values[2]
end
@krasio
krasio / new-vm.textile
Created December 14, 2011 14:03 — forked from petyosi/new-vm.textile
Instructions on setting up new work VM.

Installation

  • Update your VirtualBox
  • Download ubuntu LTS server (64 bit)
  • name “garmz-dev”
  • Run default installation from the downloaded iso in new VM
    • hostname “garmz-dev”
    • Don’t encrypt home
    • No automatic updates
    • Pick OpenSSH server and PostgreSQL server