Skip to content

Instantly share code, notes, and snippets.

View lukmdo's full-sized avatar
:octocat:
loading...

Lukasz Dobrzanski lukmdo

:octocat:
loading...
View GitHub Profile
@lukmdo
lukmdo / mc_a.py
Last active August 29, 2015 14:23
"""
FIND MOST COMMON ELEMENT IN LIST
- what is "most common"
- restrictions
- list properties
- tests?
"""
def solution(items):
@lukmdo
lukmdo / m.py
Last active February 2, 2018 22:09
meta without __metaclass__ (by inheritance)
from __future__ import print_function
from functools import wraps
class Fish(object):
def __new__(cls, *args, **kwargs):
o = super(Fish, cls).__new__(cls, *args, **kwargs)
o.foo_cache = {}
o.type = 'goldfish'
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta http-equiv="Content-Style-Type" content="text/css">
<title></title>
<meta name="Generator" content="Cocoa HTML Writer">
<meta name="CocoaVersion" content="1265.2">
<style type="text/css">
p.p1 {margin: 0.0px 0.0px 0.0px 0.0px; line-height: 22.0px; font: 12.0px 'Lucida Grande'}
@lukmdo
lukmdo / gist:7634956
Last active December 29, 2015 07:19
R multibar plot
library(Hmisc) # summarize
dx = summarize(mtcars$hp, llist(mtcars$cyl, mtcars$gear), sum)
dx = summarize(mtcars$hp, llist(mtcars$cyl, mtcars$gear), mean)
names(dx) = c("cyl", "gear", "hp")
dx.t = xtabs(hp ~ cyl + gear, dx)
barplot(dx.t,
beside=T,
col=rainbow(3),
@lukmdo
lukmdo / README.md
Created November 22, 2013 18:26
coderetreat

Run

python golgame.py
Ctrl + C to stop

There are some options too:

Usage: golgame.py [options]

Options:

@lukmdo
lukmdo / gist:7212129
Last active December 26, 2015 20:49
MacPorts Upgrade Procedure

MacPorts Upgrade Procedure - more

Save the list of installed ports:
port -qv installed > myports.txt
Uninstall all installed ports:
sudo port -f uninstall installed
Clean any partially-completed builds:
sudo port clean all
Get fresh MacPorts-X.Y.Z
@lukmdo
lukmdo / lehmer.py
Last active May 23, 2021 23:39
Permutations by Lehmer codes
"""
Permutations by Lehmer codes (http://en.wikipedia.org/wiki/Lehmer_code)
Inspired by http://stackoverflow.com/a/3241894/212278
Given input sequence
>>> seq = ["A", "B", "C", "D"]
>>> lehmer_code = [2, 1, 0, 0]
>>> int_from_code(lehmer_code)
6
>>> list(lehmer.iter_perm(['A', 'B', 'C']))
@lukmdo
lukmdo / gist:5916389
Created July 3, 2013 08:35
rlcomplete snippet
# http://algorithmicallyrandom.blogspot.it/2009/09/tab-completion-in-python-shell-how-to.html
import rlcompleter
import readline
readline.parse_and_bind("tab: complete")