Skip to content

Instantly share code, notes, and snippets.

Peter Philips synth

Block or report user

Report or block synth

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@synth
synth / application_helper.rb
Last active Mar 29, 2016
Ad hoc simple form calendar input
View application_helper.rb
module ApplicationHelper
def mmddyyyy_date_input_tag(scope, attribute, value)
object = Struct.new(attribute, :class).new(value, Hashie::Mash.new(model_name: "Date"))
builder = SimpleForm::FormBuilder.new(scope, object, self, {}, nil)
input = DateMmddyyyyInput.new(builder, attribute, nil, nil)
input.input
end
end
@synth
synth / ecmabara.rb
Created Feb 12, 2016
Ecmabara - A foolish attempt to reimplement capybara-webkit in pure js
View ecmabara.rb
module Ecmabara
def self.included(base_class)
base_class.class_eval do
def self.new
super.extend Page
end
end
end
@synth
synth / gist:d1045e129a5f35d87b69
Last active Mar 5, 2019
High quality gifs on OSX with ffmpeg
View gist:d1045e129a5f35d87b69
brew install ffmpeg ImageMagic mplayer gifsicle
# Option 1
# http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality
ffmpeg -y -i yourmovie.mov -vf fps=10,scale=800:-1:flags=lanczos,palettegen palette.png
ffmpeg -i yourmovie.mov -i palette.png -filter_complex "fps=10,scale=800:-1:flags=lanczos[x];[x][1:v]paletteuse" yourgif.gif
# Option 2
# https://gist.github.com/dergachev/4627207
ffmpeg -i in.mov -s 600x400 -pix_fmt rgb24 -r 10 -f gif - | gifsicle --optimize=3 --delay=3 > out.gif
@synth
synth / add_signature_fields_to_delayed_jobs.rb
Last active Jul 24, 2018
Prevent Duplicates with Delayed Jobs
View add_signature_fields_to_delayed_jobs.rb
class AddFieldsToDelayedJobs < ActiveRecord::Migration
def change
add_column :delayed_jobs, :signature, :string
add_column :delayed_jobs, :args, :text
end
end
@synth
synth / gist:02bae8f2453de3d43353
Last active Aug 29, 2015
Ruby constant lookup hell
View gist:02bae8f2453de3d43353
module Foo
def print_hello
puts HELLO
end
end
class Bar
HELLO="hi there!"
include Foo
end
View keybase.md

Keybase proof

I hereby claim:

  • I am synth on github.
  • I am synth (https://keybase.io/synth) on keybase.
  • I have a public key whose fingerprint is 21F3 1810 5912 3776 C65E B287 C33D 7669 E2A2 3723

To claim this, I am signing this object:

@synth
synth / activerecord-joins-find-multiple-bug.rb
Last active Aug 29, 2015
ActiveRecord bug when joining has_many association and finding multiple records
View activerecord-joins-find-multiple-bug.rb
unless File.exist?('Gemfile')
File.write('Gemfile', <<-GEMFILE)
source 'https://rubygems.org'
gem 'rails', github: 'rails/rails'
gem 'arel', github: 'rails/arel'
gem 'sqlite3'
GEMFILE
system 'bundle'
end
@synth
synth / gist:3f7f4e4726b8e3db2539
Last active Aug 29, 2015
rails 4.1.0 bug when finding multiple records while joining a has_many association
View gist:3f7f4e4726b8e3db2539
rails g model Post
rails g model Comment post_id:integer comment:string
rails c
p1 = Post.create
p2 = Post.create
p1.comments.create(comment: "1")
p1.comments.create(comment: "2")
p2.comments.create(comment: "3")
p2.comments.create(comment: "4")
View gist:6f08396ccb3ce528d0e3
Shiva:recognize pete$ direnv status
direnv exec path /usr/local/Cellar/direnv/2.3.0/bin/direnv
DIRENV_CONFIG /Users/pete/.config/direnv
No .envrc loaded
Found RC path /Users/pete/work/recognize/.envrc
Found RC mtime 1399402756
Found RC allowed true
Found RC allowPath /Users/pete/.config/direnv/allow/ff6c702ed5d2ddd9c0c25dc39583506d3fe5944604480c51eb7473287e7d7d48
@synth
synth / nice_errors
Created Jan 19, 2014
A recursive algorithm for generating nested error messages in rails
View nice_errors
def nice_errors(object, errors)
object.errors.each do |key|
error_obj = object.send(key)
if error_obj.kind_of?(Array)
errors[key] = {}
error_obj.each {|item| nice_errors(item, errors[key])}
elsif error_obj.kind_of?(ActiveRecord::Base)
errors[error_obj.id] = {}
nice_errors(error_obj, errors[error_obj.id])
else
You can’t perform that action at this time.