Skip to content

Instantly share code, notes, and snippets.

@cpinto
cpinto / shortener.py
Created March 11, 2009 23:24
Single line url shortener in python
# usage: gen_token(n)
# Pass this the numerical ID of an URL at the cross reference table
# and you'll get a tinyurl-like base36 string
gen_token=lambda n,cs="0123456789abcdefghijklmnopqrstuvwxyz":(lambda b=len(cs):cs[n%b]+gen_token((n-(n%b))/b))() if n else ""
@cpinto
cpinto / hacked up ntlm proxy tunnel
Created July 28, 2009 12:04
I use this program to wrap putty, which doesn't support NTLM auth, setting the proxy type to telnet and create a SOCKS proxy to a remote SSH server.
package ntlmptunnel;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetSocketAddress;
import java.net.ServerSocket;
import java.net.Socket;
import org.apache.commons.httpclient.HostConfiguration;
import org.apache.commons.httpclient.NTCredentials;
@cpinto
cpinto / gist:305094
Created February 15, 2010 23:29
dropdown with most recently clicked items
<body>
<select id="teste">
<option>item 1</option>
<option>item 2</option>
<option>item 3</option>
<option>item 4</option>
</select>
<script src="js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function()
#!/bin/bash
SVN_USERNAME=$1
GIT_REPO=$2
SVN_TRUNK_REPO=$3
if [ -z $1 ]; then
echo "Usage: $0 SVN_USERNAME GIT_REPO SVN_TRUNK_REPO"
exit 1
fi
git svn clone --username $SVN_USERNAME $SVN_TRUNK_REPO
<html>
<head><title>wonderstache</title></head>
<body>
<script type="text/x-mustache-yadayada" name="widgetTemplate1">
<div id="notComplicatedWidget">
{{ name }}
</div>
</script>
<div id="widgetContainer">
{{>//script[name=widgetTemplate1]}}
@cpinto
cpinto / mustache_xpath_partials.js
Created October 4, 2010 18:21
Read the top comments
/*
* Q: What is this?
* A: A sample file that uses mustache to render a single html tmeplate (including partials) on the serverside but keeps those partials intact so that they can be used by the client-side as well (ie. browser)
*
* Q: How is this useful?
* A: To you, I have little idea. I'm doing this because I want to be able to fully render a page on the server and then refresh parts of it on the client, while reusing the widget presentation code. As the widget code is in the file, I just have to bring in mustache.js, fetch new data, and have it render the parts I need to update. And I'd like to keep it all in a single file also.
*
* Q: Isn't that template code broken?
* A: Yes. I'll come back to it as I plan to patch Mu to support xpath partials natively.
* */
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<!-- This software application is Twitter-Ware. If you like it,
use it, or have something to say, follow and tell me on Twitter
at @codemonkeyism
http://twitter.com/codemonkeyism
Blog at http://www.codemonkeyism.com
Webssite http://www.simple-kanban.com
See MIT license at bottom.
@cpinto
cpinto / nginx_macosx_installer.sh
Created January 6, 2011 00:01
A script that installs nginx on a MacOS X system
#!/bin/bash
SCRIPT_DIR="`cd $(dirname $0);pwd`"
NGINX_VERSION="0.8.54"
PCRE_VERSION="8.01"
INSTALL_PREFIX="$SCRIPT_DIR/binaries"
DOWNLOAD_DIR="/tmp/src"
LD_LIBRARY_PATH="$INSTALL_PREFIX/lib:$LD_LIBRARY_PATH"
@cpinto
cpinto / mysql_drop_all_tables
Created February 16, 2011 00:28
drop all tables from a specific mysql database
mysql --silent --skip-column-names -u <username> -p<password> <database> -e "show tables" | awk '{ print "drop table " $1 ";"}' | mysql -u <username> -p<password> <password>
@cpinto
cpinto / django_decorators.py
Created February 19, 2011 14:58
a collection of django decorators
from django.contrib import admin
def AutoManaged(clazz):
""" The AutoManaged decorator can be used on model classes which you want to have available
on the administration site with the stock admin forms.
Example usage:
@AutoManaged
class MyModel(models.Model):