Skip to content

Instantly share code, notes, and snippets.

View varyonic's full-sized avatar

Piers Chambers varyonic

View GitHub Profile
varyonic / formtastic_faux_model.rb
Created February 3, 2021 19:37
object that plays well with formtastic
# See
# -------------------------------------------------------------------------------
# Faux model object that plays well with formtastic; this is used for example in
# a contact form which generates a request to salesforce
# -------------------------------------------------------------------------------
class FormtasticFauxModel
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
varyonic / Gemfile
Created November 9, 2017 15:14 — forked from tylerhunt/Gemfile
ActiveAdmin association autocomplete without complicated plugins.
gem 'active_model_serializers'
gem 'activeadmin'
gem 'jquery-ui-rails'

Keybase proof

I hereby claim:

  • I am varyonic on github.
  • I am piersc ( on keybase.
  • I have a public key whose fingerprint is 470E 0AE5 2340 04BF C6CE F9FD 3B88 5D68 B62E 5106

To claim this, I am signing this object:

varyonic / docker-compose.yml
Last active May 18, 2021 13:18
Capybara standalone Selenium Chrome config
build: .
- .:/opt/myapp
- '3000:3000'
- db
- redis
- selenium
varyonic / Dockerfile
Created June 10, 2016 14:14
Dockerfile with chromedriver
# See
FROM myapp:base
# We need wget to set up the PPA and xvfb to have a virtual screen and unzip to install the Chromedriver
RUN apt-get install -y wget xvfb unzip
# Set up the Chrome PPA
RUN wget -q -O - | apt-key add -
RUN echo "deb stable main" >> /etc/apt/sources.list.d/google.list
context "with inputs twice" do
let :body do
build_form do |f|
f.inputs do |f|
f.input :title
f.input :body
f.inputs do |f|
f.input :author
f.input :published_at
varyonic / gist:542c37648de91a02402a
Last active August 29, 2015 14:08
Deprecated but working version of form_buffers removed by
module ActiveAdmin
module Views
class ActiveAdminForm
class DeprecatedFormBufferSubstitute
def initialize(form)
@form = form
def << (value)
@form.text_node value.html_safe

Install with Homebrew

brew install redis

Set up launchctl to auto start redis

$ ln -sfv /usr/local/opt/redis/*.plist ~/Library/LaunchAgents

/usr/local/opt/redis/ is a symlink to /usr/local/Cellar/redis/x.y.z (e.g., 2.8.7)

varyonic / number_finder.rb
Last active August 29, 2015 14:05
Find which element deleted from a sequential array
require 'set'
module NumberFinder
# Most efficient solution for single number missing from sequence.
def self.method1(arr)
(arr.size+1)*(arr.size+2)/2 - arr.reduce(:+)
# Generic solution works with any quantity of missing numbers.
varyonic / inflector_extensions.rb
Created August 21, 2014 20:51
makes titleize respect hypens
# inspired by
module ActiveSupport::Inflector
def nice_title(phrase)
return phrase if phrase =~ /^-+$/
phrase.split('-').map { |part|
if part.chars.count == part.bytes.count
part.split(' ').map { |word| word.mb_chars.titleize }.join(' ')