Skip to content

Instantly share code, notes, and snippets.

View miikka's full-sized avatar

Miikka Koskinen miikka

View GitHub Profile
#!/bin/sh
# Etsitään tiedostot hakemistosta foo ja siirretään ne hakemistoon bar
find foo -type f -exec mv {} bar \;
# Vaihtoehtoinen tapa, joka lienee nopeampi jos on paljon tiedostoja:
find foo -type f -print0 | xargs -0 -n 25 mv -t bar
# Tiedostot on siirrety pois foosta, poistetaan foo
rm -r foo
#!/usr/bin/env python
import fnmatch
from ftplib import FTP
import os
import sys
class Downloader(object):
destdir = '.'
pattern = '*'
% cabal install hledger-web
Resolving dependencies...
Configuring hledger-web-0.22.1...
Building hledger-web-0.22.1...
Preprocessing library hledger-web-0.22.1...
Application.hs:31:7:
warning: missing terminating ' character [-Winvalid-pp-token]
-- Don't forget to add new modules to your cabal file!
^
var x = cos * sideHexOffset - sin * (vertHexOffest + sideVertHexOffset);
var y = cos * (sideVertHexOffset + vertHexOffest) + sin * sideHexOffset;
@miikka
miikka / git-b
Last active August 8, 2018 07:27
#!/bin/bash
# Intearctively select one of the recent branches and checkout it.
set -e
git rev-parse --is-inside-work-tree >/dev/null
git checkout $(git for-each-ref --sort=-committerdate --format='%(refname:short)' refs/heads/ | fzf -q "$*")
@miikka
miikka / keybase.md
Created February 13, 2015 09:35
Keybase proof

Keybase proof

I hereby claim:

  • I am miikka on github.
  • I am miikka (https://keybase.io/miikka) on keybase.
  • I have a public key whose fingerprint is 0753 C3DA 748E DA91 AAB1 E35E 8005 E0EB BCB7 E306

To claim this, I am signing this object:

@miikka
miikka / pc.py
Last active October 11, 2017 14:45
Python parser combinators
"""A sketch of parser combinators for Python.
I wanted to parse a recursive list of words with Python-like syntax, for
example:
[foo, [bar, baz], quux]
Using an external library would have been too hard and complicated.
Unfortunately this didn't end up being very beautiful, either. Check out the
definition of wordlist(). Ugh.
@miikka
miikka / matcher.py
Created April 4, 2015 22:12
Pattern matching in Python
"""This is a sketch of implementing pattern matching of lists.
"""
from collections import namedtuple
# Destructuring lists
#
# In a destructuring pattern:
#
# * V('foo') matches a value and assigns it to foo
@miikka
miikka / mtr.md
Last active August 29, 2015 14:21
Moralistic Therapeutic Rationalism

Moralistic Therapeutic Rationalism (MTR)

  1. A rational principle exists that ordered the world and governs over human life on earth.
  2. Rationalism wants people to be good, nice, and fair to each other, as taught by LessWrong and by most world religions.
  3. The central goal of life is to be rational and to feel smart about oneself.
  4. Rationalism does not need to be particularly involved in one's life except when rationalism is needed to resolve a problem.
  5. Rational people live forever when the Singularity happens.

See also: http://en.wikipedia.org/wiki/Moralistic_therapeutic_deism

@miikka
miikka / once.py
Created September 23, 2015 14:03
import inspect
DONE_ONCE = set()
def only_once():
"""Use as a generator to run a block only once."""
frame = inspect.stack()[1]
# frame is (frame object, path, line, ...)
key = (frame[1], frame[2])