Skip to content

Instantly share code, notes, and snippets.

View andrewyoo's full-sized avatar

Andrew Yoo andrewyoo

  • Salt Labs
  • Los Angeles, Formerly: Manila, Emeryville, and Manhattan
View GitHub Profile
@andrewyoo
andrewyoo / capybara_custom_chrome_headless.rb
Last active December 3, 2023 14:01
Getting Started: Capybara + Selenium + Custom user-agent, chrome settings
require 'capybara'
require 'selenium/webdriver'
require 'capybara/dsl'
include Capybara::DSL
Capybara.run_server = false
# setting driver
# rack_test is default and non js
# selenium_chome_headless seems best headless option
@andrewyoo
andrewyoo / extract_copy_from_locales.rb
Last active March 19, 2017 22:36
Extract Copy from Rails Locale Files
h = {}
Dir.glob('config/locales/**/*.yml').each do |f|
h[f] = YAML.load(File.read(f))
end
@lines = []
def print_h(h)
h.each do |k,v|
if v.is_a? String
@lines << v
@andrewyoo
andrewyoo / keep_sites_active.rb
Created March 20, 2012 19:20
Cron to keep sites on shared hosts active
#put file list on dropbox public folder
#run cron every 5 mins
page = `curl 'http://dl.dropbox.com/u/xxxxxxx/sites_to_reload.txt' 2>/dev/null`
sites = page.split("\n").each do |site|
`curl '#{site.strip}' > /dev/null 2>&1`
end
@andrewyoo
andrewyoo / backup_mysql_to_s3.rb
Created February 1, 2012 18:55
Backup mysql DB to S3 in ruby
require 'rubygems'
require 'aws/s3'
include AWS::S3
Base.establish_connection!(
:access_key_id => '#####################',
:secret_access_key => '###############################'
)
today = Time.now.strftime("%Y%m%d")