This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// W2V script intended for http://www.globalforestwatch.org/map/3/15.00/27.00/ALL/grayscale/loss,forestgain?begin=2001-01-01&end=2013-01-01&threshold=30 | |
w2v.info("Injecting polyfill"); | |
// Inject W2V polyfill so that this script will run in normal browsers without errors | |
(function(d, s, id){ | |
var js, fjs = d.getElementsByTagName(s)[0]; | |
if (d.getElementById(id)){ return; } | |
js = d.createElement(s); js.id = id; | |
js.onload = function(){ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# seconds = duration in seconds as integer i.e. time.to_i | |
[ | |
seconds / (60*60*24), # days | |
seconds % (60*60*24) / (60*60), # hours | |
seconds % (60*60) / 60, # minutes | |
seconds % 60 # seconds | |
].zip(%w(d h m s)).map { |u| u.join unless u.first.zero? }.compact.tap { |a| a << '<1s' if a.none? }.join | |
# Uses Object#tap rather than Rails Object enhancements like Object#presence |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<a href="#">Test</a> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'benchmark' | |
def require(file) | |
puts `pmap #{Process.pid} | grep 'total'` | |
puts Benchmark.measure('') { super }.format("%t require #{file}") | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ $ 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] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ActiveRecord | |
class Base | |
# Use like User.sample or User.pluck(:id).sample | |
def self.sample | |
order('RAND()').first rescue nil | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |