Skip to content

Instantly share code, notes, and snippets.

View jmg's full-sized avatar

Juan Manuel Garcia jmg

View GitHub Profile
@jmg
jmg / replace.py
Created November 29, 2011 19:59
search and replace recursively with this python script
"""
Search and replace recursive
Usage:
~$ python replace.py [rootdir] [searched_text] [replace_text]
"""
import os
import sys
if len(sys.argv) <= 1:
@jmg
jmg / TrailingWhiteSpaces
Created January 2, 2012 01:09
Remove Trailing WhiteSpaces from the current dir recursively
find . -not -path '.git' -iname '*.py' -type f -exec sed -i 's/ *$//' '{}' ';'
@jmg
jmg / lxml_scraper.py
Created January 6, 2012 16:06
lxml scraper example
from lxml import etree
from StringIO import StringIO
import urllib2
url = "http://www.ivao.aero/atcss/list.asp"
data = urllib2.urlopen(url).read()
parser = etree.HTMLParser()
tree = etree.parse(StringIO(data), parser)
@jmg
jmg / Another_scraper.py
Created January 6, 2012 19:30
Another_scraper.py
from lxml import etree
from StringIO import StringIO
import urllib2
url = "http://www.ivao.aero/flightss/list.asp"
data = urllib2.urlopen(url).read()
parser = etree.HTMLParser()
tree = etree.parse(StringIO(data), parser)
@jmg
jmg / ProxyDispatcher.php
Created January 12, 2012 03:06
Proxy Dispatcher using php call_user_func_array
<?php
/**
* Proxy Dispatcher using php call_user_func_array (http://us2.php.net/manual/en/function.call-user-func-array.php)
* */
class Foo {
function bar1($arg, $arg2, $arg3, $arg4) {
return "arg: $arg, arg2: $arg2, arg3: $arg3, arg4: $arg4\n";
@jmg
jmg / gist:4271779
Created December 12, 2012 21:26
Django class based view
from django.views.generic import TemplateView
class MyView(TemplateView):
url = "myurl/view1"
template_name = "index/template.html"
def get(self, *args, **kwargs):
context = {}
@jmg
jmg / django-shopify-virtualenv-setup.sh
Created January 6, 2014 17:41
Creates a new django-shopify app using virtualenv
virtualenv env
source env/bin/activate
pip install django==1.4.10 #Replace this for the django version you want
pip install django-shopify
start_shopify_app testing
@jmg
jmg / fabric-django.py
Created January 30, 2014 01:40
django deploy fabric
from fabric.api import run, env
def staging():
env.hosts = ['root@crawley-cloud.com']
def prod():
env.hosts = ['root@crawley-cloud.com']
@jmg
jmg / manage_example.py
Created May 16, 2014 20:49
Configuration for multiple environments in manage.py
import os
# By default assume it's local environment
env = os.environ.get("ENV", "LOCAL")
# PROD/DEV/LOCAL are values the environment variable ENV can have.
# Example for production server: ~$ export ENV=PROD
settings_files = {
"PROD": "production_settings",
"DEV": "development_settings",
import sys
sys.path.append('../api2/include')
from helpers.database import DataBase
from config import config
class WarehousesFinder(object):
def __init__(self):