I can never find this page without a lot of searching.
// This is a proof-of-concept port of Python's Stan // to Javascript. function make_tag_fn() { var _indent = 0 ; var indent = function() { var tmp = "" ; var i ; for (i = 0 ; i < _indent ; i++) { tmp += " "; } return tmp; } // tag is a function contructor var tag = function(name) { // fn is the function which tag contructs var fn = function() { // this copies the arguments which fn // receives, so that fn_ can acces them var argz = [].slice.call(arguments);
I've been trying to rationalise the way in which I think imperative and functional programming can be brought together. Primarily, this is an exercise in clarifying my thoughts on how I expected Scala to work. (It doesn't work this way, possibly because it would certainly break interoperability with Java, but probably because Scala's author(s) are a lot cleverer than me. This idea probably has implications of which I have not thought.)
I have structured my thoughts as a series of definitions.
After finding that there was no easy way to get immutable collections to 'snapshot' the state of their contained objects, I realised I would have to use only immutable objects. (See the previous post.)
Immutable objects are much more costly to modify (not modify per se, but to create a new object that almost the same as the old one). A new object has to be created on each mutating method call. There is also then the garbage collection which needs to be done.
I did a little informal benchmark:
I'm evaluating Scala and am having a problem with it's immutable collections.
I want to make immutable collections, which are completely immutable, right down through all the contained objects, the objects they reference, ad infinitum.
Is there a simple way to do this?
The code below illustrates what I'm trying to achieve, and a nasty work around (ImmutablePoint).
The UDP Echo Server seems to be the 'hello world' of network programming.
What is Scala?
Scala is a hybrid OO/functional programming language which runs on the Java Virtual Machine.
In the spirit of 'doing the simplest thing which works', I've been using the following idiom for encapsulating data within objects. I'm still quite new to Javascript, so I'm sure others have been doing similar things for a long time, in a more elegant fashion (I must get round to reading the jQuery source).
A naive object is:
var account = { name : "fred" , balance : 100.00 , branch : "Worcester" } ;
I read Douglas Crockford's book and was rather inspired.
Now JavaScript is starting to grow up, with excellent projects including env-js, nodeJS, CommonJS, v8 and jQuery, what are the reasons to still use other 'scripting' languages. (I'm not using 'scripting' in a derogatory way - I suppose I mean dynamic/interpreted.)
The hosting environment is assumed to be Ubuntu Jaunty, with qemu already installed.
First, get the files you'll need:
$ wget http://ftp.de.debian.org/debian/dists/lenny/main/installer-armel/current/images/versatile/netboot/initrd.gz $ wget http://ftp.de.debian.org/debian/dists/lenny/main/installer-armel/current/images/versatile/netboot/vmlinuz-2.6.26-2-versatile
Create a disk image:
$ qemu-img create -f qcow hda.img 10G
Then start qemu:
$ qemu-system-arm -M versatilepb -kernel vmlinuz-2.6.26-2-versatile \
I'm still hacking away at little bits of Haskell, gradually learning my way around.
I happened to find code for Bresenham's Algorithm on Rosetta Code. It made me uncomfortable - it looked like the author had pushed a C-shaped programme into Haskell-shaped syntax.
This was just my first impression - I don't know the language well enough to know when to use the State Monad - and I'm certainly not qualified to criticise the orginal author of the following code.
It's this easy to write a programme which uses libc's open and read functions to print it's own source. See Python's documentation for more details.
#!/usr/bin/env python import os import sys from ctypes import CDLL MAX_CHARS = 1000 # maximum number of characters to read if __name__ == "__main__": libc = CDLL("libc.so.6") fd = libc.open(sys.argv[0], os.O_RDONLY) buffer = " " * MAX_CHARS num_chars_read = libc.read(fd, buffer, MAX_CHARS)
Sorry for the delay, I had more to learn about Apache's proxypass directive.
See http://www.finalcog.com/recombinant-hashes for some details of, and applications for, the algorithm.
The demo is now running, the urls are:
To use the demo:
The 'with' keyword, introduced in Python 2.5, allows a nice way of handling the initialisation (and teardown) of curses applications.
The object used with 'with' needs to have two methods, __enter__ and __exit__.
The __enter__ method is called before the code in the 'with' block is executed. Whatever it returns can be assigned to a variable using the 'as' keyword.
The __exit__ method is called after the code in the 'with' block is executed, or if an exception is raised within the block.
Just drew this from a comment, made by a bloke on the row behind me at europython. Thanks to my employers, ApplianSys Ltd., for letting me attend. Enjoy.
Ubuntu 9.04 and t-mobile wireless broadband.
I bought a t-mobile 'USB stick 110' (which is actually a Huawai E160 dongle). It cost £40, including £20 credit. It's PAYG, costing £2/day, with a 3GB monthly limit.
I plugged it into my laptop and a new connection appeared in the network manager.
Sceptically, I clicked to enable it - and *it just worked*.
No messing with kernels, mode switching or anything else.
The E160 is detected as an E220, which is fully supported by linux.
chris@vostro:~$ lsusb | grep Huawei
Introduction
I must admit, after a decade of working professionally with unix/linux, that I had never encountered kill -0 until last week.
What does the -0 signal do?
Nothing at all...
What is it useful for?
It returns 0 if the process exists, or 1 (and an error message on stderr) if it doesn't.
All the Linux/C error codes are listed below.
I occasionally google C error codes, but always end up grepping through /usr/include to find the answer (on Ubuntu 8.10). To save myself, and a few others, some time in the future...
/usr/include/asm-generic/errno-base.h
#ifndef _ASM_GENERIC_ERRNO_BASE_H #define _ASM_GENERIC_ERRNO_BASE_H #define EPERM 1 /* Operation not permitted */ #define ENOENT 2 /* No such file or directory */ #define ESRCH 3 /* No such process */ #define EINTR 4 /* Interrupted system call */
I recently purchased a Dell Vostro 1710 17" laptop, with 2.1GHz Core2 Duo, 4GB RAM and 1920x1200 display for £624 + VAT.
The requirement was for a new machine to be used as a 'desktop replacement' laptop. As I'm a software developer, it needed a big screen, lots of ram, and to have virtualisation support in the CPU. Fast OpenGL support didn't hurt either :-)
I've been in the fortunate position to test a couple of SSDs recently. To round things off, I've also included results for a standard 7,200rpm SATA disk and a USB key.
The results are:
SAMSUNG MCBQE32G5MPP-0VA £400
seq. write: 65MB/s
seq. read: 96MB/s
random seeks: 7,511/s
OCZ VERTEX 00.PT1 £100
seq. write: 77MB/s
seq. read: 142MB/s
random seeks: 9,058/s
WDC WD1600AAJS-00B4A0 (normal 3.5" 7,200rpm hdd) £30
seq. write: 68MB/s
seq. read: 91MB/s
random seeks: 226/s
KINGSTON DATATRAVELER USB STICK
seq. write: 8MB/s
seq. read: 32MB/s
random seeks: 2,828/s