Skip to content

Instantly share code, notes, and snippets.

View lucascaton's full-sized avatar

Lucas Caton lucascaton

View GitHub Profile
@lucascaton
lucascaton / Gemfile
Created December 13, 2014 05:48
Car Sales checker (Ruby script)
source 'https://rubygems.org'
gem 'mechanize'
gem 'pry'
@lucascaton
lucascaton / Rails' time zones
Created December 3, 2014 05:18
$ rake time:zones:all
* UTC -11:00 *
American Samoa
International Date Line West
Midway Island
Samoa
* UTC -10:00 *
Hawaii
* UTC -09:00 *
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)
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]
@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]
})))
@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 / 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>"
#! /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 / modern.rb
Last active January 26, 2023 07:57
Swift and Ruby comparison
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"
}
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 } }