Skip to content

Instantly share code, notes, and snippets.

View mariocesar's full-sized avatar

Mario-César mariocesar

View GitHub Profile
@mariocesar
mariocesar / _runserver.py
Last active December 12, 2015 09:19
Conditionaly register a management command in Django. In this example if compass is available on the system, it will load a custom version of runserver to run the compass watch process and the runserver command at the same time.
import os
import subprocess
from optparse import make_option
from django.core.management.commands.runserver import BaseRunserverCommand
from django.conf import settings
class Command(BaseRunserverCommand):
option_list = BaseRunserverCommand.option_list + (
@mariocesar
mariocesar / website.yml
Created February 20, 2013 00:12
An idea in progress. #jekyll #pelican. A more convenient way to make static sites
---
site_name: C1.com.bo
description: C1
keywords: design, bolivia
build_dir: htdocs
apps:
blog:
handler: constructor.handlers.BlogHandler
@mariocesar
mariocesar / Makefile
Last active December 14, 2015 03:08
Deploying Django with a makefile
.PHONY: default deploy
ROOT_PATH := $(shell dirname $(abspath $(lastword $(MAKEFILE_LIST))))
PROJECT_DIR := $(ROOT_PATH)/src
PYENV := $(ROOT_PATH)/env
python := $(ROOT_PATH)/env/bin/python
pip := $(ROOT_PATH)/env/bin/pip
remote = ssh app@deploy -qnt -C '. ~/.profile && cd ~/app &&$1'
@mariocesar
mariocesar / changegroup.sh
Created February 27, 2013 02:55
Mercurial Hook, update the WD if the commit has a a new node for the 'release' branch
#!/usr/bin/env bash
hg diff --stat -r $HG_NODE -r tip
BRANCH=$(hg log --template '{branches}' -r $HG_NODE)
if [ "$BRANCH" == "release" ] ; then
hg update --clean release >&2
fi
@mariocesar
mariocesar / admin.py
Last active December 14, 2015 16:38
A generic view to create a web resource, suitable to use with Backbone #django #backbone #generic-views
from project import api
from .resources import UserResource
api.resources.register(UserResource)
@mariocesar
mariocesar / notes.sh
Created March 17, 2013 04:58
Ubuntu Touch tools for 12.04
# As http://developer.ubuntu.com/get-started/gomobile/ says
sudo add-apt-repository ppa:canonical-qt5-edgers/qt5-proper
sudo add-apt-repository ppa:ubuntu-sdk-team/ppa
sudo apt-get update
sudo apt-get install ubuntu-sdk notepad-qml
# On ubuntu 12.04 qmake 3 is set as the default alternative for qmake,
# I was no able to start correctly the qt-designer, so I search the
# qmake
@mariocesar
mariocesar / string_helpers.js
Last active December 18, 2015 00:18
#javascript #jquery #trim I get tired of removing the blank spaces everywhere, ... If I just realize months ago that I can do this !
// Load after jquery.js
// Instead of $('#my_input').val(), do $('#my_input').trimmed_val()
(function() {
String.prototype.trim = function(){return this.replace(/^\s+|\s+$/g, '');};
String.prototype.ltrim = function(){return this.replace(/^\s+/,'');};
String.prototype.rtrim = function(){return this.replace(/\s+$/,'');};
@mariocesar
mariocesar / u1sdtool.sh
Last active December 21, 2015 08:18
Running ubuntuone headless in a server. // Start reading from ubuntuone-installing.sh
#!/bin/bash
# u1sdtool wrapper for headless Ubuntu One
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
ENVVAR="DBUS_SESSION_BUS_ADDRESS"
eval $(ps xe | grep "[u]buntuone-syncdaemon.*$ENVVAR" | \
sed -E "s/.*($ENVVAR=[^ ]+).*/\1/g" )
if [ -z "$DBUS_SESSION_BUS_ADDRESS" ]; then
# Ubuntu One is not running and we don't have a dbus daemon
@mariocesar
mariocesar / uwsgi-install.sh
Last active December 21, 2015 09:19
Compile and Install uwsgi in Ubuntu 12.04 with gevent support
sudo apt-get install apache2-threaded-dev apache2-utils apache2.2-bin apache2.2-common \
cdbs dctrl-tools devscripts dh-translations erlang-base erlang-dev help2man intltool \
javahelper libapr1 libapr1-dev libaprutil1 libaprutil1-dbd-sqlite3 libaprutil1-dev \
libaprutil1-ldap libarchive-zip-perl libjansson-dev libjansson4 libldap2-dev \
liblua5.1-0-dev libluajit-5.1-2 libluajit-5.1-common libluajit-5.1-dev libmysqlclient-dev \
libperl-dev libpgm-5.1-0 libpython3.2 libreadline-dev libzmq-dev libzmq1 \
python-all python-all-dev python-greenlet-dev python-scour python3-all python3-all-dev \
python3-dev python3.2-dev uuid-dev python-pip build-essential python-dev \
libjansson-dev libpq-dev libxml2-dev libyaml-dev libdb-dev libxslt1-dev libsqlite3-dev \
libcurl4-openssl-dev libgeoip-dev libbz2-dev
@mariocesar
mariocesar / share.py
Last active December 22, 2015 01:28
SimpleHTTPServer reimplemented as a simple wsgi app
"""
Delegate the static serving to uwsgi
DOCUMENT_ROOT=/media/Datos/music uwsgi --wsgi share:application --http :8000 --static-check /media/Datos/music --workers 8 --master
"""
import re
import os
from cStringIO import StringIO