Skip to content

Instantly share code, notes, and snippets.

View patbenatar's full-sized avatar

Nick Giancola patbenatar

View GitHub Profile
@patbenatar
patbenatar / pattern_matching_methods.rb
Created October 25, 2019 23:51
Experiment in using Ruby 2.7 case/in to implement pattern-matching methods
require 'active_support/concern'
require 'active_support/core_ext/class/attribute'
module PatternMatchingMethods
extend ActiveSupport::Concern
included do
class_attribute :defined_pattern_matching_methods, default: []
def send_match(name, input)

Setup Atom to use eslint, tslint, prettier, js-beautify, scss-lint, json-lint, etc

install some modules into project dev for when you call atom from commandline

npm install eslint-plugin-html eslint-config-prettier eslint-plugin-prettier tslint-config-prettier --dev

or

Keybase proof

I hereby claim:

  • I am patbenatar on github.
  • I am patbenatar (https://keybase.io/patbenatar) on keybase.
  • I have a public key ASAz6SE6D_Mr8wjdYIAQ-7oEays8_uSud-NRViQZO9rZSwo

To claim this, I am signing this object:

@patbenatar
patbenatar / hash.rb
Created October 19, 2017 23:21
Ruby Proof of Work example
require 'optparse'
require_relative './proof_of_work'
options = {}
OptionParser.new do |opts|
opts.on('--input INPUT', 'Input data') { |v| options[:input] = v }
opts.on('--difficulty DIFFICULTY', 'Difficulty (leading zeroes)') { |v| options[:difficulty] = v }
end.parse!
start_time = Time.now
@patbenatar
patbenatar / gist:8c08f89827dca18bd43f8f762af70d03
Created June 20, 2017 21:58
Percy visual diff scroll fx
def visual_diff_scroll_fx(page, id:, name:)
page.evaluate_script('window.scrollTo(0,0)')
scroll_top = page.evaluate_script(
"document.getElementById('#{id}').getBoundingClientRect().top"
)
page.evaluate_script("window.scrollTo(0, #{scroll_top})")
sleep 0.1
Percy::Capybara.snapshot(page, name: name)
@patbenatar
patbenatar / sheet_column_identifiers.rb
Created August 31, 2016 00:20
Just in case you ever find yourself needing to generate spreadsheet column identifiers from an arbitrary index
class SheetColumnIdentifiers
def initialize
@alphabet = ('A'..'Z').to_a
end
def [](index)
return alphabet[index] if index < alphabet.length
pad_index = (index / alphabet.length) - 1
self[pad_index] + self[index % alphabet.length]
@patbenatar
patbenatar / webpack_rails_heroku_notes.md
Last active February 14, 2016 19:41
webpack-rails + Heroku

Reference implementation on cardsorter: https://github.com/philosophie/cardsorter/commit/46285b42383ecfd77706fbedaf6654bdd14ebe99

@patbenatar
patbenatar / lock_gemfile.rb
Created June 7, 2015 17:01
Write lock versions back to Gemfile
gemfile = File.read('Gemfile')
locks = Bundler.locked_gems
specs = locks.specs
# Naively convert to single quotes
gemfile.gsub! '"', "'"
specs.each do |gem|
# Don't try to set versions on git or github sources
@patbenatar
patbenatar / application_controller.rb
Created November 1, 2013 18:45
Some code to help with running a Rails app within the Facebook app iframe (not page tab)
class ApplicationController < ActionController::Base
before_filter :sign_in_with_facebook_signed_request
protect_from_forgery
private
def sign_in_with_facebook_signed_request
return true unless params[:signed_request]
@patbenatar
patbenatar / cookie_helper.rb
Created October 16, 2013 17:33
Helper for setting cookies with Capybara for both Selenium and Webkit