Skip to content

Instantly share code, notes, and snippets.

View bsnux's full-sized avatar
💭
👨‍💻

Arturo Fernandez bsnux

💭
👨‍💻
View GitHub Profile
@bsnux
bsnux / gist:4502604
Created January 10, 2013 14:52
Get a short URL using Google API
#!/usr/bin/python
import sys
import requests
import json
headers = {'content-type': 'application/json'}
url = 'https://www.googleapis.com/urlshortener/v1/url'
@bsnux
bsnux / set_language_from_request.py
Created January 25, 2013 09:25
Django => Reading and setting current language from request
from django.utils.translation import activate
lang = request.GET['language']
activate(lang)
@bsnux
bsnux / gist:4672788
Created January 30, 2013 11:49
Storing Django queryset in session. Useful when you need to pass querysets between requests
import pickle
# Session key
key = 'my_qs'
# Pizza => model example
qs = Pizza.objects.filter(ingredient='tomato')
# Dumping data
request.session[key] = pickle.dumps(qs.query)
@bsnux
bsnux / jquery_plugin_skeleton.js
Created February 5, 2013 10:33
Simple skeleton for creating a jQuery plugin
(function( $ ){
/* Global variables for the plugin */
var defaults = {
timeout: 15
};
var settings = {};
var form;
@bsnux
bsnux / create_fieldfile.py
Created February 14, 2013 11:57
Creating a Django FileField from shell
from django.core.files import File
f = File(open('path_to_file','r'))
m = MyModel.objects.create(one_field='value')
m.file_field = f
m.save()
@bsnux
bsnux / gist:7485014
Created November 15, 2013 14:18
Backup PostgreSQL
#!/bin/bash
pg_dump mydb -U myuser | gzip > /home/user/db_backups/`date '+%Y-%m-%d-%H-%M'`.sql.gz
@bsnux
bsnux / createdb.sh
Created November 15, 2013 14:20
Create PostgreSQL on OS X
!#/bin/zsh
createdb -E utf-8 mydb
@bsnux
bsnux / create_user_db.sh
Created November 15, 2013 14:24
Create PostgreSQL user and DB
#!/bin/bash
# Next command will ask you for entering username/password
sudo -u postgres createuser -P
sudo -u postgres createdb mydb -O myuser
@bsnux
bsnux / sync_remote_local.sh
Last active December 28, 2015 10:19
Syncing remote and local directories
#!/bin/bash
# Copying files from remote to local
# ----
# Syncs remote '/home/user/sync_test' with local '/tmp/sync'
# You should run this command each time you need remote directory
# gets syncronized with your local one
rsync -avzhe ssh user@yourhost:/home/user/sync_test/ /tmp/sync
@bsnux
bsnux / get_instagram_url.py
Last active December 31, 2015 22:49
Gets a public URL for a given Instagram photo ID
#!/usr/bin/python
#------------------------------------------------------------------------
# Gets public URL for a given Instagram photo ID.
# Example: http://instagram.com/p/h6qXCCmCJf/ => photo_id = h6qXCCmCJf
#------------------------------------------------------------------------
import requests
import sys
import json