Skip to content

Instantly share code, notes, and snippets.

View mkelley33's full-sized avatar
🎯
Focusing

Michaux Kelley mkelley33

🎯
Focusing
View GitHub Profile
@mkelley33
mkelley33 / clear-coffee-script.coffee
Created November 28, 2012 01:20
Clear form with CoffeeScript
(($) ->
$.fn.clearForm = ->
@find(":input").each ->
switch @type
when "password", "select-multiple"
, "select-one"
, "text"
, "textarea"
$(this).val ""
when "radio", "checkbox"
@mkelley33
mkelley33 / clear-form.js
Created November 28, 2012 01:18
Clear form with JavaScript
(function($) {
$.fn.clearForm = function() {
return this.find(':input').each(function() {
switch (this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
return $(this).val('');
@mkelley33
mkelley33 / gist:4158093
Created November 28, 2012 00:12 — forked from dodecaphonic/gist:946254
Function set sequences to max in Postgres (instead of writing the same piece of code in ruby again and again)
Taken from http://stackoverflow.com/questions/244243/how-to-reset-postgres-primary-key-sequence-when-it-falls-out-of-sync.
--drop function IF EXISTS reset_sequence (text,text) RESTRICT;
CREATE OR REPLACE FUNCTION "reset_sequence" (tablename text,columnname text) RETURNS bigint --"pg_catalog"."void"
AS
$body$
DECLARE seqname character varying;
c integer;
BEGIN
select tablename || '_' || columnname || '_seq' into seqname;
ActiveSupport::Notifications.subscribe "process_action.action_controller" do |name, start, finish, id, payload|
if payload[:exception]
name, message = *payload[:exception]
Uhoh::Failure.create!(:message => message)
end
end
@mkelley33
mkelley33 / copy_my_computer_ip.sh
Created June 15, 2012 02:28
Copy computer's IP address to clipboard
# When testing a rails website on my local development machine, I found my
# Parallel's VM wouldn't load 0.0.0.0:3000, 127.0.0.1, or localhost:3000.
#
# So I tried using my computers IP address and voila. I thought I'd hone
# my bash chops a little and extract the IP address with the port number
# concatenated to it. This command puts that on the clipboard so I can just
# paste it into IE so I could browser test.
#
# NOTE: the pbcopy command is Mac specific.
#
@mkelley33
mkelley33 / strip_tags.py
Created April 1, 2012 15:00 — forked from braveulysses/strip_tags.py
Strip HTML tags using BeautifulSoup
def strip(untrusted_html):
"""Strips out all tags from untrusted_html, leaving only text.
Converts XML entities to Unicode characters. This is desirable because it
reduces the likelihood that a filter further down the text processing chain
will double-encode the XML entities."""
soup = BeautifulStoneSoup(untrusted_html, convertEntities=BeautifulStoneSoup.ALL_ENTITIES)
safe_html = ''.join(soup.findAll(text=True))
return safe_html
#!/usr/bin/env python
from __future__ import with_statement # needed for python 2.5
from fabric.api import *
from fabric.contrib.console import confirm
from fabric.contrib import files
USAGE = """
================================================================
NOTE:
using this fabfile expects that you have the python utility
@mkelley33
mkelley33 / contact-us-fields.html
Created September 3, 2011 03:31
django 1.3 ajax contact form post using jQuery
<!-- this will be requested and rendered via ajax so we only want the form fields
so we can replace them later using jQuery with the fields PLUS the errors. -->
<div id="form-fields">
{{ form.as_p }}
</div>
@mkelley33
mkelley33 / settings.py
Created August 20, 2011 19:22 — forked from dfeeney/settings.py
Working django-cms settings with django 1.3 staticfiles
# -*- coding: utf-8 -*-
import os
gettext = lambda s: s
PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
DEBUG = True
TEMPLATE_DEBUG = DEBUG

SciPy, PyQt and Matplotlib on OS X Snow Leopard

The squeeky-clean way with homebrew and pip/virtualenv.

$ easy_install pip
$ pip install virtualenvwrapper mercurial
$ brew install gfortran && brew install pyqt
# Have a nice long coffee break -- compiling Qt took 67 minutes on my

quad-core i7 MBP, PyQt another 8.