Skip to content

Instantly share code, notes, and snippets.

$output-media-width: true !default; // true = all, otherwise use a list of numeric values (eg. 320px 23em)
@mixin media-min-width($bp) {
@if type-of($output-media-width) != list {
@media (min-width: $bp) {
@content;
}
} @else {
$output-bp: find-comparable($bp, $output-media-width);
@if not comparable($output-bp, $bp) {
var page = new WebPage(),
url = 'http://localhost/a-search-form',
stepIndex = 0;
/**
* From PhantomJS documentation:
* This callback is invoked when there is a JavaScript console. The callback may accept up to three arguments:
* the string for the message, the line number, and the source identifier.
*/
page.onConsoleMessage = function (msg, line, source) {
@pgeraghty
pgeraghty / capture-element.coffee
Last active December 12, 2015 08:39
Captures matching element of page with PhantomJS
page = require('webpage').create()
system = require 'system'
if system.args.length is 1
console.log 'Usage: capture-element.coffee <URL> (filename) (#selector)'
phantom.exit 1
else
address = system.args[1]
filename = system.args[2] || 'capture.png'
selector = system.args[3]
@pgeraghty
pgeraghty / gist:4754245
Last active December 12, 2015 09:49
Finding emails and URLs in MySQL columns
# contains email address
where("column_name REGEXP '[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]@[a-zA-Z0-9][a-zA-Z0-9._-]*[a-zA-Z0-9]\.[a-zA-Z]{2,4}'").count
# contains url
where("column_name REGEXP ?", "(https?://|www\\.)[\.A-Za-z0-9\-]+\\.[a-zA-Z]{2,4}").count
@pgeraghty
pgeraghty / gist:4948780
Created February 13, 2013 22:03
ActiveRecord::Base.sample hack for choosing a random model instance - useful for tests and seeding
module ActiveRecord
class Base
# Use like User.sample or User.pluck(:id).sample
def self.sample
order('RAND()').first rescue nil
end
end
end
@pgeraghty
pgeraghty / gist:5431830
Created April 22, 2013 01:13
ox 2.0.0 failure
~ $ ruby -rox -ropen-uri -e 'Ox.sax_parse(Ox::Sax.new, open("http://go.alphashare.com/external/external.php?__method=external_xmlfeed&__feed=kyr&__company_serial=376"))'
*** glibc detected *** ruby: double free or corruption (!prev): 0x00000000018f0530 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x7eb96)[0x7f15e8cc4b96]
/home/paul/.rvm/gems/ruby-2.0.0-p0/gems/ox-2.0.0/ext/ox/ox.so(ox_sax_drive_cleanup+0x21)[0x7f15e73ebaa1]
/home/paul/.rvm/gems/ruby-2.0.0-p0/gems/ox-2.0.0/ext/ox/ox.so(ox_sax_parse+0x640)[0x7f15e73ee1c0]
/home/paul/.rvm/gems/ruby-2.0.0-p0/gems/ox-2.0.0/ext/ox/ox.so(+0x12c5d)[0x7f15e73f0c5d]
/home/paul/.rvm/rubies/ruby-2.0.0-p0/lib/libruby.so.2.0(+0x1996ff)[0x7f15e919e6ff]
/home/paul/.rvm/rubies/ruby-2.0.0-p0/lib/libruby.so.2.0(+0x1a6e4d)[0x7f15e91abe4d]
@pgeraghty
pgeraghty / rails_admin.rb
Last active December 7, 2023 15:22
Add Delayed Job to Rails Admin (make it visible as a model)
RailsAdmin.config do |config|
config.included_models = RailsAdmin::Config.models_pool << 'Delayed::Job'
config.model Delayed::Job do
label 'Task'
navigation_label 'Background Processing'
end
end
@pgeraghty
pgeraghty / gist:9469912
Created March 10, 2014 17:35
Benchmark require load time and memory usage
require 'benchmark'
def require(file)
puts `pmap #{Process.pid} | grep 'total'`
puts Benchmark.measure('') { super }.format("%t require #{file}")
end
@pgeraghty
pgeraghty / gist:9600721
Last active August 29, 2015 13:57
Migrate Carrierwave local images to S3
Image.where.not(photo: nil).each do |image|
image_path = URI.parse(image.photo_url).path
image.update_attribute("remote_photo_url", "http://localhost:3000#{image_path}")
end
@pgeraghty
pgeraghty / deploy.rb
Created December 7, 2014 14:11
Mina - serial deployment to multiple hosts
set :domains, %w[host1 host2 host3]
desc "Deploy to all servers"
task :deploy_all do
isolate do
domains.each do |domain|
set :domain, domain
invoke :deploy
run!
end