Skip to content

Instantly share code, notes, and snippets.

View jcypret's full-sized avatar

Justin Cypret jcypret

View GitHub Profile
@jcypret
jcypret / ruby.yml
Created October 29, 2019 03:06
Ruby CI (RSpec + CodeClimate) using GitHub Actions
name: build
on: [push, pull_request]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
@jcypret
jcypret / deep_permit.rb
Created October 4, 2019 21:43
Recursively marks ActionController::Parameters as permitted
def deep_permit(args)
case args
when ActionController::Parameters
args.to_unsafe_hash.deep_symbolize_keys
when Hash
args.symbolize_keys.transform_values(&method(:deep_permit))
when Array
args.map(&method(:deep_permit))
else
args
@jcypret
jcypret / Gemfile
Last active October 7, 2021 13:59
Phone normalization in Rails
gem "phonelib"
@jcypret
jcypret / string_enum.rb
Last active July 9, 2019 03:01
Store ActiveRecord enums in database as strings rather than integers
# Store enums in database as strings rather than integers.
#
# Wraps `ActiveRecord::Enum`; just use `string_enum` instead of `enum`.
# https://api.rubyonrails.org/v4.2.11.1/classes/ActiveRecord/Enum.html
#
# Usage:
# extend StringEnum
# string_enum status: [:active, :archived]
#
module StringEnum
@jcypret
jcypret / objectToQueryString.js
Created June 28, 2018 17:57
Convert a plain JS object to an encoded query string
export function objectToQueryString(obj) {
return Object.keys(obj)
.map(k => encodeURIComponent(k) + "=" + encodeURIComponent(obj[k] || ""))
.join("&");
}
@jcypret
jcypret / application_helper.rb
Last active November 6, 2016 00:31
Rails helper method for building nested layouts. https://justincypret.com/nested-layouts-in-rails/
def inside_layout(layout = "application", &block)
render inline: capture(&block), layout: "layouts/#{layout}"
end
@jcypret
jcypret / .gitlab-ci.yml
Last active September 23, 2016 03:46
GitLab CI for Ember
image: node:latest
cache:
paths:
- node_modules/
- bower_components/
before_script:
- npm install
- npm install -g phantomjs-prebuilt

Keybase proof

I hereby claim:

  • I am jcypret on github.
  • I am jcypret (https://keybase.io/jcypret) on keybase.
  • I have a public key whose fingerprint is 7A1B A777 0AA5 6016 264C CA30 6CD8 25D3 010E 798A

To claim this, I am signing this object:

@jcypret
jcypret / svg_fallback.js
Last active August 29, 2015 15:30
svg-fallback.js
if (!document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1')) {
$('img[src*="svg"]').attr('src', function () { return $(this).data('svg-fallback'); });
}
@jcypret
jcypret / hashids.rb
Created February 10, 2015 07:40
Initializer to enable Hashids in a Rails app
module HashidsSupport
extend ActiveSupport::Concern
class_methods do
def hashids
Hashids.new(table_name, 6)
end
def encode_id(id)
hashids.encode(id)