Skip to content

Instantly share code, notes, and snippets.

@abeger
abeger / gist:2378370
Created April 13, 2012 17:02
Turn foreign keys off before importing a MySQL database
SET FOREIGN_KEY_CHECKS=0;
@abeger
abeger / gist:2378389
Last active October 3, 2015 03:08
Dump a MySQL database with mysqldump to a gzipped SQL file.
mysqldump --compact
--skip-add-locks
--skip-lock-tables
--ignore-table=TABLE1
--ignore-table=TABLE2
-h HOST
-u USER
-p
DATABASE_NAME | gzip > DUMPFILE.sql.gz
@abeger
abeger / gist:2378414
Created April 13, 2012 17:09
Setting up web testing with Cucumber and Capybara
Feature: Testing a web site with Capybara and Cucumber
Useful resources:
The Cucumber wiki: https://github.com/cucumber/cucumber/wiki
Capybara RDocs: http://rubydoc.info/github/jnicklas/capybara/file/README.md
Rspec RDocs: http://rubydoc.info/github/rspec/rspec/frames
The Cucumber Book: http://pragprog.com/book/hwcuc
Ruby Toolbox for Gem Selection: https://www.ruby-toolbox.com/
Interesting discussion of Cucumber and BDD: http://gfxmonk.net/2011/01/26/how-i-replaced-cucumber.html
@abeger
abeger / BaseTable1.php
Created April 25, 2012 03:22
Handle a table with two foreign keys to another table with Doctrine
//Table1 has two foreign keys to Table2
abstract class Table1 extends Doctrine_Record {
public function setUp() {
//...
$this->hasOne('Table2 as FirstAlias', array(
'local' => 'table2_id_first',
'foreign' => 'id'));
@abeger
abeger / gist:3813787
Created October 1, 2012 19:13
Print two things with no carriage returns or spaces
sys.stdout.write('1')
sys.stdout.write('2')
@abeger
abeger / gist:3813804
Created October 1, 2012 19:15
Dictwriter.writeheader() pre-2.7
writer = csv.DictWriter(csvfile, header_list)
writer.writerow(dict((h,h) for h in header_list))
@abeger
abeger / gist:3935950
Created October 23, 2012 00:47
Read a CSV in Python
import csv
f = open('mycsv.csv','r')
try:
reader = csv.reader(f)
for row in reader:
print row
finally:
f.close()
@abeger
abeger / filehash.py
Created November 11, 2012 23:16
Runs through a list of files and finds any that have duplicate md5 hashes
import md5
import datetime
def output_line(line):
timestamp = datetime.datetime.today().strftime("%Y-%d-%m %H:%M:%S")
print(timestamp + ': ' + line)
output_line("Starting program...")
list_file = open('mp3_list.txt','r')
counter = 0
@abeger
abeger / hosts
Created January 9, 2013 20:45
Add a new domain to localhost on OS X
#In /etc/hosts
127.0.0.1 testsite.localdomain
@abeger
abeger / gsc
Last active December 19, 2015 14:39
Wrappers for git svn that stash work before the commands and pop them after:
# Little script that stashes outstanding changes, performs an svn dcommit, and pops the stash
git_stashed=0
git diff-index --quiet HEAD > /dev/null
if [ $? -eq 1 ]
then
echo "Stashing current work..."
git stash
git_stashed=1
fi