Skip to content

Instantly share code, notes, and snippets.

View antonagestam's full-sized avatar
🍉

Anton Agestam antonagestam

🍉
View GitHub Profile
@antonagestam
antonagestam / gist:1989563
Created March 6, 2012 22:52
JavaScript: jQuery: Pub/Sub
// Works in modern browsers + IE9, but Modernizr has a polyfill baked in for function.bind.
// Hat tip Paul Irish
(function($){
var o = $( {} );
$.subscribe = o.on.bind(o);
$.unsubscribe = o.off.bind(o);
$.publish = o.trigger.bind(o);
})(jQuery);
@antonagestam
antonagestam / gist:4565712
Last active December 11, 2015 07:19
Shell script that runs `workon project_name` when entering the project directory
function f(){
if [[ $VIRTUAL_ENV != /Users/anton/.virtualenvs/fundedbyme ]];
then
workon fundedbyme
fi
cdvirtualenv
}
function r(){
f
@antonagestam
antonagestam / gist:4586768
Created January 21, 2013 15:18
Remove everyone's emails but admin's
for u in User.objects.all():
if u.email not in ['msn@antonagestam.se','appel268576@gmail.com']:
u.email = '%s@example.com' % u.username
u.save()
@antonagestam
antonagestam / gist:4604297
Created January 23, 2013 10:46
Start development tools
function dev(){
f
sass --watch fundedbyme/static/css/sass:fundedbyme/static/css --style compressed &
rabbitmq-server -detached &
open /Applications/Postgres.app &
}
@antonagestam
antonagestam / settings.py
Last active December 20, 2015 04:59
Django AWS storages
# …
###### AWS SETTINGS
AWS_MEDIA_BUCKET_NAME = AWS_MEDIA_CUSTOM_DOMAIN = 'media.mysite.com'
AWS_STATIC_BUCKET_NAME = AWS_STATIC_CUSTOM_DOMAIN = 'static.mysite.com'
###### END AWS SETTINGS
@antonagestam
antonagestam / Match pattern
Created September 24, 2013 00:31
Replace Django url tags with > 1.5 syntax
\{% url (?!(?:\'|\"))(.*?)( .*?) ?%}
@antonagestam
antonagestam / gist:8176498
Last active January 1, 2016 17:19
Level up
# Move contents of dir to current dir
function level_up(){
temp_name="_$1_temp"
mv $1 $temp_name; mv $temp_name/{,.}* .; rmdir $temp_name;
}
function __shcmd_complete(){
echo "COMPLETING WOHO!"
tput rc
tput ed
echo "COMPLETING WOHO!"
export READLINE_LINE="uh-huh"
}
function read_completion(){
set -o emacs
@antonagestam
antonagestam / middleware.py
Last active June 29, 2017 08:28
JSONRequestMiddleware
import json
from .utils import copy_body
class JSONRequest(dict):
def __init__(self, request):
try:
data = json.loads(copy_body(request))
self.is_valid = True
@antonagestam
antonagestam / gist:095ddb4e4f4cb6029d28
Last active August 29, 2015 14:06
Working with Zanox

Getting started with Zanox

Confused!? Yeah, me too ... Zanox' developer center is super-confusing and even finding the documentation for the correct API was tough. I had to realize that our app should access the Publisher API, which kind of makes sense but I didn't look at it first because I was thinking it's for publishing items to Zanox.