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 / gist:5105021
Last active October 15, 2017 06:12
intrigued by python signal capabilities [async]
"""Got intriged with signal capabilities (http://docs.python.org/2/library/signal.html)
I define simple ``asyncall`` function thats takes numner seconds and deffered function (similar window.setTimeout(n_ms, func/code_literal))
>>> asyncall(5, lambda *args: say('A'))
>>> asyncall(10, lambda *args: say('B'))
>>> asyncall(2, lambda *args: say('C'))
C
A
B
@lukmdo
lukmdo / gist:5564189
Last active December 17, 2015 06:19
Command line shortcuts
  • ^A move cursonr to Begin of line
  • ^E move cursonr to End of line
  • ^D delete current char
  • ^W delete word left to current char
  • ^U delete everything left to current char
  • ^K delete everything right to current char
  • ^T transpose
  • ^F (right arrow) move cursonr to Next char
  • ^B (left arrow) move cursonr to Prev char
  • ^P bring Prev history cmd
@lukmdo
lukmdo / ybisect.py
Last active December 18, 2015 22:29
Bisect based formula testing
"""Bisect based formula testing.
Implements bisect_lt, bisect_le, bisect_ge, bisect_gt from scratch using `yfun`
# http://code.google.com/codejam/contest/2418487/dashboard
>>> r, t = 10**16, 10**18
>>> yfun = lambda x: (2*(10**16) + (2*x) -1) * x
Given bisect_le(yfun, y, range(N))
>>> bisect_le(yfun, t, range(t))
49
@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")
@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: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 / 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: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),
<!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'}