Skip to content

Instantly share code, notes, and snippets.

View lucascaton's full-sized avatar

Lucas Caton lucascaton

View GitHub Profile
if ARGV.count > 2
puts 'ERROR - Wrong arguments'
puts 'Usage: `ruby grid.rb <size> <grid_padding>`'
exit
end
size = (ARGV[0] || 10).to_i
grid_padding = (ARGV[1] || 2).to_i
grid = Array.new(size) { Array.new(size) { ['o', ' '].sample } }
#! /bin/bash
mkdir ~/Desktop/nova_pasta
touch ~/Desktop/nova_pasta/primeiro_arquivo.txt
cd ~/Desktop/nova_pasta/
ls -lh
rm primeiro_arquivo.txt
cd ..
rm -rf nova_pasta
@lucascaton
lucascaton / backup.sh
Created July 25, 2014 06:40
PostgreSQL database dump generator
#! /bin/bash
# ┌──────────────────────────────────────┐
# │ PostgreSQL database dump generator |
# | Created by Lucas Caton on 2010-08-14 |
# | Updated by Lucas Caton on 2014-07-25 |
# └──────────────────────────────────────┘
usage() {
echo "usage: $0 <project_name> <db_name>"
@lucascaton
lucascaton / Capfile
Last active August 29, 2015 14:04
Capistrano v3 configuration example
# ...
# Loads custom tasks from `lib/capistrano/tasks' if you have any defined.
Dir.glob('lib/capistrano/tasks/*.rake').each { |r| import r }
@lucascaton
lucascaton / vision6_api.rb
Last active August 29, 2015 14:05
Vision6 (http://vision6.com.au/) API integration (Ruby)
# Docs: http://developers.vision6.com.au/
require 'httparty'
url = 'http://www.vision6.com.au/api/jsonrpcserver.php?version=3.0'
api_key = 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx'
JSON.parse(HTTParty.post(url, headers: { 'Content-Type' => 'application/json' }, body: JSON.dump({
'method' => 'getSessionInfo', 'params' => [api_key]
})))
a = [1, 2, 3, 4]
a.each_with_index.map do |element, index|
a.dup.delete_if { |e| e == a[index] }.inject(:*)
end
#=> [24, 12, 8, 6]
def print_line(n, growning:)
sleep 0.02
puts '>>' * n
if growning
n += 1
print_line(n, growning: n < 30)
else
n -= 1
print_line(n, growning: n <= 0)
badge year color fuel price title description image kilometres link
Elite 2010 White Diesel 12990 2010 Hyundai ix35 The 2010 Hyundai ix35 Elite Sports Automatic All Wheel Drive in White http://liveimages.carsales.com.au/carsales/car/dealer/180316017.jpg?aspect=FitWithinNoPad&height=750&width=560 137891 http://www.carsales.com.au/dealer/details/Hyundai-ix35-2010/AGC-AD-16650996/?Cr=0&sdmvc=1
Elite 2010 Sleek Silver Petrol - Unleaded ULP 15900 2010 Hyundai ix35 The 2010 Hyundai ix35 Elite Sports Automatic All Wheel Drive in Sleek Silver http://liveimages.carsales.com.au/carsales/car/private/cp5660190667547643765.jpg?aspect=FitWithinNoPad&height=750&width=560 141500 http://www.carsales.com.au/private/details/Hyundai-ix35-2010/SSE-AD-3033756/?Cr=1&sdmvc=1
Active 2011 Black Petrol - Unleaded ULP 16350 2011 Hyundai ix35 The 2011 Hyundai ix35 Active MY11 Sports Automatic in Black http://liveimages.carsales.com.au/carsales/car/dealer/182253036.jpg?aspect=FitWithinNoPad&height=750&width=560 103540 http://www.carsales.
require 'rdoc'
converter = RDoc::Markup::ToMarkdown.new
rdoc = File.read(ARGV[0] || 'README.rdoc')
puts converter.convert(rdoc)
# ruby rdoc2md.rb > README.md
# ruby rdoc2md.rb ABC.rdoc > abc.md
Rails::Generator::Commands::Create.class_eval do
def template(relative_source, relative_destination, template_options = {})
file(relative_source, relative_destination, template_options) do |file|
# Evaluate any assignments in a temporary, throwaway binding.
vars = template_options[:assigns] || {}
b = template_options[:binding] || binding
# this no longer works, eval throws "undefined local variable or method `vars'"
# vars.each { |k, v| eval "#{k} = vars[:#{k}] || vars['#{k}']", b }
vars.each { |k, v| b.local_variable_set(:"#{k}", v) }