Skip to content

Instantly share code, notes, and snippets.

View mwlang's full-sized avatar

Michael Lang mwlang

View GitHub Profile
def clone_table(src_db, dest_db, table, key_field = nil, filter = nil)
# filter the rows to be cloned
src_ds = src_db[table]
filter.each_pair{|k, v| src_ds = src_ds.filter(k => v)} unless filter.nil?
# truncate if no key_field
unless key_field
puts "truncating #{table}..."
dest_db[table].delete
end
def clone_table(src_db, dest_db, table)
# filter the rows to be exported
dataset = src_db[table]
# truncate if no key_field
unless key_field
puts "truncating #{table}..."
dest_db[table].delete
end
require 'rubygems'
require 'sequel'
require 'faker'
require 'sequel_plus'
require 'progressbar'
require 'benchmark'
begin
DB = Sequel.connect("jdbc:mysql://localhost/jdbc_test?user=root")
rescue
@mwlang
mwlang / after_use_textmate
Last active December 17, 2015 22:19
TextMate hook that will switch Textmate's ruby versions automatically when rvm switches ruby versions....see http://www.christopherirish.com/2010/06/28/how-to-setup-textmate-to-use-rvm/ for background -- this script simpy automates the rvm wrapper ${RUBY_VERSION} textmate call described in the blog post.
#!/usr/bin/env bash
#
# Automatically sets the wrappers for textmate's use
# Based on article posted: http://www.christopherirish.com/2010/06/28/how-to-setup-textmate-to-use-rvm/
# Set up the TM_RUBY shell variable as described and remove the Builder as described and restart TextMate
#
# Make this script executable and you should be good to go! TextMate will stay in sync with rvm, which
# generally means the last project folder you switched into from terminal shell.
#
if [[ $TM_WRAPPING != "1" ]]; then
prefix: 'textmate'.
wrapper: 'ruby'.
wrapper: 'gem'.
wrapper: 'irb'.
wrapper: 'ri'.
wrapper: 'rdoc'.
wrapper: 'rake'.
wrapper: 'erb'.
wrapper: 'testrb'.
@mwlang
mwlang / show.rb
Created June 14, 2013 17:34
Pivitol exporter viewer
require 'csv'
raise "usage: ruby show.rb filename" unless ARGV[0]
fn = ARGV[0]
raise "specified file, #{fn.inspect} does not exist" unless File.exist? fn
flattened_tasks = CSV.read(fn)
headers = flattened_tasks.shift
require 'pcap'
require 'getopts'
def pcaplet_usage()
$stderr.print <<END
Usage: #{File.basename $0} [ -dnv ] [ -i interface | -r file ]
#{' ' * File.basename($0).length} [ -c count ] [ -s snaplen ] [ filter ]
Options:
-n do not convert address to name
-d debug mode
@mwlang
mwlang / routes.rb
Created June 20, 2013 17:18
passing the new path from router during redirect
scope(:controller => 'site/about') do |about|
get 'about/community', :controller => 'site', :action => 'redirect', :path => '/community', as: :site_about_community
get 'about/offices', :controller => 'site', :action => 'redirect', :path => '/offices', as: :site_about_offices
get 'about/office/:id', :controller => 'site', :action => 'redirect', :path => '/offices', as: :site_about_office_detail
end
module ApplicationHelper
def back_url(parents)
url_for(parents).split("/")[0..-2].join("/")
end
end
require 'minitest_helper'
ADDRESSES = {
toledo_ohio: {
street1: '',
city: 'Toledo',
state: '',
zip: '',
country: 'United States',
expected_obfuscated_street: '',