<terminator-voice>I'm back!</terminator-voice>
10 weeks of my internship at Resolver Systems passed like ten days. It was amazing experience - I learned a lot and I had great time. Many thanks to all my co-workers, you are great!
I had a great opportunity to attend first day of PyCon UK - it was really cool. I got some ideas I'd like to transplant to SFI festival.
TODO:
- expand this post
- LLVM
- programming language ideas
- vim + python
- more
Monday, 22 September 2008
Saturday, 21 June 2008
LaTeX thoughts and lack of time
I haven't written here for quite a long time — it's because of current semester's ending. I had a lot of work to do with my projects (btw: it's one of them; another video). For every project one has to write a documentation. And I know only one way to write documents that doesn't suck hard. It's the way of TeX. I have written quite a lot of LaTeX documents last month. Here is what I learned:
There are some things I wanted to write about, but I haven't got time. Here is my public TODO list:
Maybe one day one of those will turn intro full-blown post. Maybe.
- \newcommand and \newenvironment are your friends
- Making your comands and env names uppercase lets you avoid clashes with predefined ones.
- Try to be semantic from very beginning if it's easy. For example: you mention electronical parts or Java classes all over your document. Add \newcommand{\Class}[1]{#1} in the beginning of your document and wrap all class names with \Class{}. It would be easy do make all class names typed with some special font later on.
- If your documents take a lot of time to compile
- break it intro few files and \input them. Comment out inputs you don't work on currently.
- use draft option
- break it intro few files and \input them. Comment out inputs you don't work on currently.
- Thinking about writing documents in TeX as of programming helps a lot!
- Being a nazi with DRY principle makes your document sources look very semantic and the output is prettier. You do more tweaking if you can do it in one place instead of 20 places.
- Do the simple thing that gives you desired result. If you repeat yourself ⇒ abstract out repetition intro new command(s) and/or environment(s).
- Refactor!
There are some things I wanted to write about, but I haven't got time. Here is my public TODO list:
- Why Eiffel standard library is so cheesy that it makes me want to write program in brainf*ck instead of Eiffel (which is quite a nice language), and what can we learn from that (in "I promise, I'll never code something similar" way of learning)
- Why hovercrafts rock and how it is like to discharge 8 Duracell bateries in 20 minutes of playing with your homemade, bluetooth controlled one. (It's much more Witek's one than mine, but still)...
- Hooray, yet another post about monads!
- Hooray, yet another post about Scala!
- Erlang, OOP and functional programming
- I switched to zsh
Maybe one day one of those will turn intro full-blown post. Maybe.
Friday, 2 May 2008
organize your python imports in vim
My first script at vim.sf.net. You can grab it here. Source code of it and unittests (nose is great!) are on my mercurial repo.
Have fun!
Have fun!
Sunday, 20 April 2008
bash fun vol. 2
Forget previous post. Bash has functions:
Much better now. :)
goj@abulafia ~ $ tail ~/.bashrc
function apply() {
cmd=$1
shift
for x in $*; do $cmd $x; done
}
function go() {
$@
cd ${!#}
}
Much better now. :)
Monday, 14 April 2008
bash fun
Quote by Terrence Parr:
We do a lot of actions that make a directory interesting for us and then we want to cd intro that directory. Consider:
Boring, repetitive and not DRY.
Lesson 1: You can do something like this:
Better, but not good enough for me. I'd like to type
So we need to create a short bash script, don't we?
How do we get last argument of the script (we'll need that). Provided that
How nice and intuitive. Try those:
So do we have all that we need?
Epic FAIL. ./go script is executed in child shell. When it terminates it's parent's CWD is unaffected. We have to source it:
But this syntax sucks. Luckily, alias is our friend:
You have to have ~/bin in your PATH.
Ta-dam!
My Motto: "Why program by hand in five days what you can spend five years of your life automating?"
We do a lot of actions that make a directory interesting for us and then we want to cd intro that directory. Consider:
hg init my_repo; cd my_repo
mkdir -p a/b/c/d; cd a/b/c/d
mv my_file /tmp; cd /tmp
Boring, repetitive and not DRY.
Lesson 1: You can do something like this:
mkdir -p a/b/c/d; cd !$
Better, but not good enough for me. I'd like to type
go hg init my_repo
go mkdir -p a/b/c/d
go mv my_file /tmp
So we need to create a short bash script, don't we?
How do we get last argument of the script (we'll need that). Provided that
$1
is the first argument, $2
- second and $#
- argument count and $@
all arguments as an array... yes, you guessed it. It's ${!#}
How nice and intuitive. Try those:
$$# ${$#} ${${#}} $@[$#]
.So do we have all that we need?
goj@abulafia tmp $ cat go
#!/bin/bash
$@
cd ${!#}
goj@abulafia tmp $ ./go echo ~
/home/goj
goj@abulafia tmp $
Epic FAIL. ./go script is executed in child shell. When it terminates it's parent's CWD is unaffected. We have to source it:
goj@abulafia tmp $ . ./go echo ~
/home/goj
goj@abulafia ~ $
But this syntax sucks. Luckily, alias is our friend:
goj@abulafia tmp $ echo 'alias go=". go-source-me"' >> ~/.bashrc
goj@abulafia tmp $ mv go ~/bin/go-source-me
You have to have ~/bin in your PATH.
goj@abulafia tmp $ go echo ~
/home/goj
goj@abulafia ~ $
Ta-dam!
Wednesday, 2 April 2008
April Fool's day
As last year, I managed to make my year's forum unreadable for April Fool's day. Awful, pink theme from last year was yesterday joined by truly horrible spelling and flipped avatars. :>
Here are the results:
Here is a little HOWTO. It may be useful for something practical, or for next year. Basically, you have to use mod_ext_filter see the sed example.
Polish spelling mistakes are different to English ones. They are (mostly) caused by fact, that there are (for historical & (maybe) other slavic languages "compatibility" reasons (is legacy a proper word?)) few sounds that have the two spellings, like ź-rz and u-ó, h-ch. It makes it very easy to inject typos to polish text.
We are talking about HTML pages. You cannot break html, eg <a chref="..."> would be BAD. So we don't touch anything inside html tags, comments and entities. This makes it hard to use regexps. If I were to write this joke's filter program once again I would use flex. But I wrote a short and slow (2,2 seconds to process a page - unacceptable) automata-based python script, and then (when it turned out how bad it performs) added lighting-fast (0,01 s/page) C-code generation to it. Generating code for automata is very easy.
code is here
Code generation itself is a bit over-engineered, too. I shouldn't have cared about beautiful indentation & proper newlines. I should have used GNU indent instead.
Apache configuration:
gunzip-filter-gzip is a filthy trick. You can probably avoid it by proper filter configuration. If you know how, please drop me a comment.
Here are the results:
Here is a little HOWTO. It may be useful for something practical, or for next year. Basically, you have to use mod_ext_filter see the sed example.
Polish spelling mistakes are different to English ones. They are (mostly) caused by fact, that there are (for historical & (maybe) other slavic languages "compatibility" reasons (is legacy a proper word?)) few sounds that have the two spellings, like ź-rz and u-ó, h-ch. It makes it very easy to inject typos to polish text.
We are talking about HTML pages. You cannot break html, eg <a chref="..."> would be BAD. So we don't touch anything inside html tags, comments and entities. This makes it hard to use regexps. If I were to write this joke's filter program once again I would use flex. But I wrote a short and slow (2,2 seconds to process a page - unacceptable) automata-based python script, and then (when it turned out how bad it performs) added lighting-fast (0,01 s/page) C-code generation to it. Generating code for automata is very easy.
code is here
Code generation itself is a bit over-engineered, too. I shouldn't have cared about beautiful indentation & proper newlines. I should have used GNU indent instead.
Apache configuration:
ExtFilterDefine ortozawal mode=output intype=text/html cmd="/usr/local/bin/ortozawal"
ExtFilterDefine ungzip-filter mode=output intype=text/html cmd="/bin/gunzip -"
ExtFilterDefine gzipme-filter mode=output intype=text/html cmd="/bin/gzip"
ExtFilterDefine flip-image mode=output cmd="/usr/bin/convert - -flip -"
<Location "/forum">
SetOutputFilter ungzip-filter;ortozawal;gzipme-filter
</Location>
<Location "/forum/images">
SetOutputFilter flip-image
</Location>
gunzip-filter-gzip is a filthy trick. You can probably avoid it by proper filter configuration. If you know how, please drop me a comment.
Labels:
apache,
C,
code generation,
joke,
orthography,
python
Saturday, 1 March 2008
small, pythonic lisp
Grab it here.
It's < 256 LOC toy lisp. Nothing super-fancy. If you don't count unit tests and Guido's mm.py it's even < 128 LOC.
It's quite pythonic. When you write
Talking about Python and lisp lists:
Yes, this is just a linked list, not a true scheme cons, since it doesn't support improper lists, I posted it just to show how Python iterators are neat.
It's < 256 LOC toy lisp. Nothing super-fancy. If you don't count unit tests and Guido's mm.py it's even < 128 LOC.
It's quite pythonic. When you write
eval
in LISP it's just a big cond
. It translates directly to if/elif/elif/... which doesn't look good. I used dict of functions instead, which looks better in my eyes. Uses as many Python features as possible. Python functions, python lists. etc.Talking about Python and lisp lists:
class slist(object):
class iterator(object):
def __init__(self, lst):
self.lst = lst
def next(self):
if self.lst:
result = self.lst.car
self.lst = self.lst.cdr
return result
else: raise StopIteration
def __iter__(self):
return slist.iterator(self)
def __init__(self, a, b=None):
self.car = a
self.cdr = b
def __str__(self):
return '(%s)' % ' '.join(str(elem) for elem in self)
list_123 = slist(1, slist(2, slist(3)))
a, b, c = list_123
Yes, this is just a linked list, not a true scheme cons, since it doesn't support improper lists, I posted it just to show how Python iterators are neat.
Subscribe to:
Posts (Atom)