Skip to content

Instantly share code, notes, and snippets.

@jmcnamara
jmcnamara / bench_excel_writers.py
Last active Dec 11, 2020
Benchmark of several Python Excel writing modules
View bench_excel_writers.py
##############################################################################
#
# Simple Python program to benchmark several Python Excel writing modules.
#
# python bench_excel_writers.py [num_rows] [num_cols]
#
#
import sys
from time import clock
@magopian
magopian / fix_permissions.py
Created Nov 19, 2013
Django admin command to "fix permissions" (create them properly for proxy models). This is needed because of the following bug in Django (not fixed as of 1.6): https://code.djangoproject.com/ticket/11154
View fix_permissions.py
# -*- coding: utf-8 -*-
"""Add permissions for proxy model.
This is needed because of the bug https://code.djangoproject.com/ticket/11154
in Django (as of 1.6, it's not fixed).
When a permission is created for a proxy model, it actually creates if for it's
base model app_label (eg: for "article" instead of "about", for the About proxy
model).
@eerien
eerien / forms.py
Last active Sep 6, 2020
Comma Separated Values Form Field for Django. There are CommaSeparatedCharField, CommaSeparatedIntegerField.
View forms.py
from django import forms
from django.core import validators
from django.core.exceptions import ValidationError
class MinLengthValidator(validators.MinLengthValidator):
message = 'Ensure this value has at least %(limit_value)d elements (it has %(show_value)d).'
class MaxLengthValidator(validators.MaxLengthValidator):
message = 'Ensure this value has at most %(limit_value)d elements (it has %(show_value)d).'
@rturowicz
rturowicz / page.py
Last active Dec 19, 2018
django - intermediate admin page
View page.py
# admin.py: admin action definition
def make_copy(self, request, queryset):
form = None
if 'apply' in request.POST:
form = CopyPageForm(request.POST)
if form.is_valid():
issue = form.cleaned_data['issue']
@emil2k
emil2k / Locator.java
Last active Oct 13, 2020
Android utility class for getting device location using various methods. Depends on `Connectivity` class found here: https://gist.github.com/emil2k/5130324
View Locator.java
/*
* Copyright (c) 2017 Emil Davtyan
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
@perrygeo
perrygeo / django_model_graph.sh
Created Apr 13, 2013
Generate UML diagram of django app models
View django_model_graph.sh
apt-get install python-pygraphviz
pip install django-extensions
# add 'django_extensions' to INSTALLED_APPS in settings.py
python manage.py graph_models trees -o test.png
@mattmcc
mattmcc / models.py
Created Mar 27, 2013
Quick & dirty "read-only" model for using SQL views
View models.py
class ViewManager(models.Manager):
def bulk_create(self, *args, **kwargs):
raise NotImplementedError
def create(self, *args, **kwargs):
raise NotImplementedError
def get_or_create(self, *args, **kwargs):
raise NotImplementedError
@strathmeyer
strathmeyer / gist:4990173
Created Feb 19, 2013
Improve OSX Bluetooth quality
View gist:4990173
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Max (editable)" 80
defaults write com.apple.BluetoothAudioAgent "Apple Bitpool Min (editable)" 48
defaults write com.apple.BluetoothAudioAgent "Apple Initial Bitpool (editable)" 40
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool" 48
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Max" 53
defaults write com.apple.BluetoothAudioAgent "Negotiated Bitpool Min" 48
defaults write com.apple.BluetoothAudioAgent "Stream - Flush Ring on Packet Drop (editable)" 30
defaults write com.apple.BluetoothAudioAgent "Stream - Max Outstanding Packets (editable)" 15
defaults write com.apple.BluetoothAudioAgent "Stream Resume Delay" "0.75"
@gonzalo-bulnes
gonzalo-bulnes / comunas.json
Last active May 14, 2021
Comunas de Chile (seed Ruby on Rails, JSON) - (see also https://github.com/gonzalo-bulnes/chilean_cities)
View comunas.json
[
{
"name": "Arica",
"code": "15101",
"provincia": "Arica",
"region": "Arica y Parinacota",
"region_number": "XV",
"region_iso_3166_2": "CL-AP"
},
{
@bunkat
bunkat / index.html
Created Apr 8, 2012
Timeline using d3.js
View index.html
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Chronological Diagram of Asia</title>
<script type="text/javascript" src="http://mbostock.github.com/d3/d3.v2.js"></script>
<style type="text/css">
.chart {
shape-rendering: crispEdges;
}