Skip to content

Instantly share code, notes, and snippets.

View karmadonov's full-sized avatar
🥷

Kirill Karmadonov karmadonov

🥷
View GitHub Profile
@karmadonov
karmadonov / postgres-cheatsheet.md
Created February 3, 2018 14:53 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

Some interesting flags (to see all, use -h):

  • -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)
@karmadonov
karmadonov / min_cost.cc
Last active March 14, 2017 00:06
Minimum cost flow using C++ Lemon library. CapacityScaling implements the capacity scaling version of the successive shortest path algorithm for finding a minimum cost flow amo93networkflows, edmondskarp72theoretical
#include <iostream>
#include <lemon/smart_graph.h>
#include <lemon/lgf_reader.h>
#include <lemon/lgf_writer.h>
#include <lemon/capacity_scaling.h>
using namespace lemon;
int main() {
SmartDigraph g;
@karmadonov
karmadonov / Preferences.sublime-settings
Created December 15, 2012 12:08
My Sublime Settings
{
"color_scheme": "Packages/Color Scheme - Default/GitHub.tmTheme",
"font_face": "SourceCodePro",
"font_size": 13,
"highlight_line": true,
"ignored_packages": [],
"rulers": [79],
"theme": "Soda Light.sublime-theme",
"translate_tabs_to_spaces": true,
"trim_trailing_white_space_on_save": true
@karmadonov
karmadonov / clean.sh
Created September 25, 2012 11:14
Removing files that are not under version control
git clean -df
Cleans the working tree by recursively removing files that are not under version control, starting from the current directory.
@karmadonov
karmadonov / base64.py
Last active January 29, 2018 15:46
Upload base64 file from POST request to Django form
import base64
import cStringIO
from django.core.files.uploadedfile import InMemoryUploadedFile
# ...
if request.POST.get('file') and request.POST.get('name'):
file = cStringIO.StringIO(base64.b64decode(request.POST['file']))
image = InMemoryUploadedFile(file,
field_name='file',
@karmadonov
karmadonov / rand_name.py
Created May 2, 2012 13:06
Python random string generator
from random import choice
import string
chars = string.letters + string.digits # Python 2
chars = string.ascii_letters + string.digits # Python 3
rand_name = lambda x: ''.join(choice(chars) for i in range(x))
>>> rand_name(5)
'Hxm7y'
@karmadonov
karmadonov / Nightbook.yaml
Created January 3, 2012 10:28
Ludovico Einaudi - Nightbook YAML example
title: Nightbook
artist: Ludovico Einaudi
tags: [classical, neoclassical, contemporary classical]
release_date: 2009-09-20
label: Sony Classical
country: United Kingdom
barcode: 028947636397
cover: cover.jpg
files: