Skip to content

Instantly share code, notes, and snippets.

View cauethenorio's full-sized avatar
🎯
Focusing

Cauê Thenório cauethenorio

🎯
Focusing
View GitHub Profile
@cauethenorio
cauethenorio / i18n_routing.py
Created February 13, 2013 20:56
Django snippet to make Django do not create URL language prefix for the main language (settings.LANGUAGE_CODE) Usage info in snippet docstring.
# coding: utf-8
"""
Cauê Thenório - cauelt(at)gmail.com
This snippet makes Django do not create URL languages prefix (i.e. /en/)
for the default language (settings.LANGUAGE_CODE).
It also provides a middleware that activates the language based only on the URL.
This middleware ignores user session data, cookie and 'Accept-Language' HTTP header.
# coding: utf8
import bdb
import sys
# borrowed from: https://gist.github.com/rctay/3169104
def info(type, value, tb):
if (hasattr(sys, 'ps1')
or not sys.stdin.isatty()
@cauethenorio
cauethenorio / free-folha.js
Created October 13, 2014 19:46
Desbloqueador de matérias da folha
javascript:$("> span",$("body").attr("style","")).remove();for(var m=setTimeout(function(){},0),i=0;m>i;i++)clearTimeout(i);
@cauethenorio
cauethenorio / save-n-restore-files-mtime.py
Created December 13, 2014 22:25
save and restore mtime from all files in a dir
#! /usr/bin/env python
# coding: utf-8
import hashlib
from os import listdir, path, utime
import time
import pickle
import sys
@cauethenorio
cauethenorio / angular-request-fake-latency.js
Last active August 29, 2015 14:11
Angular app configuration to add 1s fake latency to xhr json requests
app.config(function ($httpProvider) {
$httpProvider.interceptors.push(
function ($q, $timeout) {
return {
'response': function (response) {
var deferred = $q.defer();
if (response.headers('content-type') == 'application/json')
$timeout(function() {deferred.resolve(response);}, 1000);
else
@cauethenorio
cauethenorio / dni_peru.py
Created March 25, 2015 01:50
estudo validação DNI peruano
def dni_validator_1(dni):
multiplos = '32765432'
numbers = list('67890112345')
letters = list('KABCDEFGHIJ')
dni = list(dni)
control = dni.pop()
suma = sum(int(char) * int(mul) for mul, char in zip(multiplos, dni))
@cauethenorio
cauethenorio / php-array-to-dict.py
Last active August 29, 2015 14:21
converter inputs de array (PHP) para um dict python
# coding: utf8
import re
from functools import reduce
def merge_dicts(*dicts):
# http://stackoverflow.com/questions/7204805/dictionaries-of-dictionaries-merge
if not reduce(lambda x, y: isinstance(y, dict) and x, dicts, True):
raise TypeError("Object in *dicts not of type dict")
@cauethenorio
cauethenorio / django_admin_dynamic_lookup_mixin.py
Created January 12, 2016 03:35
A mixin to add support to related attributes like 'book_author' in django ModelAdmin list_display field
class DynamicLookupMixin(object):
'''
A mixin to add support to related attributes like
'book_author' in django ModelAdmin list_display field
creating callables on the fly
'''
def __getattr__(self, attr):
if ('__' in attr
and not attr.startswith('_')
@cauethenorio
cauethenorio / clean-php.sh
Created January 29, 2016 11:10
recusively remove back door malicious code from infected php files
# Remove linha com codigo malicioso de arquivos php hackeados (sed para linux)
find . -name "*.php" -exec sed -i '1s/^<?php if(!isset(\$GLOBALS\["\\x61\\156\\x75\\156\\x61.*-1; ?>//' {} \;
# Remove linha com codigo malicioso de arquivos php hackeados (sed para mac)
find . -name "*.php" -exec sed -i '1s/^<\?php if(!isset(\$GLOBALS\["\\\x61\\\156\\\x75\\\156\\\x61.*-1; \?>//' {} \;
@cauethenorio
cauethenorio / WhatsApp Web Send Sad Emoji
Last active November 8, 2016 15:18 — forked from rootux/WhatsApp Web Send Random Heart
Just a simple WhatsApp Web Heart Sender
/*
Simple WhatsApp Web Spam Bot Originally written by Pablode. Modified by Gal Bracha.
Use with love <3. Do not act reckless.
====================================================================================
DISCLAIMER: I do not take any responsibility for any damage caused with this script.
WhatsApp might be able identify script users if this becomes a problem. Do only use
this if you are aware of the consquences.
====================================================================================
Usage: Copy all of this script (Ctrl+A, Ctrl+C). Add a new Bookmark. In the URL section,
write "javascript:" and paste (Ctrl+V) this script. Visit WhatsApp Web, select your