Skip to content

Instantly share code, notes, and snippets.

View vvalgis's full-sized avatar

Vladimir Valgis vvalgis

  • Barcelona, Spain
View GitHub Profile
@vvalgis
vvalgis / install_gem_list_nodoc.sh
Last active December 20, 2015 03:09
Gem list for install
gem sources -a http://gems.github.com
gem install aaronh-chronic --version=0.3.9 --no-ri --no-rdoc
gem install actionmailer --version=3.2.3 --no-ri --no-rdoc
gem install actionmailer --version=3.2.2 --no-ri --no-rdoc
gem install actionmailer --version=3.1.1 --no-ri --no-rdoc
gem install actionmailer --version=2.3.5 --no-ri --no-rdoc
gem install actionpack --version=3.2.3 --no-ri --no-rdoc
gem install actionpack --version=3.2.2 --no-ri --no-rdoc
gem install actionpack --version=3.1.1 --no-ri --no-rdoc
gem install actionpack --version=2.3.5 --no-ri --no-rdoc
@vvalgis
vvalgis / gist:4327550
Created December 18, 2012 12:25
month day ranges
dates = [10 ,11, 12].map {|y| (1..12).map {|m| [1, ( m == 2 ? ((y % 4) == 0 ? 29 : 28) : ((m % 2) == 0 ? (m < 8 ? 30 : 31) : (m < 8 ? 31 : 30))), m, y] } }
@vvalgis
vvalgis / gemit.rb
Created December 12, 2012 14:07 — forked from sshirokov/gemit.rb
gem_cmd = ENV["GEM_CMD"] || 'sudo gem'
STDIN.map { |l| l.strip }.each { |l|
gem, versions = l.split(' ', 2)
versions = versions.gsub(/[\(\)]/, '').split(', ')
versions.each { |version|
cmd = "#{gem_cmd} install #{gem} -v #{version}"
puts cmd if ENV["PRETEND"] or ENV["ECHO"]
system cmd unless ENV["PRETEND"]
@vvalgis
vvalgis / int_to_ip4_even_better.rb
Last active October 12, 2015 02:38
convert ip to integer
# Better version from
# http://basic70tech.wordpress.com/2007/04/13/32-bit-ip-address-to-dotted-notation-in-ruby/
[24, 16, 8, 0].map{|b| (1089052672 >> b) & 255}.join('.')
@vvalgis
vvalgis / Gemfile
Created September 9, 2012 13:11
Middleman with compass-twitter-bootstrap-plugin
gem 'compass-twitter-bootstrap-plugin', git: 'git://github.com/corroded/compass-twitter-bootstrap-plugin.git'
@vvalgis
vvalgis / gist:3444393
Created August 24, 2012 01:17
String mixin for console color output
<<COLORS
black='\033[0;30m'
BLACK='\033[1;30m'
red='\033[0;31m'
RED='\033[1;31m'
green='\033[0;32m'
GREEN='\033[1;32m'
yellow='\033[0;33m'
YELLOW='\033[1;33m'
blue='\033[0;34m'
@vvalgis
vvalgis / gems_install.rb
Created November 23, 2011 11:28 — forked from sshirokov/gemit.rb
Install gems from a gem list dump
#!/usr/bin/env ruby
#gem_cmd = ENV["GEM_CMD"] || 'sudo gem'
gem_cmd = 'gem'
STDIN.map { |l| l.strip }.each { |l|
gem, versions = l.split(' ', 2)
versions = versions.gsub(/[\(\)]/, '').split(', ')
versions.each { |version|
cmd = "#{gem_cmd} install #{gem} -v #{version} --no-ri --no-rdoc"
@vvalgis
vvalgis / gist:789593
Last active September 24, 2015 18:18
Credit card number validation
def ccn_valid?(number)
(number.to_s.split(//).inject([]){ |r,d| r << (r.count.even? ? (d.to_i * 2).to_s : d); r }.map{|d| d.split(//)}.flatten.inject(0){|sum,d| sum += d.to_i} % 10) == 0
end
puts ccn_valid?("4417123456789113")
@vvalgis
vvalgis / paperclip.rb
Created December 28, 2010 11:02
Delete "original" files extension for paperclip
# placed in config/initializers/paperclip.rb
module Paperclip
module InstanceMethods #:nodoc:
def save_attached_files
exceptions = [:scan]
each_attachment do |name, attachment|
if self.changed.include?("#{name}_updated_at")
logger.info("[paperclip] Saving attachments.")
attachment.send(:save)
unless exceptions.include?(name.to_sym)
@vvalgis
vvalgis / Capistrano tasks for starting unicorn.rb
Created May 7, 2010 08:13
Capistrano tasks for starting unicorn
set :rails_env, :production
set :unicorn_binary, "/usr/bin/unicorn"
set :unicorn_config, "#{current_path}/config/unicorn.rb"
set :unicorn_pid, "#{current_path}/tmp/pids/unicorn.pid"
namespace :deploy do
task :start, :roles => :app, :except => { :no_release => true } do
run "cd #{current_path} && #{try_sudo} #{unicorn_binary} -c #{unicorn_config} -E #{rails_env} -D"
end
task :stop, :roles => :app, :except => { :no_release => true } do