This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Cocoa | |
// Load data from a URL. | |
let url: NSURL = NSURL(string: "http://www.tokyomuslim.com") | |
let resultsData = NSData(contentsOfURL: url, options: NSDataReadingOptions.DataReadingUncached, error: nil) | |
let resultsString:NSString = NSString(data: resultsData, encoding: NSUTF8StringEncoding) | |
// Load JSON data. | |
let jsonUrl: NSURL = NSURL(string: "https://api.github.com/users/mralexgray/repos/") | |
let jsonResultsData = NSData(contentsOfURL: jsonUrl, options: NSDataReadingOptions.DataReadingUncached, error: nil) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
TODO: | |
- Handle 404s / other errors | |
- Handle invalid Attachment ids | |
- | |
*/ | |
class testUploadAttachment { | |
@future(callout=true) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import os | |
import tempfile | |
from django.core.exceptions import SuspiciousFileOperation | |
from django.core.files import File | |
from django.utils._os import safe_join | |
import requests | |
from django.core.files.storage import Storage |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 :( | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
def chgrp(filepath, gid): | |
uid = os.stat(filepath).st_uid | |
os.chown(filepath, uid, gid) |
OlderNewer