Skip to content

Instantly share code, notes, and snippets.

View pokka's full-sized avatar
🌮
I may be slow to respond.

Pokka pokka

🌮
I may be slow to respond.
View GitHub Profile
skip_filter *_process_action_callbacks.map(&:filter), :only => [:action_goes_here]
@pokka
pokka / brew-rvm
Created May 26, 2015 06:38
brew&rvm
sudo mkdir /usr/local
sudo chown -R $USER /usr/local
curl -Lsf \
http://github.com/mxcl/homebrew/tarball/master | \
tar xvz -C /usr/local --strip 1
mkdir -p ~/.rvm/src && cd ~/.rvm/src && rm -rf ./rvm && \
git clone --depth 1 git://github.com/wayneeseguin/rvm.git && \
cd rvm && ./install
@pokka
pokka / mysql-dump-import.sh
Last active April 21, 2016 10:02
mysql dump & import
#import
gunzip < backupfile.sql.gz | mysql -uroot -ppassw database
#dump
mysqldump -h -u -p database | gzip > backupfile.sql.gz
#dump without schema(data only)
mysqldump --no-create-info --skip-triggers -h -u -p database | gzip > backupfile.sql.gz
#dump with columns
@pokka
pokka / .profile
Last active August 29, 2015 14:22
bundle exec short hand
function be () {
bundle exec $@
}
function ber () {
bundle exec rake $@
}
function bes () {
bundle exec rake spec $@
}
function bess () {
@pokka
pokka / i_rb
Created June 2, 2015 07:14
ruby-install
#!/bin/sh
_ver='2.1.6'
if [ -z "$V" ]; then
_ver='2.1.6'
else
_ver=$V
fi
ruby-install --rubies-dir /usr/local/rubies ruby $_ver
@pokka
pokka / Ruby STRFTIME conversion formats.rb
Last active September 7, 2015 03:06 — forked from akshaymohite/Ruby STRFTIME conversion formats.rb
Ruby script to print out strftime conversion format options and outputs
# Function to print strftime results
def print_strftime_formats(a,cur_date)
a.each do |format|
b = "%#{format}"
output = cur_date.strftime(b)
puts "t.strftime('#{b}'), => #{output}"
end
end
a = ('a'..'z').to_a
@pokka
pokka / fl.sh
Created March 17, 2016 03:08
finding-the-largest-files-directories
find . -type d -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
find . -type f -print0 | xargs -0 du | sort -n | tail -10 | cut -f2 | xargs -I{} du -sh {}
@pokka
pokka / execute_statements.rb
Last active April 12, 2016 05:10
run multiple statments in rails migrate
sql = File.read(sql_file)
statements = sql.split(/;$/)
statements.pop if statements.last.blank?
ActiveRecord::Base.transaction do
statements.uniq.each { |statement| execute(statement.gsub(/\n/, '')) }
end
@pokka
pokka / model_cache_key.rb
Created April 12, 2016 05:13
ActiveRecord cache key
module ActiveRecord
class Base
def self.cache_key
Digest::MD5.hexdigest "#{scoped.maximum(:updated_at).try(:to_i)}-#{scoped.count}"
end
end
end
@pokka
pokka / rails_skip_validate_callback.rb
Created April 21, 2016 08:58
Rails skip validates and callbacks, temporary
module ActiveRecord::Persistence::ClassMethods
def create!(attributes = nil, &block)
if attributes.is_a?(Array)
attributes.collect { |attr| create!(attr, &block) }
else
object = new(attributes, &block)
[:save,:create].each { |cb| object.class.reset_callbacks cb }
object.save(validate: false)
object