Skip to content

Instantly share code, notes, and snippets.

@amcclosky
amcclosky / gist:994139
Created May 26, 2011 21:34
This will return a list of alter table statements which drop all foreign keys from the given database in MySQL. (via http://goo.gl/9ZD9N)
SELECT concat('alter table ',table_schema,'.',table_name,' DROP FOREIGN KEY ',constraint_name,';') from information_schema.table_constraints WHERE constraint_type='FOREIGN KEY' AND table_schema='<database_name>';
@amcclosky
amcclosky / remove_foreign_keys.py
Created May 26, 2011 22:37
Remove all foreign key constraints from a MySQL database with Django 1.3
"""
remove_foreign_keys.py
Removes all the foreign key constraints in a django project's MySQL database.
NO FOREIGN KEYS = NO FOREIGN KEY HEADACHES
(of course if you are using anything other than the django ORM its likely to cause other headaches)
Before running this script be sure your django settings module is available
to your environment.
@amcclosky
amcclosky / gist:1050382
Created June 28, 2011 02:46
LaTeX Example
\begin{itemize}
\renewcommand{\labelitemi}{ }
\item
...
@amcclosky
amcclosky / raw_sql_util.rb
Created January 9, 2012 21:32
Simple Rails lib for executing raw SQL
module RawSqlUtil
def sql_select(sql, params)
# We have to do this weirdness because sanitize_sql_array is a protected method
query = ActiveRecord::Base.send(:sanitize_sql_array, [sql].concat(params))
ActiveRecord::Base.connection.select_all(query)
end
@amcclosky
amcclosky / current-tasks.py
Created June 7, 2012 18:44
Pulls your currently "In Progress" tasks from a JIRA instance.
!/usr/bin/env python
# current-tasks.py
# author: Anthony McClosky - http://amcclosky.com
import requests
import json
JIRA_ROOT_URL = "jira.example.com"
JIRA_API_ENDPOINT = "http://%s/rest/api/2.0.alpha1/" % JIRA_ROOT_URL
task :history => :environment do
item = Item.find(21064127)
start_date = item.updated.to_date - 90
item.item_logs.delete_all
90.times do |i|
if i % 7 == 0
item_log = ItemLog.new
item_log.company_id = item.company_id
item_log.item_id = item.id
item_log.beforePrice = item.price
@amcclosky
amcclosky / NativeLibrary.java
Created June 26, 2012 18:44
Dynamic loading of Native code embedded in a jar
package com.amcclosky.nativelib;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
public class NativeLibrary {
public static final long NULL = 0;
protected static final Logger log = Logger.getLogger(Peer.class.getPackage().getName());
@amcclosky
amcclosky / server.sh
Created June 29, 2012 16:34
bash `server` alias
# Start an HTTP server from a directory, optionally specifying the port
# via - http://dl.dropbox.com/u/39519/talks/io-tooling/index.html#13
function server() {
local port="${1:-8000}"
open "http://localhost:${port}/"
python -m SimpleHTTPServer "$port"
}
@amcclosky
amcclosky / README
Created August 22, 2012 16:52 — forked from brutuscat/README
Anonymous Rotating Proxies with Monit, Tor, Haproxy and Delegated. Idea by http://blog.databigbang.com/running-your-own-anonymous-rotating-proxies/
0 - Read http://blog.databigbang.com/running-your-own-anonymous-rotating-proxies/
1 - Install monit, haproxy, tor and delegated.
2 - Setup your environment in the setup.rb file
3 - Just run > ruby setup.rb
4 - ...........
5 - PROFIT! > http://www.southparkstudios.com/clips/151040/the-underpants-business
@amcclosky
amcclosky / rack-mini-profiler-toggle.js
Created September 6, 2012 02:13
Hide rack-mini-profiler Bookmarklet
javascript:(function(){ $('.profiler-results').toggle(); })();