Skip to content

Instantly share code, notes, and snippets.

View jacek213's full-sized avatar

Jacek Grzybowski jacek213

View GitHub Profile
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
@jacek213
jacek213 / fib.rb
Created February 11, 2014 12:33
nth fibbonachi number
def fib n
a, b = 0, 1
n.times do
a, b = b, a + b
end
a
end
@jacek213
jacek213 / test_acceptance_validation.rb
Created May 19, 2015 11:51
Test the acceptance validation for Rails 4.2.1
# 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.
def solution(a)
@top_gain = 0
a.each_with_index do |price, day|
if day == 0
@bottom = price
@top = price
end
@jacek213
jacek213 / file.rb
Created February 16, 2016 08:38 — forked from zloydadka/file.rb
Write a simple init.d ruby startup script
#!/usr/local/bin/bootup_ruby
# this is /my/daemon/file
require 'rubygems'
require 'daemons'
Daemons.run('main.rb')
#main.rb is the real script
# 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
@jacek213
jacek213 / 0_reuse_code.js
Created June 28, 2016 14:28
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@jacek213
jacek213 / clockwork.cap
Created August 6, 2016 15:29 — forked from vjfrancois/clockwork.cap
Clockwork and delayed_job tasks file for capistrano 3
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
// 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} {
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