Skip to content

Instantly share code, notes, and snippets.

View jmahmood's full-sized avatar

Jawaad Mahmood jmahmood

View GitHub Profile
@jmahmood
jmahmood / PyRSS2GenCDATA.py
Created March 7, 2011 08:48
A concept class that extends PyRSS2Gen to permit you to include unescaped CDATA characters in RSS feeds.
# This is insecure, and only here for a proof of concept. Your mileage may vary. Et cetra.
import PyRSS2Gen
import datetime
class NoOutput:
def __init__(self):
pass
def publish(self, handler):
pass
@jmahmood
jmahmood / retrieve_mail.py
Created June 8, 2011 08:52
Retrieve Emails by Python, using Generators and Closures
# Jawaad Mahmood
# June 8th, 2011
# based on code I found at http://stackoverflow.com/questions/730573/django-to-send-and-receive-email.
# By using generators and nested functions / closures, I can more easily use this in code without screwing around
# with passing around messages, etc..
# Not sure if deletion works on the servers. Oh well :(
"""
@jmahmood
jmahmood / necessary_libs.py
Created December 1, 2011 08:02
How to use Paramiko to get rid of files from your rssh /chrootjail/lib path that don't have to be there.
#!/usr/bin/env python
# Moves files in directory, then checks to see if SCP works.
# If SCP fails, it moves the files back.
# This assumes you have a functional chroot jail configured with rssh, but you want to get rid of all files that are unnecessary.
# This works as follows
# 1. Script moves file from /chrootroot/lib/ to a temporary directory
# 2. Script attempts to connect to with a sftp connection using a restricted user
# 3. If user can connect and upload the file he wants to, the file can be discarded
# ELSE, the file is moved back.
@jmahmood
jmahmood / views.example.py
Created January 26, 2012 03:44
An example of a reusable Django View
# This is not tested and not complete, but give an interesting example of how you can turn a Django view into something reusable.
# It is based on the code here: http://code.google.com/p/django-jqchat/
# It might make sense to turn this into an abstract base class.
# The purpose of this is:
# 1. Improved code reuse for outputting data.
# 2. Easier modification to relevant areas
# 3. Because it is new and interesting to me (Kiss my future jobs goodbye for admitting that :/)
# 4. Can stash it in a different file, so the view is not as cluttered-up.
@jmahmood
jmahmood / image_resize.py
Created February 14, 2012 07:01
Resize Images in Python
#!/usr/bin/env python
# This is intended as a quick and dirty image resizer. It doesn't even check to see if the filename is already in use. I
# don't suggest it for production use without changes.
# Stashing it here for future improvements.
import Image
import sys
import os
def resize_image_width_ratio(filename, new_filename, max_width=800):
@jmahmood
jmahmood / output_screenshots.sh
Created March 23, 2012 06:04
Get Screenshots for files in a directory
for file in *.m4v ; do
ffmpeg -ss 00:00:15 -i $file -vframes 1 -an -f image2 $(echo $file | rev | cut -f2- -d. | rev).png
done
@jmahmood
jmahmood / chgrp.py
Created April 27, 2012 04:23
Python chgrp Function
import os
def chgrp(filepath, gid):
uid = os.stat(filepath).st_uid
os.chown(filepath, uid, gid)
@jmahmood
jmahmood / stickystudy.py
Created May 19, 2012 08:40
Sticky Study Import File Generator
o = open("Kanji_Vocab_List.txt")
contents = o.read().decode('utf8')
o.close()
c = contents.split()
words = [ (c[i], c[i+1]) for i in range(len(c)) if i%2==0 ]
# This is for testing actually writing the kanji.
output = []
@jmahmood
jmahmood / example.py
Created July 9, 2012 03:54
3 years of python
A few years ago:
def parseBugzillaCookies(self,s):
if s is None: return {self.SESSION_ID_STRING:None}
ret = {}
tmp = s.split(';')
for t in tmp:
t = t.replace('HttpOnly, ','')
coppia = t.split('=')
if coppia[0].strip() in ['Bugzilla_logincookie','Bugzilla_login']:
@jmahmood
jmahmood / base_websql.coffee
Created September 6, 2012 08:15
Coffeescript WebSQL
# This is a simple websql class I built in coffeescript.
# This gives a good example of how to use "fat arrows" to maintain a different
# level's "this" pointer - without fat arrows, you will not be able to save @results
"use strict";
root = exports ? this
class @websql
constructor: ->