This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Array | |
def quicksort(min=0, max=length-1) | |
if min < max | |
mid = partition(min, max) | |
quicksort(min, mid - 1) | |
quicksort(mid + 1, max) | |
end | |
self | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def fib n | |
a, b = 0, 1 | |
n.times do | |
a, b = b, a + b | |
end | |
a | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Activate the gem you are reporting the issue against. | |
gem 'activerecord', '4.2.1' | |
require 'active_record' | |
require 'minitest/autorun' | |
require 'logger' | |
# Ensure backward compatibility with Minitest 4 | |
Minitest::Test = MiniTest::Unit::TestCase unless defined?(Minitest::Test) | |
# This connection will do for database-independent bug reports. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def solution(a) | |
@top_gain = 0 | |
a.each_with_index do |price, day| | |
if day == 0 | |
@bottom = price | |
@top = price | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/local/bin/bootup_ruby | |
# this is /my/daemon/file | |
require 'rubygems' | |
require 'daemons' | |
Daemons.run('main.rb') | |
#main.rb is the real script |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pass message | |
log() { | |
now=$(date "+%d.%m.%Y %H:%M:%S") | |
echo "[$now] $1" | |
} | |
# pass command description | |
log_status() { | |
exitval=$? | |
if [ $exitval -eq 0 ]; then |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Use Gists to store code you would like to remember later on | |
console.log(window); // log the "window" object to the console |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace :workers do | |
namespace :clockwork do | |
desc "Stop clockwork" | |
task :stop do | |
on roles(:app) do | |
within release_path do | |
with rails_env: fetch(:rails_env) do | |
execute :bundle, :exec, :clockworkd, "-c lib/clockwork.rb --pid-dir=#{cw_pid_dir} --log-dir=#{cw_log_dir} stop" | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Examples: | |
// no-margin-bottom, no-padding-left, margin-top-5, padding-left-20, etc | |
$directions: ('top' 'bottom' 'left' 'right'); | |
$properties: ('margin' 'padding'); | |
@each $direction in $directions { | |
@each $property in $properties { | |
.no-#{$property}-#{$direction} { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def self.from_omniauth(auth, opts = {}) | |
where('(provider = :provider AND uid = :uid) OR email = :email', | |
provider: auth.provider, | |
uid: auth.uid, | |
email: auth.info.email).first_or_initialize.tap do |user| | |
user.provider = auth.provider | |
user.uid = auth.uid | |
user.oauth_token = auth.credentials.token |
OlderNewer