Skip to content

Instantly share code, notes, and snippets.

View bdewater's full-sized avatar

Bart de Water bdewater

View GitHub Profile
  1. Start Chrome with a flag from the terminal by copy-pasting the following line and hitting enter /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --show-component-extension-options
  2. Open [chrome://extensions/] in the browser
  3. Find CryptoTokenExtension, and click its 'background page' link
  4. In the JS console that opens, type: HTTP_ORIGINS_ALLOWED = true; and hit enter
  5. Keep the console open while testing with your U2F device
@bdewater
bdewater / screen_ppi.rb
Last active November 21, 2015 11:12
Calculate screen pixel density
require 'bigdecimal'
# https://en.wikipedia.org/wiki/Pixel_density#Calculation_of_monitor_PPI
def calculate_ppi(height_pixels, width_pixels, diagonal_inches)
diagonal_pixels = Math.sqrt((height_pixels**2) + (width_pixels**2))
ppi = diagonal_pixels / diagonal_inches
end
def calculate_ppi_rounded(height_pixels, width_pixels, diagonal_inches)
ppi = calculate_ppi(height_pixels, width_pixels, diagonal_inches)
@bdewater
bdewater / application.rb
Created November 27, 2015 15:54
Conditionally call Rack middleware (e.g. ContentLength) depending on path
# config/application.rb
config.middleware.use 'ConditionalContentLength', ['/foo', '/bar']
@bdewater
bdewater / currency.rb
Last active July 10, 2018 23:13
Translate from CLDR
# frozen_string_literal: true
#
# Usage:
# $ LANGUAGE=de ruby currency.rb
require 'open-uri'
require 'nokogiri'
require 'active_support/time_with_zone'
CLDR_URI = "http://unicode.org/repos/cldr/trunk/common/main/#{ENV['LANGUAGE']}.xml"
CURRENCIES = %w(USD AED AFN ALL AMD ANG AOA ARS AUD AWG AZN BAM BBD BDT BGN BIF BMD BND BOB BRL BSD BWP BZD CAD CDF CHF CLP CNY COP CRC CVE CZK DJF DKK DOP DZD EGP ETB EUR FJD FKP GBP GEL GIP GMD GNF GTQ GYD HKD HNL HRK HTG HUF IDR ILS INR ISK JMD JPY KES KGS KHR KMF KRW KYD KZT LAK LBP LKR LRD LSL MAD MDL MGA MKD MMK MNT MOP MRO MUR MVR MWK MXN MYR MZN NAD NGN NIO NOK NPR NZD PAB PEN PGK PHP PKR PLN PYG QAR RON RSD RUB RWF SAR SBD SCR SEK SGD SHP SLL SOS SRD STD SVC SZL THB TJS TOP TRY TTD TWD TZS UAH UGX UYU UZS VND VUV WST XAF XCD XOF XPF YER ZAR ZMW)
@bdewater
bdewater / example.rb
Last active May 30, 2019 17:23
Migrating from U2F to WebAuthn
# Migrating from https://github.com/castle/ruby-u2f to https://github.com/cedarcode/webauthn-ruby
# Also see FIDO CTAP2 specs on backwards compatibility with CTAP1/U2F authenticators:
# https://fidoalliance.org/specs/fido-v2.0-rd-20180702/fido-client-to-authenticator-protocol-v2.0-rd-20180702.html#u2f-authenticatorMakeCredential-interoperability
# Chrome team encouraging to migrate: https://groups.google.com/a/chromium.org/forum/#!msg/security-dev/BGWA1d7a6rI/W2avestmBAAJ
require 'u2f'
require 'webauthn'
require 'webauthn/fake_client'
require 'webauthn/attestation_statement/fido_u2f'
@bdewater
bdewater / time_vs_datetime.rb
Created June 8, 2020 16:07
Ruby Time vs DateTime
# From https://gist.github.com/pixeltrix/e2298822dd89d854444b / https://ruby-doc.org/stdlib-2.3.0/libdoc/date/rdoc/DateTime.html
# "Almost certainly you'll want to use Time since your app is probably dealing with current dates and times."
# Here's a practical example
require "time"
# The line below is probably set different for your system, or not at all
# On macOS I can see this with `sudo systemsetup -gettimezone`
# I'm in Montreal so for the examples to work you need to pretend to be as well
ENV["TZ"] = "America/Toronto"
@bdewater
bdewater / steppable_job.rb
Last active October 26, 2024 02:12
Job with resumable steps
# frozen_string_literal: true
class SubmitWidgetJob < ApplicationJob
include JobIteration::Iteration
queue_as :default
attr_accessor :funding_token, :confirmation_number, :profile_id
STEPS = [