Skip to content

Instantly share code, notes, and snippets.

View leemour's full-sized avatar

Viacheslav Ptsarev leemour

View GitHub Profile
@leemour
leemour / until_gets_stop.rb
Created February 14, 2014 12:42
Loop until gets stop
Thread.new do
# Do this in a new thread so that the loop can run at the same time as gets (the latter waits until a newline is entered)
until gets.chomp == "stop"; end
# Exit the entire program (this only stops the current thread in IRB, I warn you)
exit
end
puts "Program started"
loop do
sleep 5
@leemour
leemour / Guardfile
Created February 19, 2014 14:33
RSpec exclude spec folders path
guard 'rspec', :spec_paths => ['spec/models', 'spec/workers', 'spec/observers'] do
# ...
end
HTML
=====
<script type='text/javascript'>
window.jQuery || document.write('<script src="js/jquery-1.7.1.js">\x3C/script>')
</script>
<script src='http://cdnjs.cloudflare.com/ajax/libs/modernizr/2.0.6/modernizr.min.js' type='text/javascript'></script>
<script type='text/javascript'>
window.Modernizr || document.write('<script src="js/modernizr-2.0.6.js">\x3C/script>')
</script>
#!/usr/bin/env bash
# Simple move this file into your Rails `script` folder. Also make sure you `chmod +x puma.sh`.
# Please modify the CONSTANT variables to fit your configurations.
# The script will start with config set by $PUMA_CONFIG_FILE by default
PUMA_CONFIG_FILE=config/puma.rb
PUMA_PID_FILE=tmp/pids/puma.pid
PUMA_SOCKET=tmp/sockets/puma.sock
@leemour
leemour / Rakefile
Created April 1, 2014 12:48 — forked from jeffreyiacono/Rakefile
rake task for precompiling assets using sprockets within a sinatra app + view helpers
require 'rubygems'
require 'bundler'
Bundler.require
require './application'
namespace :assets do
desc 'compile assets'
task :compile => [:compile_js, :compile_css] do
end
@leemour
leemour / Guardfile
Created April 27, 2014 10:00
Guardfile ignore rspec livereload
ignore([
%r{^bin/*},
%r{^config/*},
%r{^db/*},
# %r{^lib/*},
%r{^log/*},
%r{^public/*},
%r{^tmp/*}
])
@leemour
leemour / console.rb
Last active August 29, 2015 14:02 — forked from marcamillion/console.rb
Rails 4 cache_counter for has_and_belongs_to_many relationship
## I imagine this could be done in the migration, but it was giving me problems so I moved it to the model
## and just did it on the command line
> Tag.reset_questions_count
@leemour
leemour / rename.sh
Created September 10, 2014 14:06
Rename haml to slim files in all subidrectories
rename 's/\.[^.]*$/.slim/' app/views/devise/**/*
@leemour
leemour / generate.sh
Created April 14, 2015 13:33
Rails generate image polymorphic
rails generate model Image name:string imageable:references{polymorphic}
@leemour
leemour / kill_process.sh
Created April 22, 2015 09:03
Kill process Ubuntu by name
kill $(ps aux | grep 'puma' | awk '{print $2}')
# The ps gives you the list of all the processes.
# The grep filters that based on your search string, [p] is a trick to stop you picking up the actual grep process itself.
# The awk just gives you the second field of each line, which is the PID.
# The $(x) construct means to execute x then take its output and put it on the command line. The output of that ps pipeline inside # that construct above is the list of process IDs so you end up with a command like kill 1234 1122 7654