Skip to content

Instantly share code, notes, and snippets.

@jjdelc
jjdelc / list_filter_collapse.js
Created May 22, 2011 08:56
Collapse list_filter in Django admin
;(function($){
ListFilterCollapsePrototype = {
bindToggle: function(){
var that = this;
this.$filterEl.click(function(){
that.$filterList.slideToggle();
});
},
init: function(filterEl) {
this.$filterEl = $(filterEl).css('cursor', 'pointer');
@fudomunro
fudomunro / dict_format.py
Created March 9, 2012 14:51
Recursively format a dictionary of strings
def dict_format(original, **kwargs):
"""Recursively format the values in *original* with *kwargs*.
>>> sample = {"key": "{value}", "sub-dict": {"sub-key": "sub-{value}"}}
>>> dict_format(sample, value="Bob") == \
{'key': 'Bob', 'sub-dict': {'sub-key': 'sub-Bob'}}
True
"""
new = {}
for key, value in original.items():
if type(value) == type({}):
@baali
baali / dlAttachments.py
Created May 8, 2012 08:32
Python script to download all gmail attachments.
# Something in lines of http://stackoverflow.com/questions/348630/how-can-i-download-all-emails-with-attachments-from-gmail
# Make sure you have IMAP enabled in your gmail settings.
# Right now it won't download same file name twice even if their contents are different.
import email
import getpass, imaplib
import os
import sys
detach_dir = '.'
@ChrisBeaumont
ChrisBeaumont / custom.css
Last active June 22, 2022 15:20
Demystifying Python Descriptors
<style>
@font-face {
font-family: "Computer Modern";
src: url('http://mirrors.ctan.org/fonts/cm-unicode/fonts/otf/cmunss.otf');
}
div.cell{
width:800px;
margin-left:16% !important;
margin-right:auto;
}
@cassus
cassus / admin.py
Last active July 23, 2024 04:43
Django admin action as row button
class MyAdmin(admin.ModelAdmin):
list_display = (..., 'actions_html')
def actions_html(self, obj):
return format_html('<button class="btn" type="button" onclick="activate_and_send_email({pk})">Activate and send email</button>', pk=obj.pk)
actions_html.allow_tags = True
actions_html.short_description = "Actions"
@barkady
barkady / HP_ALM_python
Last active May 22, 2024 07:53
HP ALM python RESTful client
# -*- coding: utf-8 -*-
__author__ = 'Arkady.Babaev'
import requests
import xml.etree.ElementTree as ET
class ALMUrl:
def __init__(self, ip, port, domain, project):
self.__base = u'http://' + ip + u':' + port + u'/qcbin'
self.__auth = self.__base + u'/authentication-point/authenticate'
@Kartones
Kartones / postgres-cheatsheet.md
Last active July 25, 2024 09:09
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h or --help depending on your psql version):

  • -E: will describe the underlaying queries of the \ commands (cool for learning!)
  • -l: psql will list all databases and then exit (useful if the user you connect with doesn't has a default database, like at AWS RDS)
@inirudebwoy
inirudebwoy / 0001_createsuperuser.py
Created March 13, 2015 12:18
Django 1.7+ migration for creating superuser
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations
from django.contrib.auth.admin import User
def create_superuser(apps, schema_editor):
superuser = User()
superuser.is_active = True
@evantoli
evantoli / GitConfigHttpProxy.md
Last active July 29, 2024 08:05
Configure Git to use a proxy

Configure Git to use a proxy

In Brief

You may need to configure a proxy server if you're having trouble cloning or fetching from a remote repository or getting an error like unable to access '...' Couldn't resolve host '...'.

Consider something like:

@danni
danni / fields.py
Created March 8, 2016 08:52
Multi Choice Django Array Field
from django import forms
from django.contrib.postgres.fields import ArrayField
class ChoiceArrayField(ArrayField):
"""
A field that allows us to store an array of choices.
Uses Django 1.9's postgres ArrayField
and a MultipleChoiceField for its formfield.