Hack Jam Log Book is a log of progress made in and around a weekly hack session. Topics include natural language processing, high energy electronics, linguistics, interface design, &c. Enjoy.

Recent Posts:

Archives:

19.7.13

 

Prolegomena to Any Future HackJam Post

Hi friends,

Hacking and Jamming are alive and well in their various forms.

Loki and I got FPGA dev kits a couple weeks ago and are giving a go at VHDL.

I suppose I will make a nice note here when we have something to show off.

Cheers,
~js


18.7.12

 

annual update

I have been working with C++ quite a bit lately and had to deal with things like this:

template < class List_entry>
void List< List_entry>::traverse(void (*visit)(List_entry &))
{
   Node *q;

   for (q = head; q; q = q->next)
      (*visit)(q->entry);
}

It was useful to invoke this method when I needed to print the contents of the list. I just passed in the name of a function like this:

void print_entry ( List_entry &e )
{
   std::cout << e << std::endl;
}

I thought I could do a bit more advanced things by adding a void* argument, but there would be a little bit of work with that and it was not perfectly general.

The notion of lambdas also occurred to me but I did not think too hard about it since they are still new in C++ so I was like ... meh.

Then I kept thinking some more and I was like, uggh, the way I toss bits around, an additional arbitrary callback argument will be approximately as powerful as a temporary anonymous function, if not as syntactically pretty, and both of these are going to be more or less limited to doing only so much with the current object in the iteration.

The potential versatility suggested by this kind of element-iterator with arbitary callback suggests interesting possibilities that, well, ought to be a lot easier! It would be great if I could call traverse on a binary search tree and have it generate a dot file representing the relationships between nodes so a computer program could draw them nicely for me. In fact that kind of thing seems like what any traverse method worth its salt ought to have been meant for. But it's unpleasant to do in a general way and without unnecessarily abusing global state! A callback with three parameters (parent, left, right) is one option, but I don't want to be bound to the number 3. Maybe I can just do (a, b, NULL) for a two-parameter version. But why stop there? How about vararg? Or maybe a vector of arguments? These all seem very unsatisfying and ad-hoc to me!

It might be nice if some portion of the current stack frame could be made available to my callback function -- even in a safe and read-only way. I promise I do not want to break things, just know where I'm at so I can figure out where I'm going! Oughtn't there be a concise way to define a callback with read access to certain local variables belonging to the function invoking the callback?

How can I achieve such a thing in C or C++? I mulled over this for several days, toying in my head with various unimplementable thoughts and vacillating over whether the idea itself was good or not, or whether I was already overlooking any useful language feature that made this easy as cake, or whether I had dug myself into a tarpit of hopelessly unimprovable design? A binary search tree could be drawn any number of ways, but, darnit, why not with such a traverse method as described above? No world can be a happy one that has factories where one robot tosses doodads onto a conveyor belt and another operates a claw to inspect each, one by one, without knowing anything of the status or history or progress of the doodad-loading operation; else that claw-bearing robot be an uninterestingly simple one, and the factory incapable of producing anything of value.

I was completely flummoxed. This is so basic a need, and it tears at the fabric of my thoughts with such relentlessness, someone else must already have figured it out; I must rest my mind a short time before I drive myself crazier!

Though I may have permitted my brain a brief respite from the harrowing, I could not fully abandon the matter, in spite of the mounting practical reasons to do so. Before I was prepared to abandon all responsibility and set forth once more and finally forever down this path to ultimate insanity, the notion was abruptly thrust into my consciousness to consider the bigger picture. Bigger than binary trees -- what of the general class of graphs? Here, my mind began to spin again. It would not cut it to just pass references to the parent, left, and right nodes. Total parameter variability was necessary to account for the diversity of graph representations and characteristics! In the same instant that it occurred to me that the entire state of the invoking function must be fully accessible to the callback, a sharp blow glanced off my lower abdomen and I landed on my back, striking my head on the asphalt. Dizzy, I wheezed through a scowl and by the time I had lifted my head up, a formation of one thousand diiqs and calcnerds had begun rapidly marching towards me, brandishing brightly colored pugil sticks. A dark horse with a confident gait followed. It was the general, Adam. The head of each of the two advancing columns set down his weapon and appeared on either of my shoulders. They leaned in close to my ears as if to whisper. I could not fret over the decision to listen to one or the other because they both shouted in unison, startling me further. My mind was blank from fear and as I groped for comprehension, they boxed my ears and while I reeled they fluttered up in front of me and mocked me with gestures I could barely make out through the taste of tears and snot. They flew off into the sunset together, the army marching along under them. Parentheses formed in their wake, and I could not tell if they were opening or closing.

1.8.11

 

7/28

Hackjam was pretty fun this last week. I expressed some disdain for Lisp's single single quote quoting syntax, born mostly in my ignorance, and got some good feedback from the Lispers about how it is used and what it does. The "close" for the single single quote quote is whitespace which I had previously assumed but there are so many flavors it was hard to be certain.

We also played with TheGun.exe which brings me no end of delight -- it does not have a config file, but its standalone configurator modifies the exe so that next time it runs the settings you configured are "default". "Played with" included loading it in Notepad.exe as well as vim and attempting to change some strings and observing it to fail loading, both in Windows 7 and Wine 1.32. Under Wine, at least, TheGun.exe would not save modifications to the very executable image responsible for the running process, but you could save them to a different file at least and run that, or attempt to. I suspect you probably just couldn't write to the exe of any running process. Near the top of the file there were some mentions of TheGun and I changed one to Horse and it would not load, sadly.

1.7.11

 

Movie GUIs

I went to Hackjam the first time in who knows how long and it was nice to see everyone again.

I found accessmaincomputerfile.net the other day and was inspired to try my hand at some immersive or attention-grabbing GUI components. Movie GUIs are overkill and extreme and make "real" GUIs look like the 20th century -- the ones I get excited about anyhow. The other ones I get excited about are the ones that are too real such as Trinity+nmap or SunOS in the new Tron movie. These aren't very exciting to see on your normal computer though since, well, they already are on your normal computer.

My first step is to implement a clock applet resembling the screenshot from Darkstar. I am running XFCE4 in Arch right now so I am going to target this environment. Adam was very helpful to me in gathering some information and getting started on setting up the build environment and sharing his perspective on how it might work. I have successfully compiled the original clock applet now. There are five options, each of which is based from a .c file in the xfce4-panel source tree, so my intent is to add clock-darkstar.c as an important part of finagling a sixth option into the mix.

After doing all this hard work I decided making a XFCE plugin did not really further my goals and it would probably be more fun and tasty to pursue another avenue that did not necessarily require XFCE for example.

I already have some experience with SDL so I am going to bark up that tree.

As much as I want to learn new things, what I really want is to have a sweet new Darkstar (1974) clock applet. Now I am abusing the term "clock" and "applet" since this beastmaster can be so much more! A clock for starters, but the view implies so many fiddly knobs! Every text field is completely configurable in a number of ways. Good grief I am already in over my head before I even hit the water!

I am going to nuke my copy of the xfce4-panel out of spite and also to make sure I have a lot of headache to go through in case I forget that I am doing this with SDL and not making a xfce4 plugin.

I am also listening to Voltaire right now. Background music, not advice.

Cheers!

EDIT: here is a great link to what I have accomplished thus far https://jonathanstone.homeip.net/darkstar.tgz. Please kindly disregard the certificate error, thanks. You can build it with some normal command such as "make". Also you need to put a 639x359 darkstar_1974.bmp in the folder at runtime since I am NOT distributing that. I got mine from accessmaincomputerfile.net as linked above and converted it to bmp with such a command: "convert darkstar_1974.jpg darkstar_1974.bmp". The 20ms delay is necessary to make the thing not nom down on all the cycles. Experimenting with higher values resulted in even lower (<1%) CPU utilization but then I couldn't close the window because the events occuring during the wait cycle are not processed.

Labels:


12.12.10

 

silly shell tricks

You can use 'tac' to implement a stack.

Red comes from stdin, black is stdout:

Instead of doing `factor`:
$ factor
33
33: 3 11
19
19: 19
27
27: 3 3 3
^D

You can do this:
$ tac | factor
394
87
19
666
^D
666: 2 3 3 37
19: 19
87: 3 29
394: 2 197
$

What was reversed was the order of inputs sent to factor, not the output generated by factor. The effect is of course haveable a number of different ways:
$ echo "394 87 19 666" | factor | tac
666: 2 3 3 37
19: 19
87: 3 29
394: 2 197

and this is the same procedure however factor sees them in the order you typed them, not in their stack-reversed order. I think I can use this to my advantage someday, when I want a filter to see reversed input.

You can also flip the output over the logical y = -x line using both tac and rev; this is also mostly JFF (just for fun):
$ echo "394 87 19 666" | factor | tac | rev
73 3 3 2 :666
91 :91
92 3 :78
791 2 :493

Clearly nonsensical. These filters are transitive however!
$ echo "394 87 19 666" | factor | tac | rev | tac | rev
394: 2 197
87: 3 29
19: 19
666: 2 3 3 37

and

$ echo "394 87 19 666" | factor | tac | rev | rev | tac
394: 2 197
87: 3 29
19: 19
666: 2 3 3 37

and

$ echo "394 87 19 666" | factor | tac | tac | rev | rev
394: 2 197
87: 3 29
19: 19
666: 2 3 3 37

and

$ echo "394 87 19 666" | factor | rev | tac | tac | rev
394: 2 197
87: 3 29
19: 19
666: 2 3 3 37

and

$ echo "394 87 19 666" | factor | rev | rev | tac | tac
394: 2 197
87: 3 29
19: 19
666: 2 3 3 37

While I did not exhaust the combinations of two tacs and two revs, I feel confident knowing their properties that my conjecture holds, and I would even go so far as to say that any finite stream for which their exists sufficient RAM to process is preserved through arbitrary linear combinations of even counts of tacs and even counts of revs. A number of assumptions are of course depended upon: tac should require no more space than the streamed lines actually occupy and rev's space is constant in the number of lines and per-line, linear in the length. With clever stream pointer manipulation, both of these tools should not require to allocate additional space however.

I have decided to run into a dense jungle banging on a drum and screaming DEATH TO MONKEYS!!! Here is a map of my progress: http://piratejon.com:8080/mirror.

Labels: , ,


10.10.10

 

sockets

Hack Jam Log Book deserves a new post.

I have not been to hackjam in a while due to a great personal inconvenience in the tradeoff between space and time.

This has not limited my hacking however.

This weekend I made a great sockets program in C. It has the following features: if you run it with a certain set of flags it attempts to initiate a TCP connection with a specified host on the specified port. If you run it with a different set of flags it listens for a connection attempt on the specified port. These behaviors are meant to be used in a complementary way though you can do whatever you want with them really. After a connection is established, a message loop enters which polls both stdin and the established socket connection. Since my terminal is in some kind of cooked buffered line mode, it sucks when you are typing and the remote host sends a message, but fortunately nothing is lost except maybe the user.

There is no protocol.

This is not a lot different from telnet however it has even fewer features and capabilities.

It does however illustrate basic blocking sockets and select() in C.

It does not currently compile in Windows (maybe cygwin?) though it will soon enough -- a little WSAStartup() here and maybe some WSACleanup() there and some other smidgens and #ifdefs and we'll have it.

Code at http://jonathanstone.homeip.net:8080/chat

Direction: ncurses to solve dumb text entry problems, full Win32 support, and openssl for point-to-point encryption.

29.3.10

 

A Painted Blog

I'm trying a little experiment; it's a blog that's painted on a 4'x8' piece of plywood; each new post is painted right on top of the last one, building up a visual history in layers of paint. Check it out at http://diiq.org/

9.8.09

 

xkb and xmodmap: a big mess

So I've convinced myself to try a new keyboard mapping; arensito is currently the only word that I can type quickly and accurately.

I thought that I would take a moment to write down the steps that it took to get a mapping with an extensive and unusual Alt-gr map up and running (on Linux). What is available online is exceedingly unhelpfull.

1. I used Mod_switch rather than ISO_level3_Shift. ISO is the 'correct' choice, but by default N and J cannot be level shifted; fixing that requires xkb, and xkb is evilly difficult to use.

2. Speaking of xkb and evil, Mod_switch won't always work unless xkb is off. So in xorg.conf:

Section "InputDevice"
Identifier "Keyboard0"
Driver "keyboard"
Option "CoreKeyboard"
Option "XkbDisable" "true"
# Option "XkbRules" "xorg"
# Option "XkbModel" "latitude"
# Option "XkbLayout" "us"
EndSection

Make sure to comment out all the xkb rules. In .xsession or .xinitrc or wherever you put scripts that run before your X session starts:

export XKB_DISABLE=1

3. Edit .Xmodmap:

keycode 44 = j J plus
keycode 0x41 = Mode_switch
clear mod3
add mod3 = Mode_switch

(note that I use the spacebar as my Mode_switch; chances are you want someting different)

Mode_switch uses the third and fourth keysyms; 'j' and 'J' are the first and second, 'plus' is the third. space+j will return '+'.

Please understand that this is the wrong way to do this; the 'right' way is to use xkb. However, rolling your own xkb mapping is a major undertaking, while xmodmap is reasonably simple. Disabling xkb as I have done here is not reccomended generally, and can apparently cause problems if you use compositing. Nevertheless, this solution works for me.

Labels:


8.8.09

 

a lisp

I'm working on designing a programming language. I am doing so because I want to do more of what I enjoy about programming. Boilerplate code does nothing for me. It is the beautiful code, the obvious-once-you-see-it-but-what-were-you-smoking-when-you-saw-it code, that makes me enjoy programming. I want a language that maximizes my experience of the numinous, a language that comes as close to the platonic program in my head as it can.

I don't want a super-efficient language, or a minimal language, or a super-readable language. I want a language that is fun.

The most controversial way I can put it is probably also the best: there is a quote.

"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." – Brian W. Kernighan

My design philosophy is this: I want a language in which I can code as cleverly as possible. Because I enjoy it. To hell with anything else.

Labels:


25.6.09

 

Clone of Existing Game with 3D Enhancement

I have spent the past three HackJam sessions cloning the super-fun Flash game Boomshine, in C. The reason for doing this is because I would like to add a 3D extension to this game. I want the third dimension to be time. Right now the balls bounce about on a flat plane, and the progression of time from present to more present results essentially in a visual overwrite of the balls at their new space coordinates. Well, by using perspective, I want to draw a 3D representation of the balls so that you can see in a single glance where the ball started and where the ball will be after many units of time have passed and, up to pixellation, where the ball will be at every moment in between. To describe this further, let me explain that while the balls are just bouncing about on their original 2D plane, the 3D view will be essentially static because the balls' velocities are fixed. The 3D view can only change after the player drops his ball with the mouse, and the outcomes of the original balls interact with that which was not there before.

I got the idea to do this from a discussion with Montana about "solving" the game -- i.e. figuring out where you could place your ball to ensure that you "won". He suggested something about Einstein's light cones and thus this idea was born.

I have never done 3D graphics before except in QBasic like ten years ago so this will be challenging and interesting.

Right now I have successfully cloned the behavior of the original game. The balls bounce, collide, grow, shrink and die predictably, and all parameters (initial size, color, growth rate, target growth size, waiting duration, shrink rate, and number of balls) are completely customizable within reasonable limits i.e. no negative radii.

With regard to shininess, I hope to do some transparency/alpha blending so the balls don't just overlap, also when bouncing off the edges the sprites flicker because the collision logic is funky however they ultimately careen off at the correct angle and stop flickering when they get away from the edge. Also maybe sound at some point? However these are all ancillary to my chief interest, which is representing the time dimension spatially.

This page is powered by Blogger. Isn't yours?

Subscribe to Posts [Atom]