Skip to content

Instantly share code, notes, and snippets.

View ionatan-israel's full-sized avatar
🏠
Working from home

Jonatan Rodríguez ionatan-israel

🏠
Working from home
View GitHub Profile
"""
Example of mandrill service in python (http://mandrill.com/)
Description of usage in python:
Russian: http://www.lexev.org/2014/send-email-django-project-mandrill-service/
English: http://www.lexev.org/en/2014/send-email-django-project-mandrill-service/
"""
# ======
# Django
/**
* setup JQuery's AJAX methods to setup CSRF token in the request before sending it off.
* http://stackoverflow.com/questions/5100539/django-csrf-check-failing-with-an-ajax-post-request
*/
function getCookie(name)
{
var cookieValue = null;
if (document.cookie && document.cookie != '') {
var cookies = document.cookie.split(';');
@ionatan-israel
ionatan-israel / kill-process.sh
Created December 31, 2014 04:23
A veces el proceso del servidor de desarrollo de Django queda bloqueado. Este script recibe un parámetro (el puerto) por lo regular --> 8000 y elimina el proceso que este escuchando ese puerto.
#!/bin/zsh
lsof -P | grep ':'$1 | awk '{print $2}' | xargs kill -9
@ionatan-israel
ionatan-israel / contains__in.py
Created January 5, 2015 01:59
Snippet Django para buscar diferentes palabras en un mismo campo. Es una pena que no exista 'field__contains__in'
from django.db.models import Q
lista = ['str1', 'str2', 'str3']
q_objects = Q()
for x in lista:
q_objects |= Q(title__contains=x)
queryset = queryset.filter(q_objects)
@ionatan-israel
ionatan-israel / remove_migrations.py
Created January 19, 2015 18:20
Limpiando archivos de migraciones Django.
# -*- coding: utf-8 -*-
__author__ = 'alexdzul'
"""
El script identifica las carpetas llamadas "migrations" dentro de nuestro
proyecto y elimina todos los archivos *.py
omitiendo los __init__.py.
Instrucciones:
=============
@ionatan-israel
ionatan-israel / page.py
Last active August 29, 2015 14:17 — forked from rturowicz/page.py
# admin.py: admin action definition
def make_copy(self, request, queryset):
form = None
if 'apply' in request.POST:
form = CopyPageForm(request.POST)
if form.is_valid():
issue = form.cleaned_data['issue']

Tabs and Windows

Function Shortcut
Previous Tab + Left Arrow
Next Tab + Right Arrow
Go to Tab + Number
Go to Window + Option + Number
Go to Split Pane by Direction + Option + Arrow
Go to Split Pane by Order of Use + ] , + [
@ionatan-israel
ionatan-israel / replace_word.sh
Last active April 3, 2016 19:12
This command will do it (tested on both Mac OS X Lion and Kubuntu Linux).
# Recursively find and replace in files
find . -type f -name '*.js' ! -path "./node_modules/*" -exec sed -i '' s/'old_string'/'new_string'/ {} +
@ionatan-israel
ionatan-israel / wizard.py
Last active August 29, 2015 14:19
Django, Pasando dinamicamente plantillas y formularios a una WizardView.
def get_form_list(request):
form_list = [
("categories", forms.CategoriesForm),
("description", forms.CategoriesForm)]
templates = {
"categories": "categories.html",
"description": "description.html"}
if not request.user.is_authenticated():
form_list.append(("register", forms.CategoriesForm))
templates["register"] = "step-register.html"
# coding=utf-8
import hashlib
from django import forms
from .khipu_settings import USER_ID, USER_KEY
class KhipuPaymentForm(forms.Form):