Skip to content

Instantly share code, notes, and snippets.

View padi's full-sized avatar

Marc Ignacio padi

View GitHub Profile
@nunommc
nunommc / application_controller.rb
Last active September 9, 2020 02:19
Redirect to page 404 when a Model.find(params[:id]) raises ActiveRecord::RecordNotFound
# app/controllers/application_controller.rb
class ApplicationController < ActionController::Base
# Prevent CSRF attacks by raising an exception.
# For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception
add_flash_types :success, :error
# See:
# https://stackoverflow.com/questions/2385799/how-to-redirect-to-a-404-in-rails
@nruth
nruth / pay_stripe_helper.rb
Last active March 7, 2023 00:21
capybara selenium webdriver stripe.js checkout test helper
# -*- encoding : utf-8 -*-
module PayStripeHelpers
# must be used with driver: :selenium (or :sauce?)
def pay_stripe
sleep(0.7) # wait for the js to create the popup in response to pressing the button
within_frame 'stripe_checkout_app' do # must be selenium
# fill_in 'card_number', with: '4242424242424242' no longer works
4.times {page.driver.browser.find_element(:id, 'card_number').send_keys('4242')}
# fill_in 'cc-exp', with: '5/2018' no longer works
@brysgo
brysgo / post_checkout_migrations.sh
Last active October 5, 2019 11:13 — forked from skyriverbend/rails_switch_branch.py
Post checkout hook for managing rails migrations and bundle install
CHECKING_OUT_BRANCH=$3
OLD_BRANCH=$1
NEW_BRANCH=$2
if [ $CHECKING_OUT_BRANCH -eq 1 ]
then
FILES_CHANGED=`git diff $OLD_BRANCH $NEW_BRANCH --name-status`
MIGRATIONS_REMOVED=`echo "$FILES_CHANGED" | egrep 'D\tdb/migrate/([0-9]+)' | sort -r`
MIGRATIONS_ADDED=`echo "$FILES_CHANGED" | egrep 'A\tdb/migrate/([0-9]+)'`
@andyjbas
andyjbas / gist:9962218
Last active June 23, 2020 13:33
Disable CSS Animations in Poltergeist & Phantomjs. Phantomjs does not like to wait for animations, and you can run in to nasty test flickers because of it. This pattern will disable animations in test env, and not touch any app code.
# env.rb or spec_helper.rb

Capybara.register_driver :poltergeist do |app|
  opts = {
    extensions: ["#{Rails.root}/features/support/phantomjs/disable_animations.js"] # or wherever
  }

  Capybara::Poltergeist::Driver.new(app, opts)
end
@wbroek
wbroek / genymotionwithplay.txt
Last active February 12, 2024 03:22
Genymotion with Google Play Services for ARM
NOTE: Easier way is the X86 way, described on https://www.genymotion.com/help/desktop/faq/#google-play-services
Download the following ZIPs:
ARM Translation Installer v1.1 (http://www.mirrorcreator.com/files/0ZIO8PME/Genymotion-ARM-Translation_v1.1.zip_links)
Download the correct GApps for your Android version:
Google Apps for Android 6.0 (https://www.androidfilehost.com/?fid=24052804347835438 - benzo-gapps-M-20151011-signed-chroma-r3.zip)
Google Apps for Android 5.1 (https://www.androidfilehost.com/?fid=96042739161891406 - gapps-L-4-21-15.zip)
Google Apps for Android 5.0 (https://www.androidfilehost.com/?fid=95784891001614559 - gapps-lp-20141109-signed.zip)
@keithtom
keithtom / no_animations.rb
Last active September 22, 2019 06:49
Rack Middleware to disable Disable CSS3/jQuery Animations for Capybara
# Copyright (C) [2014] by Keith Tom <keith dot tom at gmail>
# Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted.
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE
module Rack
# disable CSS3 and jQuery animations in test mode for speed, consistency and avoiding timing issues.
# Usage for Rails:
# in config/environments/test.rb
# config.middleware.use Rack::NoAnimations
class NoAnimations
@lelandbatey
lelandbatey / whiteboardCleaner.md
Last active April 25, 2024 02:01
Whiteboard Picture Cleaner - Shell one-liner/script to clean up and beautify photos of whiteboards!

Description

This simple script will take a picture of a whiteboard and use parts of the ImageMagick library with sane defaults to clean it up tremendously.

The script is here:

#!/bin/bash
convert "$1" -morphology Convolve DoG:15,100,0 -negate -normalize -blur 0x1 -channel RBG -level 60%,91%,0.1 "$2"

Results

@anytizer
anytizer / css-debug.css
Created December 25, 2013 08:31
CSS Debugging by borders coloring of the tags
http://yysource.com/2011/03/debugging-with-css-outline-all-elements/
* { outline: 2px dotted red }
* * { outline: 2px dotted green }
* * * { outline: 2px dotted orange }
* * * * { outline: 2px dotted blue }
* * * * * { outline: 1px solid red }
* * * * * * { outline: 1px solid green }
* * * * * * * { outline: 1px solid orange }
* * * * * * * * { outline: 1px solid blue }
@rstacruz
rstacruz / ansible.md
Last active April 8, 2024 23:36
Getting started with Ansible
@danfinlay
danfinlay / How to download streaming video.md
Last active March 23, 2024 03:32
How to download a streaming video with Google Chrome

How to download streaming video

Streaming just means a download that they don't want you to keep. But Chrome's developer tools make it easy to access what's really going on under the hood.

Open Developer Tools

From the page where you want to download some things, go into your chrome menu to open the developer tools. You can either:

1.  (On a mac): Command-option-J
2. (On a PC): Control-alt-J