Skip to content

Instantly share code, notes, and snippets.

View hersonls's full-sized avatar

Herson Leite hersonls

View GitHub Profile
@hersonls
hersonls / .bashrc
Last active October 7, 2015 23:47
Show git branch on bash prompt
## My alias
# mkpass - Generate random string with 12 chars
alias mkpass='python -c "import random, string; print \"\".join(random.choice(string.ascii_letters + string.digits + \"[]\") for x in range(12))"'
## Virtualenvwrapper Settings
VIRTUALENVWRAPPER=`which virtualenvwrapper.sh`
export WORKON_HOME=$HOME/.virtualenvs
if [ -f ${VIRTUALENVWRAPPER} ]; then
@hersonls
hersonls / lesscommand.py
Created August 3, 2012 20:09
Submlime plugin for less and css header doc
import sublime, sublime_plugin
import datetime
class Command(sublime_plugin.TextCommand):
def run(self, edit):
doc = """/*
Author: <Auhtor name>
Date: %s
Description:
*/
@hersonls
hersonls / Preferences.sublime-settings
Created August 26, 2012 21:36
Personal Sublime Text 2 Settings
{
"font_size": 8,
"tab_size": 2,
"word_wrap": false,
"translate_tabs_to_spaces": true,
"rulers": [80, 120]
}
@hersonls
hersonls / settings.py
Last active March 15, 2022 16:11
Django Settings
import os
# Project information
PROJECT_PATH = os.path.realpath(os.path.dirname(__file__))
PROJECT_NAME = os.path.basename(PROJECT_PATH)
# Helpers
path = lambda *p: os.path.join(PROJECT_PATH, *p)
# Debug
@hersonls
hersonls / urls.py
Created August 27, 2012 03:01
Django Urls
from django.conf import settings
from django.conf.urls import patterns, include, url
from django.contrib.staticfiles.urls import staticfiles_urlpatterns
# from django.contrib import admin
# admin.autodiscover()
urlpatterns = patterns('',
# url(r'^admin/doc/', include('django.contrib.admindocs.urls')),
@hersonls
hersonls / gist:3695466
Created September 11, 2012 02:22
Nginx and Apache configuration for sub-domains
# Nginx
server {
# [...]
server_name *.yourdomain.com;
# [...]
}
@hersonls
hersonls / middleware.py
Created September 11, 2012 02:35
Middleware for django-subdomains
class SubdomainURLRoutingMiddleware(SubdomainMiddleware):
def process_request(self, request):
super(SubdomainURLRoutingMiddleware, self).process_request(request)
subdomain = getattr(request, 'subdomain', False)
if subdomain is not False and subdomain not in settings.SUBDOMAIN_BLACKLIST:
# Here is the trick. I will put at the first rule the users url
# set at the settings, this way, the first page will be the
# user page matched with subdomain.
@hersonls
hersonls / signals_example.py
Created September 30, 2012 17:42
Example: Using signals to send email
# I have not tested, only didactic.
#
# signals.py
#
from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string
def send_notification_mail(sender, instance, raw, using):
context = {}
@hersonls
hersonls / gist:3933060
Created October 22, 2012 18:08
Personal Sublime Text 2 Packages
# Sublime Features
SublimeLinter
ColorPicker
Package Control
# Html
HTMLAttributes
HtmlTidy
# JavaScript
@hersonls
hersonls / generate_secret_key.sh
Last active June 2, 2019 22:00
Django SECRET_KEY command line generator
python -c 'from django.utils.crypto import get_random_string; print "\nSECRET_KEY = \"%s\"\n" % get_random_string(50, "abcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*(-_=+)")'