Skip to content

Instantly share code, notes, and snippets.

@abeger
abeger / httpcode.sh
Last active February 16, 2023 20:18
Just get the HTTP code for a given URL with curl
curl -I -s -o/dev/null -w"%{url_effective} %{http_code}\n" -m 5 URL
@abeger
abeger / gist:0913ca7cd3d73cf22c3e
Last active August 29, 2015 14:03
Find all files ending in php, tpl, html, or shtml that contain the word "foo" and throw them all into a vim instance
vim $(find . -regex '.*\.\(php\|tpl\|html\|shtml\)' -print0 | xargs -0 grep -l "foo")
@abeger
abeger / gist:7142341
Last active December 26, 2015 11:18
Get the number of unique values in each non-empty column in each non-empty table in a MySQL database. Handy for getting a rough idea of what your data looks like. I'm sure there's a more Ruby-ic way to do this, but this gets the job done.
c = ActiveRecord::Base.connection
c.execute("SHOW TABLES").each do |t|
table = t[0]
c.execute("SELECT COUNT(*) FROM `#{table}`").each do |n|
count = n[0]
next if count == 0
puts
puts "#{table.upcase}: #{count}"
collist = c.execute("DESC `#{table}`").map {|x| x[0]}
.select { |x| !['created_at', 'updated_at', 'id', 'visible'].include?(x) }
@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
@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 / 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 / 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 / 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: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 / 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'));