Skip to content

Instantly share code, notes, and snippets.

View miceno's full-sized avatar

Orestes Sanchez miceno

  • Barcelona, Spain
View GitHub Profile
@oryon-dominik
oryon-dominik / decorators_debug_db_queries.py
Last active November 14, 2023 08:35
Decorator for debugging Django database queries
import time
import functools
import logging
from django.db import connection, reset_queries
log = logging.getLogger("django")
@jaantollander
jaantollander / decorator.py
Last active December 30, 2023 21:50
Template for Python decorator function and class
import functools
def decorator(function):
"""A general decorator function"""
@functools.wraps(function)
def wrapper(*args, **kwargs):
# Write decorator function logic here
# Before function call
@antfu
antfu / sqlchemy_declarative_base_mixin.py
Created September 2, 2016 10:08
[Python|SqlAlchemy] as_dict for SqlAlchemy declarative base
from sqlalchemy.ext.declarative import declarative_base
class Mixin:
def as_dict(self):
return {c.name: getattr(self, c.name) for c in self.__table__.columns}
def as_clear_dict(self):
_dict = {}
for c in self.__table__.columns:
if c.foreign_keys:
continue
@bmihelac
bmihelac / import.py
Created September 30, 2015 08:34
Import management command for django-import-export
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import mimetypes
from optparse import make_option
from django.utils.encoding import force_text
from django.utils.translation import ugettext as _
from django.core.management.base import BaseCommand
@berlotto
berlotto / app.py
Created August 21, 2013 14:16
Slugify function to use in Flask (Python)
_slugify_strip_re = re.compile(r'[^\w\s-]')
_slugify_hyphenate_re = re.compile(r'[-\s]+')
def slugify(value):
"""
Normalizes string, converts to lowercase, removes non-alpha characters,
and converts spaces to hyphens.
From Django's "django/template/defaultfilters.py".
"""
import unicodedata
@akprasad
akprasad / flask_admin_enum.py
Last active June 12, 2018 23:30
Adds flask-admin support for the SQLAlchemy "Enum Recipe" on zzzeek's blog (http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/).
# -*- coding: utf-8 -*-
"""
flask-admin and "The Enum Recipe"
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Adds flask-admin support for the enum recipe on zzzeek's blog_.
This code is specific to SQLAlchemy.
.. _blog http://techspot.zzzeek.org/2011/01/14/the-enum-recipe/
@raul
raul / mediahint.js
Last active January 29, 2016 20:12
I like mediahint.com's extension but it relies on this external pac file hosted at https://mediahint.com/default.pac If mediahint.com gets compromised my whole navigation could get proxied without noticing. I'll modify the installed extension (under `~/Library/Application Support/Google/Chrome/Default/Extensions/...` in my Mac) to use a local ve…
function FindProxyForURL(url, host){
var myip = myIpAddress();
var ipbits = myip.split(".");
var myseg = parseInt(ipbits[3]);
if(myseg == Math.floor(myseg/2)*2){
proxy = 'PROXY 165.225.131.153:80; PROXY 165.225.130.193:80';
} else {
proxy = 'PROXY 165.225.130.193:80; PROXY 165.225.131.153:80';
}
if((host == 'localhost')||(shExpMatch(host, 'localhost.*'))||(shExpMatch(host, '*.local'))||(host == '127.0.0.1')){
@tjarratt
tjarratt / ie8-leaflet-projection-bug
Created August 10, 2011 23:23
standalone leaflet projection image overlay IE8
<html>
<head>
<script src="./leaflet.js"></script>
<script>
window.onload = function() {
var myCrs = L.Util.extend({}, L.CRS, {
projection: L.Projection.LonLat,
transformation: new L.Transformation(1, 0, 1, 0)
});
@esperlu
esperlu / mysql2sqlite.sh
Created April 27, 2011 05:46
MySQL to Sqlite converter
#!/bin/sh
# Converts a mysqldump file into a Sqlite 3 compatible file. It also extracts the MySQL `KEY xxxxx` from the
# CREATE block and create them in separate commands _after_ all the INSERTs.
# Awk is choosen because it's fast and portable. You can use gawk, original awk or even the lightning fast mawk.
# The mysqldump file is traversed only once.
# Usage: $ ./mysql2sqlite mysqldump-opts db-name | sqlite3 database.sqlite
# Example: $ ./mysql2sqlite --no-data -u root -pMySecretPassWord myDbase | sqlite3 database.sqlite
@jpertino
jpertino / gist:731105
Created December 6, 2010 22:30
groovy xml string generation
def referenceClosure = {
html {
body {
h1 "hello"
}
}
}
def markupBuilder(closure) {