Skip to content

Instantly share code, notes, and snippets.

View erickgnavar's full-sized avatar
🐛
Writing bugs one at time

Erick Navarro erickgnavar

🐛
Writing bugs one at time
View GitHub Profile
@erickgnavar
erickgnavar / hack.sh
Created June 20, 2012 00:15 — forked from erikh/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#
@erickgnavar
erickgnavar / base.html
Created July 1, 2012 23:26
Django base template
<!doctype html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>{% block title %}{% endblock %}</title>
{% block extrastyle %}{% endblock %}
</head>
<body>
<header id="page-header">
{% block header %}{% endblock %}
@erickgnavar
erickgnavar / .bash_template
Created October 27, 2012 00:08
bash config
#link selenium
alias selenium-server="java -jar /usr/local/Cellar/selenium-server-standalone/2.25.0/selenium-server-standalone-2.25.0.jar"
#Python-Mysql
function fix_mysql_python() {
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib
}
@erickgnavar
erickgnavar / gist:4282778
Created December 14, 2012 04:56
Django pagination with bootstrap
{% load common_tags %}
<!--Pagination-->
<div class="pagination pagination-centered">
<ul>
{% if page_obj.has_previous %}
<li><a href="?page={{ page_obj.previous_page_number }}">«</a></li>
{% else %}
<li class="disabled"><a href="">«</a></li>
{% endif %}
{% for page_number in page_obj.paginator.num_pages|to_range %}
@erickgnavar
erickgnavar / gist:4282781
Created December 14, 2012 04:57
Common tags
from django import template
register = template.Library()
@register.filter
def to_range(value):
return range(1, value + 1)
@erickgnavar
erickgnavar / gist:4282785
Created December 14, 2012 04:58
Django LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from django.utils.decorators import method_decorator
class LoginRequiredMixin(object):
@method_decorator(login_required)
def dispatch(self, *args, **kwargs):
return super(LoginRequiredMixin, self).dispatch(*args, **kwargs)
# Some good references are:
# http://russbrooks.com/2010/11/25/install-postgresql-9-on-os-x
# http://www.paolocorti.net/2008/01/30/installing-postgis-on-ubuntu/
# http://postgis.refractions.net/documentation/manual-1.5/ch02.html#id2630392
#1. Install PostgreSQL postgis and postgres
brew install postgis
initdb /usr/local/var/postgres
pg_ctl -D /usr/local/var/postgres -l /usr/local/var/postgres/server.log start
def haversine(site_one, site_2):
"""
Calculate the great circle distance between two points
on the earth (specified in decimal degrees)
"""
lat1 , lon1 = site_one
lat2 , lon2 = site_2
# convert decimal degrees to radians
lon1, lat1, lon2, lat2 = map(radians, [lon1, lat1, lon2, lat2])
@erickgnavar
erickgnavar / gist:5257488
Created March 27, 2013 19:55
Bash template
# common
alias grep="grep --color=auto"
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm"
function find_word() {
if [ $1 ]; then
find . -type f -name "*.py" -exec grep --color=always -nH "$1" {} \;
else
from flask import Flask, request, redirect, url_for, make_response, abort
from werkzeug import secure_filename
from pymongo import Connection
from pymongo.objectid import ObjectId
from gridfs import GridFS
from gridfs.errors import NoFile
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
DB = Connection().gridfs_server_test
FS = GridFS(DB)