Skip to content

Instantly share code, notes, and snippets.

View varyonic's full-sized avatar

Piers Chambers varyonic

View GitHub Profile
@varyonic
varyonic / gist:1021054
Created June 11, 2011 22:47
find largest three digit prime palindrome
def prime?(n)
for i in 2 ... n/2
return false if n % i == 0
end
true
end
def palindrome? n
s = n.to_s
s.slice( 0, (s.length+1)/2 ) == s.reverse.slice( 0, (s.length+1)/2 )
@varyonic
varyonic / inflector_extensions.rb
Created August 21, 2014 20:51
makes titleize respect hypens
# inspired by https://gist.github.com/zachrose/7549941
module ActiveSupport::Inflector
def nice_title(phrase)
return phrase if phrase =~ /^-+$/
phrase.split('-').map { |part|
if part.chars.count == part.bytes.count
part.titleize
else
part.split(' ').map { |word| word.mb_chars.titleize }.join(' ')
@varyonic
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(:+)
end
# Generic solution works with any quantity of missing numbers.

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
varyonic / gist:542c37648de91a02402a
Last active August 29, 2015 14:08
Deprecated but working version of form_buffers removed by https://github.com/activeadmin/activeadmin/pull/3486
module ActiveAdmin
module Views
class ActiveAdminForm
class DeprecatedFormBufferSubstitute
def initialize(form)
@form = form
end
def << (value)
@form.text_node value.html_safe
end
context "with inputs twice" do
let :body do
build_form do |f|
f.inputs do |f|
f.input :title
f.input :body
end
f.inputs do |f|
f.input :author
f.input :published_at
@varyonic
varyonic / Dockerfile
Created June 10, 2016 14:14
Dockerfile with chromedriver
# See https://codeship.com/documentation/docker/browser-testing/
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 - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add -
RUN echo "deb http://dl.google.com/linux/chrome/deb/ stable main" >> /etc/apt/sources.list.d/google.list
@varyonic
varyonic / docker-compose.yml
Last active May 18, 2021 13:18
Capybara standalone Selenium Chrome config
web:
build: .
volumes:
- .:/opt/myapp
ports:
- '3000:3000'
links:
- db
- redis
- selenium

Keybase proof

I hereby claim:

  • I am varyonic on github.
  • I am piersc (https://keybase.io/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
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'