Skip to content

Instantly share code, notes, and snippets.

View mariozig's full-sized avatar

Mario Zigliotto mariozig

  • San Mateo, CA
View GitHub Profile
var1, var2 = [1, 2] # var1 = 1; var2 = 2
var1, var2 = 1, 2 # var1 = 1; var2 = 2
var1, var2 = 1 # var1 = 1; var2 = nil
x = method_that_returned_nil() #=> nil
x ||= "default" #=> "default" : value of x is nil, so it will be replaced with "default"
x ||= "other" #=> "default" : value of x is "default" so it will stay "default" and NOT be set to "other"
#Model
@user.should have(1).error_on(:username) # Checks whether there is an error in username
@user.errors[:username].should include("can't be blank") # check for the error message
@user.errors[:email].should include("is invalid") # check for the error format message
#Rendering
response.should render_template(:index)
#Redirecting
response.should redirect_to(movies_path)
# Do not refactor, it is a bad practice. YOLO
# Not understanding why or how something works is always good. YOLO
# Do not ever test your code yourself, just ask. YOLO
# No one is going to read your code, at any point don't comment. YOLO
# Why do it the easy way when you can reinvent the wheel? Future-proofing is for pussies. YOLO
devise = yes?("Devise? ")
cancan = yes?("Cancan? ")
omniauth = yes?("Omniauth? ")
foundation = yes?("Foundation? ")
bootstrap = foundation ? false : yes?("Bootstrap? ")
ember = yes?("Ember? ")
handlebars = ember ? false : yes?("Handlebars? ")
underscore = yes?("Underscore? ")
staticpages = yes?("Static Pages Controller with home page? ")
github = yes?("GitHub create and push? ")
@mariozig
mariozig / #10945
Last active December 23, 2015 06:29
Add additional assert that more clearly exposes the fact that ArtistsTrack's artistic_role_id is being lost
# Activate the gem you are reporting the issue against.
gem 'activerecord', '4.0.0'
require 'active_record'
require 'minitest/autorun'
require 'logger'
# This connection will do for database-independent bug reports.
# ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'shiz.db')
ActiveRecord::Base.logger = Logger.new(STDOUT)
#!/bin/sh
git filter-branch --env-filter '
OLD_EMAIL="your-old-email@example.com"
CORRECT_NAME="Your Correct Name"
CORRECT_EMAIL="your-correct-email@example.com"
if [ "$GIT_COMMITTER_EMAIL" = "$OLD_EMAIL" ]
then
@mariozig
mariozig / migrate_repo.sh
Last active June 1, 2026 16:33
Migrate repo from GitLab to GitHub Full blog post @ http://ruby.zigzo.com/2015/03/23/moving-from-gitlab-to-github/
# Assume we are in your home directory
cd ~/
# Clone the repo from GitLab using the `--mirror` option
$ git clone --mirror git@your-gitlab-site.com:mario/my-repo.git
# Change into newly created repo directory
$ cd ~/my-repo.git
# Push to GitHub using the `--mirror` option. The `--no-verify` option skips any hooks.
@mariozig
mariozig / developer_machines.sh
Last active September 17, 2020 21:46
Changes to remote for developers. Full blog post @ http://ruby.zigzo.com/2015/03/23/moving-from-gitlab-to-github/
# Go to local repo
cd /path/on/your/machine/my-repo
# Just update the remote
git remote set-url origin git@github.com:mario/my-repo.git

#Heroku, Ruby on Rails and PhantomJS

In this post, I’m going to show you how to modify an existing Ruby on Rails app running on Heroku’s Cedar stack to use PhantomJS for screen scraping. If you’ve never heard of PhantomJS, it’s a command-line WebKit-based browser (that supports JavaScript, cookies, etc.).

Let’s get started. This is a high-level overview of the required steps:

  • Modify your app to use multiple Heroku buildpacks.
  • Extend your app to use both the Ruby as well as the PhantomJS buildpacks.
  • Confirm that everything worked.