Skip to content

Instantly share code, notes, and snippets.

View kmmbvnr's full-sized avatar
💭
#StopPutin #StopWar

Mikhail Podgurskiy kmmbvnr

💭
#StopPutin #StopWar
View GitHub Profile
@kmike
kmike / asserts.py
Created September 10, 2010 12:24
assertNumQueries decorator and context manager
import functools
import sys
import re
from django.conf import settings
from django.db import connection
def shrink_select(sql):
return re.sub("^SELECT(.+)FROM", "SELECT .. FROM", sql)
def shrink_update(sql):
@uniomni
uniomni / gist:779194
Created January 14, 2011 04:56
Geoserver REST command examples

REST commands, generated by Risk-in-a-Box and known to work

Upload shapefile + associated style. Then activate style and make it default.

PUT -H "Content-type: application/zip" "http://localhost:8080/geoserver/rest/workspaces/exposure/datastores/AIBEP_schools/file.shp" --data-binary "@AIBEP_schools.zip"
POST -H "Content-type: text/xml" "http://localhost:8080/geoserver/rest/styles" --data-ascii "<style>AIBEP_schoolsAIBEP_schools.sld</style>"
PUT -H "Content-type: application/vnd.ogc.sld+xml" "http://localhost:8080/geoserver/rest/styles/AIBEP_schools" --data-binary "@AIBEP_schools.sld"
PUT -H "Content-type: text/xml" "http://localhost:8080/geoserver/rest/layers/AIBEP_schools" --data-ascii "AIBEP_schoolstrue"

@kennethreitz
kennethreitz / 0_urllib2.py
Created May 16, 2011 00:17
urllib2 vs requests
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import urllib2
gh_url = 'https://api.github.com'
req = urllib2.Request(gh_url)
password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
@NetAngels
NetAngels / runner.py
Created June 24, 2011 04:21
Extremely fast Django test runner
# -*- coding: utf-8 -*-
"""
Extremely fast Django test runner, based on the idea that your database schema
and fixtures are changed much more seldom that your code and tests. All you
need is to make sure that your "quickstart.sqlite" database file is always up
to date.
BEWARE: Don't run this test runner on production server. It assumes that you
use only one database configured as "default", and its db engine is SQLite.
Otherwise your tests can eat your data!
@Uninen
Uninen / dbdamnit.py
Created July 1, 2011 22:40
DbDamnit -- Automagic db configuration for Django
# -*- coding: utf-8 -*-
"""
dbdamnit.py is a management command for creating and configuring MySQL
database settings automagically for Your Django project. This code
uses convention over configuration, feel free to modify and use it
for your own projects as You like.
Happy hacking! :)
- @uninen
@dpwiz
dpwiz / utils.py
Created July 15, 2011 07:49
xls stats from db
"""More specific helpers."""
from django.conf import settings
from django.core.mail.message import EmailMessage
from datetime import date, timedelta
import os
from core.extdb import ExtDB
@taavi223
taavi223 / .pythonrc.py
Last active April 19, 2024 13:37
.pythonrc.py
"""
This file is executed when the Python interactive shell is started if
$PYTHONSTARTUP is in your environment and points to this file. It's just
regular Python commands, so do what you will. Your ~/.inputrc file can greatly
complement this file.
Modified from sontek's dotfiles repo on github:
https://github.com/sontek/dotfiles
"""
@eykd
eykd / .gitignore
Created January 19, 2012 04:37
Full stack BDD testing with Behave+Mechanize+Django
*.pyc
bin/
include/
lib/
@hrldcpr
hrldcpr / tree.md
Last active May 1, 2024 00:11
one-line tree in python

One-line Tree in Python

Using Python's built-in defaultdict we can easily define a tree data structure:

def tree(): return defaultdict(tree)

That's it!

@oodavid
oodavid / README.md
Created March 26, 2012 17:05
Backup MySQL to Amazon S3

Backup MySQL to Amazon S3

This is a simple way to backup your MySQL tables to Amazon S3 for a nightly backup - this is all to be done on your server :-)

Sister Document - Restore MySQL from Amazon S3 - read that next

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc