Skip to content

Instantly share code, notes, and snippets.

View alanjds's full-sized avatar

Alan Justino da Silva alanjds

  • Santo André, São Paulo/SP - Brazil
View GitHub Profile
#make some settings accessible via settings.FOO from within templates
from django.conf import settings
def exposed_settings(request):
context_settings = dict()
for x in settings.TEMPLATE_CONTEXT_SETTINGS:
context_settings[x] = getattr(settings, x)
return { 'settings': context_settings }
@stefanfoulis
stefanfoulis / gist:715194
Created November 25, 2010 10:39
django-filer: creating Folders and Files programmatically, If-Modified-Since aware download (quick and dirty)
def download_cover(url, name=None):
#print "========================== START"
#print "==== COVER URL: %s" % (url,)
purl = urlparse(url)
path = purl.path
if path.startswith('/'):
path = path[1:]
abspath = os.path.join(settings.MEDIA_ROOT,settings.RADIOPLAYLIST_COVERS_PREFIX,path)
relpath = os.path.join(settings.RADIOPLAYLIST_COVERS_PREFIX,path)
if not os.path.exists(os.path.dirname(abspath)):
@huyng
huyng / reflect.py
Created February 7, 2011 17:57
A simple echo server to inspect http web requests
#!/usr/bin/env python
# Reflects the requests from HTTP methods GET, POST, PUT, and DELETE
# Written by Nathan Hamiel (2010)
from BaseHTTPServer import HTTPServer, BaseHTTPRequestHandler
from optparse import OptionParser
class RequestHandler(BaseHTTPRequestHandler):
def do_GET(self):
@mlafeldt
mlafeldt / scp_demo.py
Created February 24, 2011 09:09
[Python] paramiko examples
#!/usr/bin/env python
import sys, paramiko
if len(sys.argv) < 5:
print "args missing"
sys.exit(1)
hostname = sys.argv[1]
password = sys.argv[2]
@scottmessinger
scottmessinger / backbone-todos.js
Created June 19, 2011 00:09
Backbone.js todos vs knockout.js todos
We couldn’t find that file to show.
@westonruter
westonruter / ko.sh
Created October 24, 2011 06:01
Script for opening Komodo from the (Mac) command line
#!/bin/bash
# Usage: ko [options] FILE
# @author Weston Ruter (@westonruter)
# Komodo Edit or Komodo IDE?
if [ -e "/Applications/Komodo Edit.app" ]; then
app="Komodo Edit"
else
app="Komodo IDE"
fi
@joergschiller
joergschiller / a2dp_sink_ubuntu_linux.md
Created January 24, 2012 23:05
A2DP Sink on Ubuntu Linux with bluez (streaming bluetooth stereo audio from smartphone to pc)

Howto Enable and Use A2DP Sink on Ubuntu Linux with Bluez

  1. Add Enable=Source to /etc/bluetooth/audio.conf right after [General].

  2. Find address in form XX:XX:XX:XX:XX:XX of phone with hcitool scan.

  3. Pair and trust smartphone with sudo bluez-simple-agent hci0 XX:XX:XX:XX:XX:XX and sudo bluez-test-device trusted XX:XX:XX:XX:XX:XX yes.

  4. Create loopback in pulseaudio connection bluetooth a2dp source with alsa sink:

@schlamar
schlamar / processify.py
Last active April 17, 2024 19:19
processify
import os
import sys
import traceback
from functools import wraps
from multiprocessing import Process, Queue
def processify(func):
'''Decorator to run a function as a process.
Be sure that every argument and the return value
@jobliz
jobliz / RedisPythonPubSub1.py
Created May 4, 2012 17:58
A short script exploring Redis pubsub functions in Python
import redis
import threading
class Listener(threading.Thread):
def __init__(self, r, channels):
threading.Thread.__init__(self)
self.redis = r
self.pubsub = self.redis.pubsub()
self.pubsub.subscribe(channels)
@schlamar
schlamar / gist:2993700
Last active September 23, 2016 20:55
urllib2 HTTPS connection with proxy and cert verification
import httplib
import urllib2
import ssl
import certifi
from backports.ssl_match_hostname import match_hostname
class CertValidatingHTTPSConnection(httplib.HTTPConnection):
default_port = httplib.HTTPS_PORT