Skip to content

Instantly share code, notes, and snippets.

View sputnikus's full-sized avatar

Martin Putniorz sputnikus

  • Freelance
  • Brno, Czech Republic
View GitHub Profile
@sputnikus
sputnikus / hstore_en.md
Last active December 29, 2015 15:29
PyVo 28.11.2013 Lightning Eng version

hstore

Postgres

create extension hstore;

Key/value inside db column, keys and values are string-only

k => v

foo => bar, baz => whatever

@sputnikus
sputnikus / dupla_dicts.py
Created December 6, 2012 19:57
Eliminate duplicate dicts from list
# dupla_list = list full of duplicates
seen = set()
clean_list = []
for item in dupla_list:
props = tuple(item.items())
if props not in seen:
seen.add(props)
clean_list.append(item)
@sputnikus
sputnikus / sort_dates.py
Created November 27, 2012 12:49
How to sort list of dates in format '13 July 2011'
>>> import time
>>> format = '%d %B %Y'
>>> sort_dates = lambda y: sorted(y, key=lambda x: int(time.mktime(time.strptime(x, format))))
>>> dates = ['13 July 2011', '13 August 2011', '3 October 2010', '13 July 2012']
>>> sort_dates(dates)
['3 October 2010', '13 July 2011', '13 August 2011', '13 July 2012']
@sputnikus
sputnikus / scrub.py
Created October 28, 2012 19:50
Twitter list members stats
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import csv
from tweepy import Cursor
from tweepy import api
def run():
@sputnikus
sputnikus / README.md
Created September 19, 2012 08:01 — forked from agnoster/README.md
My ZSH Theme

agnoster.zsh-theme

A ZSH theme optimized for people who use:

  • Solarized
  • Git
  • Unicode-compatible fonts and terminals (I use iTerm2 + Menlo)

Compatibility

@sputnikus
sputnikus / fib.py
Created November 22, 2011 15:40
Speed kills
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import time
from math import sqrt
def fibonacci(n):
root5 = sqrt(5)
phi = 0.5 + root5 / 2
@sputnikus
sputnikus / egg_info_error.sh
Created November 21, 2011 13:14
Something wrong is going on...
λ ~/aur/requests-0.8.2/ python2 setup.py egg_info
/usr/lib/python2.7/distutils/dist.py:267: UserWarning: Unknown distribution option: 'install_requires'
warnings.warn(msg)
usage: setup.py [global_opts] cmd1 [cmd1_opts] [cmd2 [cmd2_opts] ...]
or: setup.py --help [cmd1 cmd2 ...]
or: setup.py --help-commands
or: setup.py cmd --help
error: invalid command 'egg_info'
λ ~/ uname -a
@sputnikus
sputnikus / simple_as_hell.py
Created November 7, 2011 18:10
SOAP in Python - examples
import logging
from rpclib.application import Application
from rpclib.decorator import srpc
from rpclib.service import ServiceBase
from rpclib.model.primitive import String
from rpclib.model.primitive import Integer
from rpclib.model.complex import Iterable
from rpclib.interface.wsdl import Wsdl11
from rpclib.protocol.soap import Soap11
@sputnikus
sputnikus / matrix_multiply.py
Created November 6, 2011 23:20
Too lazy for serious math...
from pprint import pprint
def zero(m, n):
new_matrix = [[0 for row in range(n)] for col in range(m)]
return new_matrix
def mult(matrix1, matrix2):
if len(matrix1[0]) != len(matrix2):
@sputnikus
sputnikus / about.md
Created August 10, 2011 14:22 — forked from blaix/about.md
Programming Achievements: How to Level Up as a Developer

Programming Achievements: How to Level Up as a Developer

  1. Select a particular experience to pursue.
  2. Pursue that experience to completion. (Achievement unlocked!)
  3. Reflect on that experience. Really soak it in. Maybe a blog post would be in order?
  4. Return to Step 1, this time selecting a new experience.

This gist is a fork of the gist from this blog post.