Skip to content

Instantly share code, notes, and snippets.

View augustomen's full-sized avatar

Augusto Men augustomen

  • Canada
View GitHub Profile
@augustomen
augustomen / lookups.py
Last active December 11, 2015 02:39
WordModelLookup: a Django Selectable lookup that searches anywhere in the field
import operator
from django.db.models import Q
from selectable.base import LookupBase, ModelLookup
# if term is 'foo - bar', the middle '-' is ignored
SEARCH_IGNORED = (',', '.', '-', '/', ';', ':', '=', '\\',)
def split_terms(get_query):
""" This decorator breaks a single string received in the request by a
list of strings.
@augustomen
augustomen / gist:6765090
Created September 30, 2013 15:01
get_template_block() - returns a part of a template
from django.template import loader, loader_tags
def get_template_block(template_name, block_name):
"""Searchs a returns a single block inside a template.
Useful for ajax reloading inside a template.
- template_name can be a filename or a list of filenames.
- block_name is the name of the block to look for:
{% block block_name %}
This function returns a BlockNode instance, which can be rendered to
@augustomen
augustomen / templatetree.py
Created October 20, 2014 18:07
templatetree - builds a inheritance tree of all templates in a Django project or folder
# coding: utf-8
__author__ = "Augusto Men"
__version__ = "$Revision: 0.1 $"
__date__ = "$Date: 2014/09/29 $"
DESCRIPTION = """Builds a tree of template files based on inheritance."""
import os
import re
@augustomen
augustomen / README.md
Last active October 21, 2015 18:56
SQLite3 to MySQL dump converter

Usage:

sqlite3 <sqlite3_filename> .dump | sqlite3-to-mysql.py | mysql <params>

or

sqlite3 <sqlite3_filename> .sch | sqlite3-to-mysql.py | mysql <params>
@augustomen
augustomen / makeword.py
Created February 10, 2016 21:57
Gerador de palavra aleatória
import random
consonants = 'bcdfghjlmnpqrstvxz'
vowels = 'aeiou'
def new_word(syllables=None):
if syllables is None:
syllables = random.randint(2, 5)
result = ''
for i in range(syllables):
#! /usr/bin/env python
import sys
def main():
sys.stdout.write("SET sql_mode='NO_BACKSLASH_ESCAPES';\n")
lines = sys.stdin.read().splitlines()
for line in lines:
sys.stdout.write(process_line(line))
sys.stdout.write('\n')
@augustomen
augustomen / xmltosrt.py
Created February 29, 2016 02:43
Converts a Youtube closed captions xml to srt
#!/usr/bin/python
import re
import sys
from datetime import datetime, timedelta
pattern = re.compile(r'<text start="([\d\.]+)" dur="([\d\.]+)">(.*?)</text>')
with open(sys.argv[1]) as fin:
content = fin.read().decode('utf-8')
dini = datetime(2010, 1, 1)
# -*- coding: utf-8 -*-
import re
import sys
NEWLINE = '\r\n'
TIME_STR = re.compile(r'\d{2}\:\d{2}\:\d{2}[\,\.]\d{0,3}\s*--\>\s*\d{2}\:\d{2}\:\d{2}[\,\.]\d{0,3}')
TAGS_PATTERN = re.compile(r'\<[^\>]*\>')
@augustomen
augustomen / build.gradle
Created June 13, 2018 14:30
Obtain Android versionCode from git commit count
def loadVersionCode() {
def code = 1
new ByteArrayOutputStream().withStream { os ->
exec {
commandLine 'git', 'rev-list', 'HEAD', '--count'
standardOutput = os
}
code = os.toString().toInteger()
}
println "Version Code: $code"
@augustomen
augustomen / fieldset.html
Last active September 24, 2019 13:29
Django Admin Bootstrapped customized fieldset.html that maintains alignment of labels and fields in two-column lines
{% load bootstrapped_goodies_tags %}
<fieldset class="_module _aligned" id="fieldset-{% if stacked_prefix %}{{ stacked_prefix }}-{% endif %}{{ forloop.counter }}" style="background:transparent">
{% if fieldset.name %}
<legend>
{% if 'collapse' in fieldset.classes %}
<a data-toggle="collapse" data-target="#fieldset-{% if stacked_prefix %}{{ stacked_prefix }}-{% endif %}{{ forloop.counter }} .fields">
{{ fieldset.name }}
&nbsp;<span class="btn btn-xs btn-default"><span class="glyphicon glyphglyphicon glyphicon-resize-full"></i></span>
</a>
{% else %}