I've seen that for the first time in years.
Thursday, March 25, 2010
Thursday, March 18, 2010
Experimenting with Scala
This is my first useful Scala program. It was ported from a Python program (see below). In 1993 I wrote an equivalent in Modula-2 ;-)
Python version:
import scala.io.Source;
import java.io.File;
import scala.util.Random;
object voc {
def train(lst : List[Tuple2[String, String]]) : Unit = {
println();
if (lst.length == 0) {
println(":-D");
return;
}
val shuffled = Random.shuffle(lst);
val current = shuffled.head;
println(">>> " + current._1);
var line = Console.readLine();
if (line == current._2) {
println("correct");
train(shuffled.tail);
} else {
print("\007");
println("wrong - correct is: " + current._2);
train(shuffled);
}
}
def main(args: Array[String]) {
val lst = Source.fromFile(new File(args(0))).getLines()
.map { s => s.split("\t") }
.filter( l => l.length == 2 )
.map (l => Tuple2(l.head, l.last))
.toList;
train(lst);
}
}
Python version:
from __future__ import with_statement
import random
import sys
def train(lst):
while len(lst) > 0:
random.shuffle(lst)
lang1, lang2 = lst[0]
print ">>>", lang1
try:
answer = raw_input("answer: ").strip()
except EOFError:
# ^Z pressed, ignore
continue
if answer == lang2:
print "correct"
lst = lst[1:]
else:
print chr(7)
print "wrong - correct is =>", lang2
print
print
print ":-D"
def main():
filename = sys.argv[1]
lst = []
for line in open(filename):
line = line.strip()
if not line:
continue
parts = line.split("\t")
assert len(parts) == 2
lst.append(parts)
train(lst)
if __name__ == "__main__":
main()
Labels:
programming,
python,
scala
Sunday, March 14, 2010
PHP, the forgotten programming language
I just took a quiz and had a complete blackout of PHP. Can you name the 25 most popular programming languages? Quiz here.
Labels:
programming
Wednesday, February 17, 2010
Monday, January 18, 2010
Thursday, November 05, 2009
Interesting read about unit tests
It's OK Not to Write Unit Tests is an interesting blog post. Recommended to make you think again why you write them, if what you're writing are really unit tests, etc.
Labels:
programming,
testing
Monday, October 05, 2009
Unverständnis bei Bosbach von CDU
"Ich verstehe die Kritik der Liberalen an den auf Kinderpornografie beschränkten Netzsperren nicht." Es gebe kein Recht auf ungehinderten Zugriff auf Kinderpornografie im Internet, betonte Bosbach.
Netzwelt-Ticker: Google Wave strandet an der Hypeküste - SPIEGEL ONLINE - Nachrichten - Netzwelt
Liberale wollen im Internet weiter freien Zugriff auf KiPo haben, während die CDU das Netz für uns sicher machen will. So einfach ist das-
Netzwelt-Ticker: Google Wave strandet an der Hypeküste - SPIEGEL ONLINE - Nachrichten - Netzwelt
Liberale wollen im Internet weiter freien Zugriff auf KiPo haben, während die CDU das Netz für uns sicher machen will. So einfach ist das-
Labels:
zensur
Tuesday, June 16, 2009
2009-01-07: Creating self-signed certificates
Note to self: When my self-signed certificate for my mail server expires next year at about the same time, this should fix it:
openssl req -config /etc/ssl/openssl.cnf \
-new -x509 -nodes -out /etc/ssl/certs/dovecot.pem \
-keyout /etc/ssl/private/dovecot.pem
Monday, July 18, 2005
The really hard bugs ...
D. Richard Hipp today on the SQLite mailing list:
I am constantly amazed at the prevailing idea (exemplified
by Java) that software should be strongly typed and should
not use goto statement or pointers - all in the name of
reducing bugs - but that it is OK to use multiple threads
within the same address space. Strong typing helps prevent
only bugs that are trivially easy to locate and fix. The
use of goto statements and pointers likewise results in
deterministic problems that are easy to test for and
relatively easy to track down and correct. But threading
bugs tend to manifest themselves as timing-dependent
glitches and lock-ups that are hardware and platform
dependent, that never happen the same way twice, and that
only appear for customers after deployment and never in a
testing environment.
I am constantly amazed at the prevailing idea (exemplified
by Java) that software should be strongly typed and should
not use goto statement or pointers - all in the name of
reducing bugs - but that it is OK to use multiple threads
within the same address space. Strong typing helps prevent
only bugs that are trivially easy to locate and fix. The
use of goto statements and pointers likewise results in
deterministic problems that are easy to test for and
relatively easy to track down and correct. But threading
bugs tend to manifest themselves as timing-dependent
glitches and lock-ups that are hardware and platform
dependent, that never happen the same way twice, and that
only appear for customers after deployment and never in a
testing environment.
Labels:
programming
Subscribe to:
Posts (Atom)




