Skip to content

Instantly share code, notes, and snippets.

View n00ge's full-sized avatar
💭
Writing code at The Futures App

Chad Calhoun n00ge

💭
Writing code at The Futures App
View GitHub Profile
@n00ge
n00ge / Nil.sublime-theme
Created June 18, 2012 13:37
Sublime Text 2 Theme Override for Nil Theme
[
{
"class": "tabset_control",
"tab_height": 32
}
]
@n00ge
n00ge / gist:3237152
Created August 2, 2012 13:37
Email validation
def valid_email?(email)
email =~ /^(|(([a-z0-9]+_+)|([a-z0-9]+\-+)|([a-z0-9]+\.+)|([a-z0-9]+))*[a-z0-9]+@([a-z0-9]{1})(([a-z0-9]+\-+)|([a-z0-9]+\.))*[a-z0-9\-\.]{1,62}\.[a-z]{2,6})$/i
end
@n00ge
n00ge / gist:3313079
Created August 10, 2012 09:51
Turn on git colors
git config --global color.ui true
@n00ge
n00ge / gist:3559604
Created August 31, 2012 21:48
Describe classes (output associations and attributes)
[ClassName].each do |object|
puts "#{object.name} ("
puts "\t# associations"
reflections = object.reflect_on_all_associations
reflections.each do |reflection|
puts "\t#{reflection.macro} => #{reflection.name.to_s.classify}"
end
puts ""
puts "\t# attributes"
object.new.attributes.each do |attribute|
@n00ge
n00ge / gist:3892456
Last active October 11, 2015 17:17
Rails attribute changed?
my_model = MyModel.find(:first)
my_model.changed? # it will return false
# You can Track changes to attributes with my_model.name_changed? accessor
my_model.name # returns "Name"
my_model.name = "New Name"
my_model.name_changed? # returns true
# Access previous value with name_was accessor
my_model.name_was # "Name"
@n00ge
n00ge / gist:5758933
Created June 11, 2013 17:34
Method sorting (Alphabetical)
class AlphabeticalService
def go!
method_a
method_b
end
private
def method_a
return if method_e?
@n00ge
n00ge / gist:5758934
Created June 11, 2013 17:34
Method sorting (1st occurance)
class FirstOccuranceService
def go!
method_a
method_b
end
private
def method_a
return if method_e?
@n00ge
n00ge / gist:5758935
Created June 11, 2013 17:34
Method sorting (last occurance)
class LastOccuranceService
def go!
method_a
method_b
end
private
def method_a
return if method_e?
@n00ge
n00ge / gist:6554340
Created September 13, 2013 18:32
Initializing a new SVN Repo with Git-SVN
git init
git status
svn mkdir --parents https://url.com/repo/trunk -m "Creating trunk"
git svn init https://url.com/repo -s
git svn fetch
git status
git branch -r
git svn rebase
git svn dcommit -n
git add -i
@n00ge
n00ge / gist:6779758
Last active December 24, 2015 09:49 — forked from JonoB/gist:6637861
A fix for unique validation when updating models in Laravel 4
<?php namespace Tmb;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Validation\Validator;
class BaseModel extends Eloquent
{
/**
* Error message bag