Skip to content

Instantly share code, notes, and snippets.

View luzfcb's full-sized avatar

Fábio C. Barrionuevo da Luz luzfcb

View GitHub Profile
@doobeh
doobeh / gist:3188318
Created July 27, 2012 14:27
Installing WeasyPrint on Windows

Installing WeasyPrint on Windows

WeasyPrint converts HTML including images to PDF, it's cross platform but Windows requires a decent amount of massaging to persuade it to work.

To install Pango and Cairo download the [all in one bundle][GTK] of the GTK+ stack and extract the archive to C:\GTK.

You'll need to add the GTK bin folder to your system path so the various

@Miserlou
Miserlou / middleware.py
Created September 6, 2012 01:47
Django Profiler
# Orignal version taken from http://www.djangosnippets.org/snippets/186/
# Original author: udfalkso
# Modified by: Shwagroo Team and Gun.io
import sys
import os
import re
import hotshot, hotshot.stats
import tempfile
import StringIO
@mt3
mt3 / pandas-heroku.md
Created September 8, 2012 23:10 — forked from nicolashery/pandas-heroku.md
Deploy Python app using Pandas on Heroku

Deploy Python app using Pandas on Heroku

2012-09-08

This document explains how to deploy a Python app that uses the Pandas library on Heroku.

Heroku builds Numpy (one of Pandas' requirements) fine. However, when trying to deploy an app with both numpy and pandas in its requirements.txt file (or even just pandas), for some reason it fails

@kennethreitz
kennethreitz / pr.md
Created September 12, 2012 20:56 — forked from piscisaureus/pr.md
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = [email protected]:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

from django.views.generic import ListView
from django.views.generic.edit import FormMixin
from django.db.models import Q
class SearchView(FormMixin, ListView):
template_name_suffix = '_search'
filter_operator = 'contains'
allow_or_operator = False
def get_filter_operator(self):
@luhn
luhn / getter_and_setter.py
Created November 29, 2012 18:35
Using getters and setters with SQLAlchemy
class Table(Base):
id = Column(Integer, primary_key=True)
_name = Column('name', String(24))
@property
def name(self):
return self._name;
@name.setter
def name(self, value):
@amitchhajer
amitchhajer / Count Code lines
Created January 5, 2013 11:08
Count number of code lines in git repository per user
git ls-files -z | xargs -0n1 git blame -w | perl -n -e '/^.*\((.*?)\s*[\d]{4}/; print $1,"\n"' | sort -f | uniq -c | sort -n
@fmasanori
fmasanori / quicksort.py
Last active August 9, 2021 01:41
Quicksort
def quicksort(v):
if len(v) <= 1:
return v
pivot = v[0]
equals = [x for x in v if x == pivot]
smaller = [x for x in v if x < pivot]
higher = [x for x in v if x > pivot]
return quicksort(smaller) + equals + quicksort(higher)
@vdboor
vdboor / jquery.django-inlines.js
Last active November 5, 2019 21:12
jQuery plugin for dynamic Django admin inlines. This script gives more freedom over the HTML layout (in constrast to `inlines.js` from Django), but does require manual binding.
/**
* jQuery plugin for Django inlines
*
* - When a `.js-django-inlines` is present, it will automatically enable this script for it.
* - When `.js-add-form` is missing, an add button will be inserted manually.
* - Make sure a `.js-remove-form` element is present in the HTML.
*
* To customize the behavior, use different class names and manually call $formset.djangoInline().
* This can also be used to manually connect the 'add' and 'delete' buttons.
*
@femmerling
femmerling / authenticate.py
Last active June 18, 2024 10:59
I have to create user authentication using python-ldap. After googling around and trying out stuffs, this is the final code for you to use. Please remember to adjust the user_dn, and base_dn accordingly to the format used in your LDAP server.
# to be able to import ldap run pip install python-ldap
import ldap
if __name__ == "__main__":
ldap_server="x.x.x.x"
username = "someuser"
password= "somepassword"
# the following is the user_dn format provided by the ldap server
user_dn = "uid="+username+",ou=someou,dc=somedc,dc=local"