Skip to content

Instantly share code, notes, and snippets.

View miceno's full-sized avatar

Orestes Sanchez miceno

  • Barcelona, Spain
View GitHub Profile
@MarkMenard
MarkMenard / gist:340526
Created March 22, 2010 21:05
Example Groovy JPA
package models
import javax.persistence.*
@Entity (name="Agreement")
@Table (name="agreement")
@EntityListeners ([QIdSetter.class])
class AgreementJpaImpl extends QIdEntityImpl implements Agreement {
@ManyToOne (targetEntity=PartyJpaImpl.class)
@shazow
shazow / mytypes.py
Created September 24, 2010 04:13
SQLAlchemy Enum type based on Integer indices, for better storage efficiency over the default Enum type.
"""
SQLAlchemy Enum type based on Integer indices.
"""
from sqlalchemy import types
class Enum(types.TypeDecorator):
impl = types.Integer
def __init__(self, value_map, strict=True, *args, **kw):
"""Emulate Enum type with integer-based indexing.
@geon
geon / ellipsis.htm
Created November 20, 2010 21:07
Textshortening and ellipsis with only CSS
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>Textshortening and ellipsis with only CSS</title>
<meta http-equiv="content-type" content="text/html;charset=utf-8" />
<style type="text/css">
p {
width: 220px;
line-height: 18px;
@jpertino
jpertino / gist:731105
Created December 6, 2010 22:30
groovy xml string generation
def referenceClosure = {
html {
body {
h1 "hello"
}
}
}
def markupBuilder(closure) {
@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
@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)
});
@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')){
@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/
@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
@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