Skip to content

Instantly share code, notes, and snippets.

View mariusbutuc's full-sized avatar
🌏

Marius Butuc mariusbutuc

🌏
  • Toronto, ON
  • 00:34 (UTC -04:00)
View GitHub Profile
guard :minitest do
# with Minitest::Unit
watch(%r{^test/(.*)\/?test_(.*)\.rb$})
watch(%r{^lib/(.*/)?([^/]+)\.rb$}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
watch(%r{^test/test_helper\.rb$}) { 'test' }
# with Minitest::Spec
# watch(%r{^spec/(.*)_spec\.rb$})
# watch(%r{^lib/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
# watch(%r{^spec/spec_helper\.rb$}) { 'spec' }
@mariusbutuc
mariusbutuc / rails_new_w_pg.log
Created November 14, 2015 15:37
Rails 4.2.2 rails new output Raw
$ rails _4.2.2_ new <app_name> --database=postgresql
create
create README.rdoc
create Rakefile
create config.ru
create .gitignore
create Gemfile
create app
create app/assets/javascripts/application.js
create app/assets/stylesheets/application.css
require 'google/api_client'
require 'google/api_client/auth/file_storage'
require 'google/api_client/auth/installed_app'
module Google
class Drive
# https://github.com/google/google-api-ruby-client-samples/blob/master/drive/drive.rb
API_VERSION = 'v2'.freeze
CREDENTIAL_STORE_FILE = Rails.root.join('lib/google/credential_store.json').freeze
@mariusbutuc
mariusbutuc / test_with_cassette.rb
Last active October 7, 2015 19:18 — forked from jrochkind/example.rb
MiniTest and VCR: one cassette per test?
module TestWithCassette
# cribbed from Rails and modified for VCR
# https://github.com/rails/rails/blob/b451de0d6de4df6bc66b274cec73b919f823d5ae/activesupport/lib/active_support/testing/declarative.rb#L9
def test_with_cassette(name, vcr_options = {}, &block)
auto_cassette_name = name.gsub(/\s+/, '_')
test_name = "test_#{auto_cassette_name}".to_sym
if block_given?
group = vcr_options.delete(:group)
group_prefix = "#{group}/" if group.present?
CSV_FILENAME = 'config/items.csv'.freeze
YML_FILENAME = 'config/items.yml'.freeze
File.open(YML_FILENAME, 'w') do |f|
f.puts(CSV.table(CSV_FILENAME).map(&:to_hash).to_yaml)
end
YAML.load(File.new(YML_FILENAME))
#!/usr/bin/env ruby
require 'csv'
require 'json'
if ARGV.size != 2
puts 'Usage: csv_to_json input_file.csv output_file.json'
puts 'This script uses the first line of the csv file as the keys for the JSON properties of the objects'
exit(1)
end
class CorreiosRequest
# ...
def build_params(package)
@params.merge(package.params)
end
def hash_query_string(params)
{
'nCdEmpresa' => params[:company_id],
'sDsSenha' => params[:password],
@mariusbutuc
mariusbutuc / simple_form_bootstrap.sh
Created April 3, 2015 16:49
Install simple_form with Bootstrap support (SLIM version)
clubhouse marius$ rails generate simple_form:install --bootstrap
create config/initializers/simple_form.rb
create config/initializers/simple_form_bootstrap.rb
exist config/locales
create config/locales/simple_form.en.yml
create lib/templates/slim/scaffold/_form.html.slim
===============================================================================
Be sure to have a copy of the Bootstrap stylesheet available on your
application, you can get it on http://getbootstrap.com/.
@mariusbutuc
mariusbutuc / pg_upgrade.sh
Last active August 29, 2015 14:17 — forked from joho/gist:3735740
PostgreSQL 9.3 to 9.4.1 upgrade steps
# Steps to install and run PostgreSQL 9.4.1 using Homebrew (Mac OS X)
# (if you aren't using version 9.3, change line #9 with the correct version)
launchctl unload -w ~/Library/LaunchAgents/homebrew.mxcl.postgresql.plist
mv /usr/local/var/postgres /usr/local/var/postgres93
brew update
brew upgrade postgresql
initdb /usr/local/var/postgres -E utf8
pg_upgrade -b /usr/local/Cellar/postgresql/9.3/bin -B /usr/local/Cellar/postgresql/9.4.1/bin -d /usr/local/var/postgres93 -D /usr/local/var/postgres
cp /usr/local/Cellar/postgresql/9.4.1/homebrew.mxcl.postgresql.plist ~/Library/LaunchAgents/
@mariusbutuc
mariusbutuc / git_rename_branch.sh
Last active August 29, 2015 14:17 — forked from stuart11n/gist:9628955
Rename git branch—both locally and upstream.
git branch -m old_branch new_branch # Rename branch locally
git push origin :old_branch # Delete the old branch
git push --set-upstream origin new_branch # Push the new branch, set local branch to track the new remote