Skip to content

Instantly share code, notes, and snippets.

@YuriyGuts
YuriyGuts / russian_casualty_parser.py
Last active September 22, 2023 14:04
Parse the numbers of Russian casualties in Ukraine from a news website, save them to CSV files, and plot them
# -*- 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:
@stephen-puiszis
stephen-puiszis / elasticsearch-cheatsheet.txt
Last active March 14, 2024 10:32
Elasticsearch Cheatsheet - An Overview of Commonly Used Elasticsearch API Endpoints and What They Do
# 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}
@thesharp
thesharp / ML, Python and virtualenv.md
Created July 25, 2012 22:56
Quick virtualenv fix on Mountain Lion

Quick virtualenv fix on Mountain Lion

Overview

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!

Installing proper Command Line Tools

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.

@hrldcpr
hrldcpr / tree.md
Last active April 26, 2024 08:53
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!

@sergray
sergray / mongolyze.py
Created February 21, 2012 19:41
Python script for automated analysis of slow queries in mongodb
"""
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
"""
@deepakdodo
deepakdodo / ai-class.py
Created October 12, 2011 20:31
Download lecture videos of ai-class (with Subtitles) (Stanford)
#!/usr/bin/env python
# -*- coding: utf-8 -*-
__author__ = "Deepak.G.R."
__license__ = 'Public Domain'
"""
usage:
Go to command line and type
python ai-class.py "topic-name"
@tomster
tomster / .gitconfig
Created September 25, 2011 11:48
An example git configuration including convenience aliases, some saner default behavior, a neat shell prompt and tab completion that can display the name of the tracking remote
# ~/.gitconfig
[branch]
autosetupmerge = true
[push]
default = current
[core]
excludesfile = .gitignore
@uhnomoli
uhnomoli / subl-upd
Created March 30, 2011 10:56
A Sublime Text 2 update script for Linux.
#!/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
@sergray
sergray / get_jobs.py
Created March 14, 2011 13:38
Tracing SQL queries of Django Command.handle with trace_sql decorator
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()
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)