kpreid: (Default)
2011-02-12 09:28 am

Google again

It’s now confirmed that I'm going to be doing the same thing this summer as last summer: working at Google on Caja.

All comments, congratulations, housing recommendations, and activity suggestions are welcome.

kpreid: (Default)
2011-02-09 09:49 am

(no subject)

Do not sort the category “Other” under “O”.

kpreid: (Default)
2011-01-27 10:28 am
Entry tags:

Catching up to 1999

(I'm posting this because I have the feeling it is not as well known as it should be.)

If you're compiling a C program with GCC, unless you have a reason to do otherwise (such as compatibility with other compilers), use -std=c99 instead of -ansi. -ansi specifically chooses the older C90 standard.

Why should you use C99? I'm not one to give you a complete list of changes (this article seems to be decent for that), but my favorite features are:

  • Boolean and complex number types
  • Variable declarations may be freely intermixed with statements, and used in the first expression of a for loop
  • // line comments
  • Variable-length arrays
  • Inline structure initializers: foo((struct bar){...});
  • Using field names or array indexes in structure initializers: struct bar g = { .x = 0, .y = 9.81 };

Note that many of these are common extensions to C (which would be rejected by -ansi -pedantic, I believe), but C99 makes them standard. C99 also removes some archaic features/looseness so as to make it harder to accidentally write incorrect programs.

kpreid: (Default)
2011-01-12 01:15 pm
Entry tags:

Toy GC

For a project I'm considering, I took a few hours to see if I could write a working garbage collector.

This is a very bare-bones copying GC, written without any reference to How To Do It Properly (just my knowledge of how a copying GC works, but I believe it is mostly cleanly written other than (a) the hardcoded pointer comparisons for object layouts, and (b) support for exactly one GC root, which happens to be the object at the lowest address. (It also calls a “heap” that which I believe is conventionally called a “space”. And I suppose someone could take issue with my placements of casts and void *s.)

The test program simply allocates a structure containing the strings “Hello” and “world”, allocates a bunch of junk, and then prints the strings to show that they are still intact.

gc.c )
kpreid: (Default)
2011-01-06 02:28 pm

New index page: Simulations/games

I've written a new topic index page for my site: Games, simulations, and animations. Except for the note about Tile Game, everything on it is something I've already published.

Condensed list of the contents: Tile Game, Fire Worms, Mouse-maze, 15-puzzle, screen savers, Varychase, Linkage, Bouncyworm, Brownian Tree, pendulum animation.

kpreid: (Default)
2010-10-06 07:50 am

Well-founded IO in logic programming?

Has anything been done in logic programming (especially in languages not too far from the classic Prolog) which is analogous to monads and the IO monad in Haskell; that is, providing a means of performing IO or other side-effects which does not have the programmer depend on the evaluation/search order of the language?

In other words, what is to Prolog as Haskell is to ML?

kpreid: (Default)
2010-10-04 05:47 pm
Entry tags:

Unix tip

The following command is not idempotent:

cat * > cat.txt
kpreid: (Default)
2010-09-25 08:35 am

New graphics toy: Varychase

Varychase is a graphics toy I just published. Runs in the browser; wave your mouse around and it makes curly patterns.

I originally wrote the option-less version May 29, 2010; yesterday I finally got around to adding a bunch of stuff, polishing the presentation, and publishing it.

It uses <canvas> for the optional line-drawing (I should compare the performance to using SVG instead, as well as also putting the dots in the canvas), and a few miscellaneous HTML5/CSS3 features for optional refinements. I've tested in Safari, Chrome, and Firefox on Mac.

kpreid: (Default)
2010-09-20 07:55 pm

Cheap tweaks for your web pages on handheld devices

Got a nice fluid layout on your web site? Annoyed at how mobile browsers like to assume pages need nine hundred virtual horizontal pixels to display properly? Add this to your <head>, as I've just done across my site:

<meta name="viewport" content="width=device-width">

This tells iPhone and Android browsers, at least, to present the page with a virtual window width equal to the device's actual screen width. It was invented and specified by Apple.

(I am not taking up the question of whether these browsers are making the right default choice. I will say, however, that in my technical opinion this is the wrong choice of location for this parameter: whether a layout will work at narrow widths depends largely on the stylesheet, not on the HTML; this parameter therefore ought to be stored in the stylesheet (that is, be a CSS extension); insofar as it does depend on the HTML, you can then put it in a <style> element.)

If you're looking to use media types to provide different styles: These browsers also don't respect the “handheld” media type; but they do support draft CSS3 Media Queries, which allow you to condition on the actual screen width — if you want, even in ems! I've used this on the main switchb.org page to make the Big Text less likely to spill off the screen (could use some further testing; all I've used so far is my desktop and a Nexus One), and also in the Caja Corkboard demo (which I wrote this summer (among other things) and ought to blog about).

kpreid: (Default)
2010-09-02 08:21 pm

Pointfree diagonalization in Haskell

James@Waterpoint (Xplat on Freenode) mentioned an interesting problem: write an elegant point-free expression to compute the diagonal of a list of lists (that is, from [[00, 01, 02, ...], [10, 11, 12, ...], ...] obtain [00, 11, ...]).

His version:

diag = (map head) . (foldr (flip ((flip (:)) . (map tail))) [])

My version, which needs a non-pointfree helper function (but one which others have invented before, and perhaps ought to be in the standard libraries), but has fewer flips:

import Control.Arrow ((***))
import Data.List (unfoldr)

uncons xs = case xs of (x:xs') -> Just (x,xs'); [] -> Nothing
diag = unfoldr (fmap (head *** (map tail)) . uncons)

uncons is sort of the opposite of unfoldr, in that unfoldr uncons = id.

Update: [livejournal.com profile] darius's version, from the comments:

diag = flip (zipWith (!!)) [0..]

kpreid: (Default)
2010-08-28 11:15 pm

data: is the new “Bookmarklet”

A data: URL directly contains its content; for example, data:text/plain,Hello%20World!. The main usefulness of this is that you can do things like including images inline in a document. But you can also use it to create 'anonymous' HTML documents, where any link to them or bookmark contains the entire document.

I originally did this in 2006 when I was in need of a URL-encoding tool and did not have one to hand; so I wrote out:

data:text/html,<form action="data:text/plain,"><input id=r>

Properly encoded, that's:

data:text/html,%3Cform%20action=%22data:text/plain,%22%3E%3Cinput%20name=r%3E

This produces a form with a single field which, when submitted, will generate a data URL for a plain text document containing “?r=” and then the text; the URL, then, will contain the entered text URL-encoded after the “?r=”.

Of course, that's a horrible kludge and JavaScript has an encodeURI function...

See my site for the rest of that thought and more examples. (I can't include any actual data URLs in this post because LiveJournal doesn't permit them, for necessary but unfortunate reasons — the origin, in the sense of same-origin policy, of a data URL is the origin of the page containing it.)

kpreid: (Default)
2010-08-25 10:26 pm

A Haskell program: what you can get from 1, 2, 3, 4, +, -, *, /, and ^

I forget why I wrote this Haskell program, but it's cluttering up my do-something-with-this folder, so I’ll just publish it.

-- This program calculates all the ways to combine [1,2,3,4] using + - * / and ^
-- to produce *rational* numbers (i.e. no fractional exponents). (It could be so
-- extended given a data type for algebraic numbers (or by using floats instead
-- of exact rationals, but that would be boring).)
--
-- Written September 7, 2009.
-- Revised August 25, 2010 to show the expressions which produce the numbers.
-- Revised August 26, 2010 to use Data.List.permutations and a fold in combine.
-- 
-- In the unlikely event you actually wants to reuse this code, here's a license
-- statement:
-- Copyright 2009-2010 Kevin Reid, under the terms of the MIT X license
-- found at http://www.opensource.org/licenses/mit-license.html

Code )

I'd include the output here, but that would spam several aggregators, so I'll just show some highlights. The results are listed in increasing numerical order, and only one of the expressions giving each distinct result is shown.

(1 - (2 ^ (3 ^ 4))) = -2417851639229258349412351
(1 - (2 ^ (4 ^ 3))) = -18446744073709551615
(1 - (3 ^ (2 ^ 4))) = -43046720
(1 - (4 ^ (3 ^ 2))) = -262143
(1 - (4 ^ (2 ^ 3))) = -65535
...all integers...
((1 - (2 ^ 4)) * 3) = -45
(((1 / 2) - 4) ^ 3) = -343/8
((1 - (3 ^ 4)) / 2) = -40
(1 - ((3 ^ 4) / 2)) = -79/2
(1 - ((3 ^ 2) * 4)) = -35
...various short fractions...
(1 / (2 - (3 ^ 4))) = -1/79
(((1 + 2) - 3) * 4) = 0
(1 / (2 ^ (3 ^ 4))) = 1/2417851639229258349412352
(2 ^ (1 - (3 ^ 4))) = 1/1208925819614629174706176
(1 / (2 ^ (4 ^ 3))) = 1/18446744073709551616
(2 ^ (1 - (4 ^ 3))) = 1/9223372036854775808
(2 ^ ((1 - 4) ^ 3)) = 1/134217728
...various short fractions...
(((3 ^ 2) + 1) ^ 4) = 10000      (the longest string of zeros produced)
...all integers...
(2 ^ (3 ^ (1 + 4))) = 14134776518227074636666380005943348126619871175004951664972849610340958208
(2 ^ ((1 + 3) ^ 4)) = 115792089237316195423570985008687907853269984665640564039457584007913129639936
Tried 23090 formulas, got 554 unique results.
kpreid: (Default)
2010-08-12 08:44 pm

Dasher/Java/Android research linkdump

I find Dasher an interesting input method, and after getting my Android phone I thought it would be nice to try Dasher on it. However, at the time there was no Dasher port or any information on the Web about the possibility, so I looked into writing one. I found several dead projects and miscellaneous repositories and eventually found that the main Dasher repository had a Java port of Dasher. I dabbled in getting it to run on Android, but before I got anywhere I found Dasher was now in the Android Market, though there was still no discussion/announcement/public project info.

I shall now dump the links I collected while I was working on this project, so as to make the matter of Dasher and Java better-indexed. Unfortunately, I don't recall the significance of all of them.

The Dasher port that's currently in the Market is pretty solid. It has a variety of options for input (touch, trackball, tilt); the main thing it's missing is independent control of the X/Y sensitivity of the tilt control.

kpreid: (Default)
2010-07-02 09:54 am

More Android notes

  • A remarkable feature: “Settings → About phone → Battery use” claims to give a breakdown of energy use over the last period the phone was unplugged. It distinguishes between “Display”, “Cell standby”, “Android System”, and applications. Don't know how accurate it is.

  • Bluetooth keyboard driver experiences:

    • “BlueInput” by Teksoft does not work correctly for my Palm Bluetooth Keyboard; as others have reported, some punctuation keys do not work at all (and Shift-2 generates ", making me think that it was written for a different keyboard layout and not tested with US QWERTY).
    • “BlueKeyboard JP” failed to connect to my keyboard — or rather, it immediately says “disconnected”. Also, the install permissions info says it reads GPS location, which makes no sense unless this is one of those ad-supported things, but it doesn't say that and I don’t remember whether it did show ads. Update: It works, but the keyboard must be discoverable. And it is ad-supported.

    So I still don't have a keyboard driver. Perhaps I should look into writing one.

  • I need to learn about how file/application associations work so I can figure out who is at fault (file browser or viewer app) in my failing to open PDF and epub documents stashed on the SD card.

  • USB connection is done right: plugging into a computer does not interrupt usage at all, and if you want to mount the SD card then that's an easily-reached option; neither mandatory nor buried. (Well, it didn't; since system updates it now pops up the do-you-want-to-mount screen immediately, which you have to exit to continue with your previous activity.)

  • The force-Google-Account-to-Gmail thing became considerably less annoying once it occurred to me to find out that it let me change the From address of mail sent from the Gmail account. So my external identity is still kpreid@switchb.org, except in Google apps.

  • Nice bit of polish: “A system update has been downloaded, but your battery is too low to install it. Connect to charger first.” (phrasing from memory.)

I'm considering writing up a document like the Gadget Coverage List but with an emphasis on features × how to get them on Android rather than features × gadgets — so it would be a recommended apps list, among other things.

kpreid: (Default)
2010-06-17 05:56 pm

A useful shortcut for working on documents with build processes

$ cat ~/bin/maken
#!/bin/sh
# Make files and view the results.
make "$@" && open "$@"

UPDATE: Turns out I posted this previously, with further thoughts: Avoiding repeating myself (on the command line).

kpreid: (Default)
2010-06-14 10:22 pm

Nexus One notes

Did buy a Nexus One; have now had it for an hour or so. The following is not a review, but some observations:

  • It will work without a SIM card from the start. So if you want a gratuitously expensive wifi PDA...
  • The Google Account-based functionality (e.g. application Market, contacts sync) requires a Gmail account — and any Google Account with Gmail necessarily has the Gmail address as its primary email address. (Since Gmail lets you forward to another address, this doesn't matter unless you use Google services that send mail on your behalf, such as calendar invites.) I haven't tested whether they will still work if you then remove Gmail (but I would note that if it's possible at all, having a Wave account might help, since that seems to allocate a no-@-sign 'username' in the same way Gmail does).
  • Not perfect, but mighty slick. Need to stop playing around and get some sleep.
kpreid: (Default)
2010-06-06 04:29 pm

Considering buying an Android phone — your input wanted (PDA, part 2)

You may recall my post about looking for a new PDA. I have lately found additional pressure to find a solution.

  • Moving about on my own in new locations, I wish for a GPS/navigation device. I am currently borrowing a standalone GPS, but that's Yet Another Gadget
  • …to add to the four I already carry about (phone, PDA, watch, iPod).
  • My phone is on a prepaid plan which was chosen to be cheap for low usage rates. But it quickly becomes not-cheap under higher usage than a couple minutes a day — which I have when trying to do such things as coordinate three people on an errand.

I've compiled some of the options and what features they have into this Google Docs spreadsheet: Gadget Coverage List. Note that “-” means “No”.

At the moment, I am strongly considering getting an Android phone, specifically the Nexus One. I have recently determined that Android meets all my requirements, at least given some third-party software.

Buying a phone (and a plan) is indeed a higher cost than a stand-alone PDA, but I think universal Internet access is worth it.

Costs and carriers

The phone, unsubsidized and unlocked, is $529.

Given that it is GSM, I understand there are basically two carriers to consider: T-Mobile and AT&T. I get the impression that T-Mobile is somewhat less evil than AT&T, and I hear complaints about AT&T's network. On the other hand, T-Mobile does not have coverage (even roaming) in Potsdam, NY, where I'm going to be spending the next two years.

T-Mobile offers a monthly plan for $60/mo, 500 minutes/mo plus fees and (as far as I've looked now) a $35 activation fee. (The option to buy a plan without a phone was buried: you have to choose "T-Mobile SIM card" from the phone list.) I get the impression that the obscure monthly 'taxes and fees' can be around $3-$20 depending on the particular situation. Total cost over 2 years (not including phone): $1475+fees.

AT&T is, er, changing tomorrow. But now it would apparently be $70/mo, 450 minutes/mo, for a two-year contract with a free locked phone (which could be tossed or resold). Plus taxes and fees. After the change in data plan pricing, it would be (assuming no other changes) $65 for 2GB or $55 for 200MB data. Total cost over 2 years (2GB option): $1560+fees, and the phone works in Potsdam.

In both of these cases I assume the cheapest voice plan option.

One option would be to go with T-Mobile for the 2.5 months before I arrive in Potsdam; this would minimize my initial obligation to $709, and assuming I found I liked having a smartphone around sufficiently, I could then switch to AT&T for service during my 2-year stay in Potsdam.

Comments?

kpreid: (Default)
2010-06-06 12:01 pm

Fire Worms From Outer Space!

(If anyone has already used this title, that wasn't my intent.)

Screenshot of the game.

“Fire Worms From Outer Space!” was a game I wrote in spring 2009 as my final project for PH115 Science of Multimedia at MVCC.

It was written in Macromedia Adobe Director, and designed as “with the structure of a shoot-em-up and the mechanics of a physics game”; you must defeat the enemies in each of a series of levels — by smashing apart their chains-of-spheresical bodies with your wrecking ball of an inexplicably orbiting asteroid.

Most of the development time was focused on getting the physics right; the graphics, sounds, and level design were all secondary.

(I'm not particularly a fan of Director; it's just what was used in the class. If I ever get around to it, I'll rewrite it in JavaScript.)

Play Fire Worms

  • Play on web (requires Shockwave plugin)

    (Please let me know if this doesn't work; I don't have the Shockwave plugin so I can't test it.)

  • Mac OS X app (standalone)
  • Windows app (standalone?)

Source

The Director file, plain-text copies of the scripts, and all of my saved development history (reconstructed; it was originally a bunch of directory copies) are available in a Git repository at git://switchb.org/fire-worms/. (No web view yet; need to do that.)

Other than the background image, credited in game and in “Title Page” to NASA, all elements of the game are Copyright 2009 Kevin Reid. I haven't gotten around to sticking a license on it; contact me and I'll get around to labeling it MIT or CC — let me know what license would be useful for what you'd like to do with it.