Skip to content

Instantly share code, notes, and snippets.

View gabrielbidula's full-sized avatar

Gabriel Borges Oliveira gabrielbidula

View GitHub Profile
@gabrielbidula
gabrielbidula / Setup.md
Last active August 29, 2015 14:25
Simple Setup of Rails Development Environment using Docker @ OS X

Setting-up

This does not covers installation of docker and compose

Also, presuming myapp is already created

For this example RoR app Will have

  • Web server
  • Postgres DB
# Path to your oh-my-zsh installation.
export ZSH=$HOME/.oh-my-zsh
# Set name of the theme to load.
# Look in ~/.oh-my-zsh/themes/
# Optionally, if you set this to "random", it'll load a random theme each
# time that oh-my-zsh is loaded.
ZSH_THEME="psyrendust"
ZSH_CUSTOM="$HOME/.oh-my-zsh-psyrendust"
def rename_photos
images.each do |image|
extension = File.extname(image.attachment_file_name).downcase
old_file_name = image.attachment_file_name
new_file_name = slug+"-"+"#{image.position}"+"#{extension}"
image.attachment_file_name = new_file_name
(image.attachment.styles.keys+[:original]).each do |style|
FileUtils.move(File.join(File.dirname(image.attachment.path(style)), old_file_name), image.attachment.path(style))
end
image.save!
@gabrielbidula
gabrielbidula / byebug.rb
Created July 16, 2016 17:33
remote debug with pow
module Byebug
class << self
def start_remote_debugging
require "byebug/core"
require "byebug"
port = begin
server = TCPServer.new(nil, 0)
server.addr[1]
ensure
server.close if server
@gabrielbidula
gabrielbidula / nice_flatten.rb
Created March 1, 2017 10:03
flatten an array of arbitrarily nested arrays of integers into a flat array of integers
class NiceFlatten
def flatten
to_s
.gsub(/[\[|\]]/, '')
.split(', ')
.map(&:to_i)
end
end
@gabrielbidula
gabrielbidula / nice_flatten_test.rb
Created March 1, 2017 10:05
flatten an array of arbitrarily nested arrays of integers into a flat array of integers - test
require 'minitest/autorun'
require_relative 'nice_flatten'
class NiceFlattenTest < Minitest::Test
def test_flattens_an_array_of_nested_arrays_into_a_flat_array
flattened_array = [[1, 2, [3]], 4].flatten
assert_equal [1, 2, 3, 4], flattened_array
end
def test_flattens_another_array_of_nested_arrays_into_a_flat_array
@gabrielbidula
gabrielbidula / capture_and_restore_heroku_pg_dump
Last active November 22, 2017 17:22
capture and restore backup from heroku
#!/bin/bash
HEROKU_APP_NAME="XXX"
LOCAL_DATABASE="XXX"
heroku pg:backups capture DATABASE_URL --app $HEROKU_APP_NAME
curl -o production.dump `heroku pg:backups public-url --app $HEROKU_APP_NAME`
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $(whoami) -d $LOCAL_DATABASE production.dump
0xe295cFcd1666800726B4ed8ffF59F32e814b7bE9
%s/\(\w\)\(\w*\)/\U\1\L\2/g #capitalize words
@gabrielbidula
gabrielbidula / leads.sh
Created August 5, 2019 14:01
shellscript to run a cron in range of dates
#!/bin/bash
d=2019-04-01
while [ "$d" != 2019-08-04 ]; do
echo $d
php artisan export:adverts:fetch:leads --date="$d"
d=$(date -I -d "$d + 1 day")
done