Skip to content

Instantly share code, notes, and snippets.

Avatar

Lucas Caton lucascaton

View GitHub Profile
View grid.rb
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 } }
@lucascaton
lucascaton / modern.rb
Last active Aug 29, 2015
Swift and Ruby comparison
View modern.rb
cities = ["London", "San Francisco", "Tokyo", "Barcelona", "Sydney"]
sorted_cities = cities.sort
if sorted_cities.include?("London")
puts "London is city number #{sorted_cities.index('London')} in the list"
}
View fernando.sh
#! /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 Jul 25, 2014
PostgreSQL database dump generator
View backup.sh
#! /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 Aug 29, 2015
Capistrano v3 configuration example
View Capfile
# ...
# 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 Aug 29, 2015
Vision6 (http://vision6.com.au/) API integration (Ruby)
View vision6_api.rb
# 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]
})))
View gist:f18d4dc426dd9da04439
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]
View print_line.rb
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)
View 2014_12_13_14_59_54.csv
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.
View rdoc2md.rb
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