Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
Using Python's built-in defaultdict we can easily define a tree data structure:
def tree(): return defaultdict(tree)
That's it!
# Elasticsearch Cheatsheet - an overview of commonly used Elasticsearch API commands | |
# cat paths | |
/_cat/allocation | |
/_cat/shards | |
/_cat/shards/{index} | |
/_cat/master | |
/_cat/nodes | |
/_cat/indices | |
/_cat/indices/{index} |
# -*- coding: utf-8 -*- | |
# Parse the numbers of Russian casualties in Ukraine from a news website, save them to CSV files, and plot them. | |
# | |
# Prerequisites: | |
# $ pip install beautifulsoup4==4.10.0 matplotlib==3.4.3 requests==2.26.0 pandas==1.3.4 | |
# | |
# Usage: | |
# $ python3 russian_casualty_parser.py | |
# | |
# Output: |
# ~/.gitconfig | |
[branch] | |
autosetupmerge = true | |
[push] | |
default = current | |
[core] | |
excludesfile = .gitignore |
It appears that Apple somehow broke Python in Mountain Lion, so even with the latest Command Line Tools and Xcode 4.4 virtualenv won't properly work. During virtual environment creation it will try to install easy_install inside /Library hierarchy. So let's give it a quick workaround. Let's install custom python into your $HOME-directory using pythonbrew!
Without the Apple Mac Developer account you won't even see the proper download link for the latest CL Tools and the old one won't work on ML. So here's the link: http://goo.gl/iBTXh. It points towards the Apple website so don't worry.
def attach_foreignkey(objects, field, select_related=None): | |
""" | |
Shortcut method which handles a pythonic LEFT OUTER JOIN. | |
``attach_foreignkey(posts, Post.thread)`` | |
""" | |
field = field.field | |
qs = field.rel.to.objects.filter(pk__in=distinct(getattr(o, field.column) for o in objects)) | |
if select_related: | |
qs = qs.select_related(*select_related) |
""" | |
Script for automated analysis of profiling data in MongoDB, | |
gathered by Mongo with db.setProfilingLevel(1). | |
See <http://www.mongodb.org/display/DOCS/Database+Profiler> | |
TODO: pass collection and database with profiling data in arguments | |
TODO: make thread-safe | |
TODO: handle map-reduce operations | |
""" |
class QuerySetDoubleIteration(Exception): | |
"A QuerySet was iterated over twice, you probably want to list() it." | |
pass | |
# "Skinny" here means we use iterator by default, rather than | |
# ballooning in memory. | |
class SkinnyManager(Manager): | |
def get_query_set(self): | |
return SkinnyQuerySet(self.model, using=self._db) |
#!/bin/sh | |
file="Sublime Text 2 Build ${1} x64.tar.bz2" | |
# Uncomment line below for 32 bit. | |
#file="Sublime Text 2 Build ${1}.tar.bz2" | |
url="http://www.sublimetext.com/${file}" | |
first=0 | |
if [ $(id -u) -ne 0 ] | |
then |
class SQLDebugCommand(object): | |
def __init__(self): | |
from devserver.modules.sql import SQLSummaryModule, SQLRealTimeModule | |
from devserver.logger import GenericLogger | |
from mock import Mock | |
self.modules = [ | |
#SQLRealTimeModule(GenericLogger(SQLRealTimeModule)), | |
SQLSummaryModule(GenericLogger(SQLSummaryModule)), | |
] | |
self.mock_request = Mock() |