Skip to content

Instantly share code, notes, and snippets.

@adeel
adeel / itex2mml.php
Created March 31, 2014 20:19
A MediaWiki extension which adds support for itex2mml.
<?php
# itex2mml.php
# A MediaWiki extension which adds support for itex2mml.
if (!defined('MEDIAWIKI')) die();
$wgExtensionCredits['other'][] = array(
'name' => 'itex2mml',
'description' => 'Adds support for math via itex2mml.',
'version' => '0.1'
% arrows
\newcommand{\too}{\longrightarrow}
\newcommand{\isoto}{\stackrel{\sim}{\longrightarrow}}
\newcommand{\hook}{\hookrightarrow}
\newcommand*{\longhookrightarrow}{\ensuremath{\lhook\joinrel\relbar\joinrel\rightarrow}}
\newcommand{\hooklong}{\longhookrightarrow}
\newcommand{\sub}{\subset}
% operators
\DeclareMathOperator*{\fibprod}{\times}
@adeel
adeel / nlab_definition.js
Created January 7, 2015 11:24
bookmarklet to insert the template for a definition environment (for nLab editors)
// Save the following as a bookmark:
// javascript:(function()%7Bfunction%20callback()%7B(function(%24)%7Bvar%20jQuery%3D%24%3Bvar%20str%20%3D%20%22%2B--%20%7B%3A%20.un_defn%7D%5Cn%5C%23%23%23%23%23%23%20Definition%5Cn%5Cn%5C%3D--%5Cn%22%3Bvar%20caretPos%20%3D%20document.getElementById(%22content%22).selectionStart%3Bvar%20textareaVal%20%3D%20%24(%22%23content%22).val()%3B%24(%22%23content%22).val(textareaVal.substring(0%2C%20caretPos)%20%2B%20str%20%2B%20textareaVal.substring(caretPos))%7D)(jQuery.noConflict(true))%7Dvar%20s%3Ddocument.createElement(%22script%22)%3Bs.src%3D%22https%3A%2F%2Fajax.googleapis.com%2Fajax%2Flibs%2Fjquery%2F1.7.1%2Fjquery.min.js%22%3Bif(s.addEventListener)%7Bs.addEventListener(%22load%22%2Ccallback%2Cfalse)%7Delse%20if(s.readyState)%7Bs.onreadystatechange%3Dcallback%7Ddocument.body.appendChild(s)%3B%7D)()
function runInstikiDefnBookmarklet() {
var str = "+-- {: .un_defn}\n\
###### Definition\n\n\
=--\n";
var caretPos = document.getElementById("content").selectionStart;
var
import berry
from berry import path, render, redirect
from models import Post
def index():
posts = Post.query.all()
return render('index', {'posts': posts})
path('^$').GET = index
def post(id):
# test.py
@cmd('^$')
def index():
# this is what shows up when you run python test.py
return "Welcome to test.py..."
@get('^hello (.+)$')
def hello(name):
# this shows up when you run python test.py hello <name>
@adeel
adeel / mail.py
Created August 4, 2009 03:20
simple smtplib wrapper
import smtplib
from smtplib import SMTPException
from email.mime.text import MIMEText
config = {
'host': None,
'port': None,
'username': None,
'password': None,
'use_tls': False,
http://74.125.95.132/search?q=cache:81MAwvRRt4kJ:twitter.com/_why/status/3389695893
programming is rather thankless. you see your works become replaced by superior works in a year. unable to run at all in a few more.
# How to get the password hint for lib.homelinux.org
import httplib
conn = httplib.HTTPConnection("lib.homelinux.org")
conn.request("HEAD", "/")
print conn.getresponse().getheaders()[3][1].decode("cp1251")
@adeel
adeel / recursive_dict_update.py
Created December 29, 2010 07:03
Like dict.update, but recursive.
def _recursive_dict_update(x, y):
for key, val in y.iteritems():
if isinstance(val, dict):
if not x.has_key(key):
x[key] = {}
x[key] = _recursive_dict_update(x[key], val)
elif isinstance(val, list):
if not x.has_key(key):
x[key] = []
x[key].extend(val)
@adeel
adeel / wdiff-html
Created February 12, 2011 02:13
How to get a word-by-word diff of two text files, and format it as html
#!/bin/sh
FILE1=$1
FILE2=$2
# http://www.gnu.org/software/wdiff/
wdiff -w "<span style='color:red; text-decoration: line-through;'>" \
-x "</span>" \
-y "<span style='color:green'>" \
-z "</span>" \