Skip to content

Instantly share code, notes, and snippets.

View mariozig's full-sized avatar

Mario Zigliotto mariozig

  • Intuit
  • San Mateo, CA
View GitHub Profile
@mariozig
mariozig / bad_monkey.sh
Last active October 21, 2017 18:53
Bad idea to monkeypatch `.to_s` -- code for post: http://ruby.zigzo.com/2017/10/21/refinements-fancy-monkey/
irb(main):001:0> 1.class
=> Integer
irb(main):002:0> 1.to_s
=> "1"
irb(main):003:0> class Integer
irb(main):004:1> def to_s
irb(main):005:2> "two"
irb(main):006:2> end
irb(main):007:1> end
=> :to_s
@mariozig
mariozig / html_test.html
Created December 15, 2016 21:20 — forked from rwestergren/html_test.html
HTML Email Filter Test
<a onafterprint="console.log(244599)" onbeforeprint="console.log(309354)" onbeforeunload="console.log(879813)" onerror="console.log(949564)" onhashchange="console.log(575242)" onload="console.log(301053)" onmessage="console.log(976974)" onoffline="console.log(796090)" ononline="console.log(432638)" onpagehide="console.log(504345)" onpageshow="console.log(696619)" onpopstate="console.log(398418)" onresize="console.log(943097)" onstorage="console.log(882233)" onunload="console.log(929443)" onblur="console.log(932104)" onchange="console.log(102339)" oncontextmenu="console.log(761265)" onfocus="console.log(188946)" oninput="console.log(143653)" oninvalid="console.log(304208)" onreset="console.log(318472)" onsearch="console.log(778420)" onselect="console.log(942035)" onsubmit="console.log(603589)" onkeydown="console.log(650647)" onkeypress="console.log(579383)" onkeyup="console.log(821763)" onclick="console.log(284098)" ondblclick="console.log(477370)" ondrag="console.log(439095)" ondragend="console.log(546684)" o
#!/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 / #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)
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? ")
#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)
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"
var1, var2 = [1, 2] # var1 = 1; var2 = 2
var1, var2 = 1, 2 # var1 = 1; var2 = 2
var1, var2 = 1 # var1 = 1; var2 = nil
@mariozig
mariozig / factorial.rb
Last active December 11, 2015 01:09
Example for proving that Sublime Text 2 is running through RVM ruby and not the system default ruby. Goes with: http://ruby.zigzo.com/2013/01/11/sublime-text-2-and-rvm/
class Factorial
attr_reader :computed
def initialize(number)
@computed = solve(number)
end
def solve(number)
number > 1 ? number * solve(number-1) : 1
end
@mariozig
mariozig / Ruby sublime-build.json
Last active December 11, 2015 01:09
Sublime Text 2 and RVM together... Full post here: http://ruby.zigzo.com/2013/01/11/sublime-text-2-and-rvm/
{
"cmd": [ "/Users/YOUR_USER_NAME/.rvm/bin/rvm-auto-ruby", "$file" ],
"file_regex": "^(...*?):([0-9]*):?([0-9]*)",
"selector": "source.ruby"
}