Archive

Posts Tagged ‘code’

Diving into OOC, a fun new programming language

November 12th, 2009

OOC is cool.  Yesterday I started writing some code in it after reading about it on the github blog.  Here is the first result:

I’m extremely happy with how well this performs.  Using the latest ooc Java compiler from the github trunk to handle the each() functions, this compiles down to a bunch of C code, and then is automagically compiled behind the scenes into an ELF Binary!  This is totally awesome, and I have to commend nddrylliog and the other contributors for their work on this awesome project.  Now I should use it for something useful :D

A quick note about getting it running on Ubuntu:


sudo apt-get install sun-java6-jdk
git clone git://github.com/nddrylliog/ooc.git
cd ooc
JAVA_HOME=/usr/lib/jvm/java-6-sun/ make

At least, that’s how I did it. Then I compile all my ooc with a Makefile like this:


INPUTS=$(wildcard *.ooc)
TARGETS=$(patsubst %.ooc, %, $(INPUTS))

all: $(TARGETS)

%: %.ooc
  java -jar ~/repos/ooc/bin/ooc.jar $@

That will compile all ooc files in the directory.


Uncategorized , , , , , ,

1,000,000th Fibonacci Number One-Liner in C

September 9th, 2009

This is possibly the best one-liner I’ve ever written:

gcc -x c -o /tmp/out - -lgmp <<< '#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdint.h>
#include <gmp.h>
void omg_i_love_leonardo_of_pisa(uint32_t num, mpz_t * result) { mpz_t retval, last, tmp; mpz_init(retval);
 mpz_init(last); mpz_init(tmp); uint32_t i = 1; if(num == 0) return; mpz_set_ui(retval, 1U);
mpz_set_ui(last, 0U); for(; i < num; i++) { mpz_set(tmp, retval); mpz_add(retval, retval, last);
mpz_set(last, tmp); } mpz_set(*result, retval); } int main() { uint32_t num; mpz_t fibo; mpz_init(fibo);
omg_i_love_leonardo_of_pisa(1000001, &fibo); mpz_out_str(stdout, 10, fibo); printf("\n"); return 1; }
' && time /tmp/out

It compiles a C program given from STDIN, puts it in /tmp/out, and runs it with time to find the time it takes to run. It generates the 1,000,000th Fibonacci number. Try it!


Uncategorized , , , , , , ,

Ruby to generate RSS feeds for sites that don’t offer them

August 23rd, 2009

There’s this site that has an equipment exchange I wanted to keep track of. Yet, it’s done with what seems to be a custom php file rather than vbulletin, so none of the usual RSS feeds from the site apply to it. So, I decided to make a scraper/feed-generator to get me the latest version every 5 minutes and generate a nice RSS feed, so I can view it in Google Reader. The volume of posting is low enough that this won’t be annoying to see in my daily feeds.

I usually use Ruby for this because it offers Hpricot, a very nice and fast scraper and XPath interface. This time, I resolved to find something that does RSS generation better, and I stumbled upon RubyRSS, which happens to be in the core ruby distribution!
Read more…


Uncategorized , , , , , , , , ,

Greasemonkey Script to get Jabber Room for Google Group Chat

March 15th, 2009

So, today I was invited to Google Group chat for the first time. This would be really cool on a terminal that’s not equipped with an IM client, since it’s all done through the web with flash and magic. But, since I don’t like having 2 IM clients running at the same time (Pidgin and the Flash one from Google), I decided I needed to rip out the Jabber Group Chat Room name from the invite page. I got some tips from this site, and wrote a Greasemonkey script to do so.

whoa

All you have to do is copy the room name into the Join Chat window, and put in groupchat.google.com as the server.  I hope you find it useful.  If anyone knows how to make this a link that GNOME will throw at Pidgin, let me know.  That would be awesome.

Get the Script

Uncategorized , , , , , , , , , , , ,

RSA Made Easy

February 27th, 2009

Lock IconAfter obsessing over it today, I decided to write a quick primer on RSA Encryption you can do in your head. It’s pretty simple, and to the point. The numbers are very small. Try it out!

I plan to write some code implementing the algorithm.  That should be fun.

Uncategorized , , , , ,

Random Fun with NASM

November 22nd, 2007

I was on IRC tonight and someone was having trouble with their NASM homework. I decided to help them by learning NASM and coding up their homework problem for fun. It was pretty cool.

Read more…

Uncategorized , , , ,