Skip to content

Instantly share code, notes, and snippets.

View telendt's full-sized avatar
🔧
solving one problem at a time

Tomasz Elendt telendt

🔧
solving one problem at a time
View GitHub Profile
@telendt
telendt / gist:607038
Created October 1, 2010 23:08
print currency exchange rate table in a shell (Polish only)
#!/usr/bin/env bash
(echo 'NAZWA WALUTY|PRZELICZNIK|KOD WALUTY|KURS ŚREDNI'; curl -s --compressed "http://www.nbp.pl/kursy/xml/`curl -s --compressed 'http://www.nbp.pl/kursy/xml/dir.txt' | tr -d '\r' | grep '^a' | sort -k1.6n | tail -1`.xml" | sed -e '/<\?xml.*?\?>/d' | iconv -f CP1250 | xml2 | grep -E 'nazwa_waluty|przelicznik|kod_waluty|kurs_sredni' | cut -d= -f 2- | sed -e 'N;N;N;s/\n/|/g' | sort -t '|' -k 3) | column -tx -s "|"
@telendt
telendt / gist:607454
Created October 2, 2010 08:28
html_entity_decode in Python
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import htmlentitydefs
import re
entity_re = re.compile(r'&(%s|#(\d{1,5}|[xX]([\da-fA-F]{1,4})));' % '|'.join(
htmlentitydefs.name2codepoint.keys()))
@telendt
telendt / xml_pretty.sh
Created December 12, 2010 11:51
XML pretty printer (reformats and highlights xml tagsoup)
alias xml_pretty='xmllint --format - | pygmentize -f terminal256 -l xml -O "encoding=utf-8"'
@telendt
telendt / pip_upgrade_all.sh
Created December 12, 2010 11:56
Upgrades all installed python modules using pip
(echo pip; pip freeze | awk 'BEGIN{FS="=="}{print $1}') | xargs sudo pip install -U
@telendt
telendt / JSONH.py
Created November 29, 2011 09:21
JSONH.py
import operator
import json
class JSONHEncoder(json.JSONEncoder):
def iterencode(self, o, *args, **kwargs):
if type(o) in (list, tuple) and len(o) and type(o[0]) is dict:
d = o[0]
keys = d.keys()
values = operator.itemgetter(*keys)
@telendt
telendt / stderr.txt
Created January 23, 2012 18:38
vagrant 0.9.2
INFO vagrant: `vagrant` invoked: ["up"]
DEBUG vagrant: Creating Vagrant environment
INFO environment: Environment initialized (#<Vagrant::Environment:0x1014f9988>)
INFO environment: - cwd: /Volumes/home/elus/Projects/archives/olympus
INFO environment: Home path: /Volumes/home/elus/.vagrant.d
DEBUG vagrant: Loading environment
INFO environment: Loading configuration...
DEBUG loader: Set :default = "/opt/local/lib/ruby/gems/1.8/gems/vagrant-0.9.2/config/default.rb"
DEBUG loader: Populating proc cache for "/opt/local/lib/ruby/gems/1.8/gems/vagrant-0.9.2/config/default.rb"
@telendt
telendt / gist:1972797
Created March 4, 2012 12:31
multiprocess zgrep
$ time find /opt/local/share/emacs/23.4/lisp/ -type f -name \*.gz -exec zgrep --color=yes -H -n -e "conf-mode" {} \;
real 0m12.239s
user 0m7.327s
sys 0m6.804s
$ time find /opt/local/share/emacs/23.4/lisp/ -type f -name \*.gz -exec zgrep --color=yes -H -n -e "conf-mode" {} +
real 0m8.574s
user 0m4.950s
sys 0m5.995s
@telendt
telendt / gist:2357273
Created April 11, 2012 05:56
get_prime
#include <stdio.h>
#include <assert.h>
#include <stdlib.h>
#include <errno.h>
#include <stdbool.h>
#include <math.h>
void die(const char *message)
{
if (errno) {
function uuid4() {
var r = Math.random,
p = "0000000",
n = 0x100000000,
a = (r() * n >>> 0).toString(16),
b = ((r() * n & 0xffff4fff | 0x4000) >>> 0).toString(16),
c = ((r() * n & 0xbfffffff | 0x80000000 ) >>> 0).toString(16),
d = (r() * n >>> 0).toString(16);
if (a.length < 8) {
a = (p + a).slice(-8);
@telendt
telendt / gist:3752529
Created September 19, 2012 21:49
Regex Tuesday Challenge
http://callumacrae.github.com/regex-tuesday/challenge1.html?find=%2F%5Cb(%5CS%2B)(%5Cs)(%5C1)%5Cb%2Fgi&replace=%241%242%3Cstrong%3E%243%3C%2Fstrong%3E
# TODO: complete hsl(a)
http://callumacrae.github.com/regex-tuesday/challenge2.html?find=%2F%5E(%3F%3A%23(%5B%5Cda-f%5D%7B1%2C2%7D)%5C1%5C1%7Crgb%5C(%5Cs*0*%3F(%5Cd%2B(%3F%3A%5C.%5Cd%2B)%3F%25%3F)%2C%5Cs*0*%5C2%2C%5Cs*0*%5C2%5Cs*%5C)%7Crgba%5C(%5Cs*0*%3F(%5Cd%2B(%3F%3A%5C.%5Cd%2B)%3F)%2C%5Cs*0*%5C3%2C%5Cs*0*%5C3%5C%2C%5Cs*%5C0*(%3F%3A0(%3F%3A%5C.%5Cd%2B)%3F%7C1)%5Cs*%5C)%7Crgba%5C(%5Cs*0*%3F(%5Cd%2B%25)%2C%5Cs*0*%5C4%2C%5Cs*0*%5C4%5C%2C%5Cs*%5C0*(%5Cd%2B%25)%5Cs*%5C))%24%2Fi
http://callumacrae.github.com/regex-tuesday/challenge3.html?find=%2F%5E(1%5Cd%7B3%7D%7C20(0%5Cd%7C1%5B0-2%5D))%5C%2F(0%5B1-9%5D%7C1%5B0-2%5D)%5C%2F(0%5B1-9%5D%7C%5B12%5D%5Cd%7C30)%20(%5B01%5D%5Cd%7C2%5B0-3%5D)(%3A%5B0-5%5D%5Cd)%7B1%2C2%7D%24%2F