Skip to content

Instantly share code, notes, and snippets.

View ibanez270dx's full-sized avatar
:shipit:
shippin' it

Jeff Miller ibanez270dx

:shipit:
shippin' it
View GitHub Profile
This file has been truncated, but you can view the full file.
A
a
aa
aal
aalii
aam
Aani
aardvark
aardwolf
Aaron
@ibanez270dx
ibanez270dx / snippet1.rb
Created June 19, 2016 09:34
Snippets from my blog post "Better Conditional Validations in Rails"
class Person < ActiveRecord::Base
validates :surname, presence: true, if: "name.nil?"
end
@ibanez270dx
ibanez270dx / setup.md
Last active June 16, 2016 17:06
Server Setup

Update and upgrade the system

sudo apt-get update && sudo apt-get upgrade && sudo apt-get dist-upgrade && sudo apt-get autoremove
sudo reboot

Configure timezone

sudo dpkg-reconfigure tzdata
sudo apt-get install -y ntp
@ibanez270dx
ibanez270dx / filestack.rb
Last active June 4, 2016 21:19
Helper for displaying an image using filestack.com and their conversion options
# Usage:
# <%= filestack_image_tag post.filestack_url, resize: { width: 100, height: 200, fit: crop }, oil_paint: { amount: 7 } %>
#
# => https://process.filestackapi.com/[FILESTACK API KEY]/resize=width:72,height:72,fit:crop/oil_paint=amount:7/https://cdn.filestackcontent.com/abc23...
def filestack_image_tag(url, task_options={}, image_tag_options={})
base_path = "https://process.filestackapi.com/#{Rails.application.config.filestack_api_key}"
task_path = task_options.collect do |task, options|
"#{task.to_s}=#{options.collect{|k,v| "#{k}:#{v}"}.join(',')}"
end.join('/')
def tracerpoint
calls = []
trace = TracePoint.new(:call, :c_call) do |tp|
calls << [tp.defined_class, tp.method_id, tp.lineno]
end
trace.enable
yield
trace.disable
{
calls: calls.group_by(&:itself).map {|k, v| {k => v.length}}.sort_by {|h| -h.values.first},
@ibanez270dx
ibanez270dx / example.rb
Last active July 14, 2016 03:46
TracerPoint
# Setup ActiveRecord
require 'active_record'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'benchmark.db')
ActiveRecord::Migration.class_eval { create_table :users } unless ActiveRecord::Base.connection.table_exists? 'users'
class User < ActiveRecord::Base;end
# Use TracerPoint
user = User.new
trace = tracerpoint do
puts user.present?
#!/usr/bin/env bash
##################################################
# Bash Prompt
##################################################
# Current configuration produces:
# 00:00:50 jeff@edison:~/Dev/humani.se (git:master:156d0b4) ruby-2.2.0
# → _
@ibanez270dx
ibanez270dx / scraper.rb
Last active September 27, 2017 14:35
Use Capybara w/ Poltergeist (PhantomJS) to scrape the text content from the body of an HTML page located at the given URL.
#!/usr/bin/env ruby
require 'capybara'
require 'capybara/poltergeist'
class Scraper
include Capybara::DSL
Capybara.register_driver :poltergeist do |app|
Capybara::Poltergeist::Driver.new app,
phantomjs_options: ['--load-images=no','--ignore-ssl-errors=yes'],
js_errors: false,
@ibanez270dx
ibanez270dx / deflate.rb
Last active October 28, 2015 13:43
Turn a hash into a sorted array of strings in order to compare to another hash
def deflate(hash)
hash.collect do |k,v|
[k.to_s].push v.is_a?(Hash) ? v.to_a.flatten : v
end.flatten.collect(&:to_s).sort
end
event1 = { foo: 'bar', bars: [4,6,10] }
event2 = { bars: [10,4,6], foo: 'bar' }
event1 == event2
@ibanez270dx
ibanez270dx / gist:75b935176a3dfaa7fdce
Created October 27, 2015 01:22
iTerm2 drop down over full-screen'd apps
Open iTerm2 over full-screen'd apps (HACK)
------------------------------------------
READ: https://gitlab.com/gnachman/iterm2/issues/1570
defaults write /Applications/iTerm.app/Contents/Info LSUIElement true