More soon…
Archive for the ‘Code’ Category
It has begun…
Saturday, June 27th, 2009MonoDevelop 2.0 released
Monday, March 30th, 2009Just a quick note to say that the MonoDevelop has released it’s second version. Go download it and check out what’s new.
Mac OS X users still have to wait for the native build to be online, which will be what my next post is based about
Learning a new programming language
Friday, July 4th, 2008It’s common sense in the programming circle that programmers should make an effort to learn a new language every year. Some make it their New Year’s resolution, some just do it for the fun of it, others do it to enrich their experience and their CV. So, today, I decided to grab a new language and stick with it until I MASTER the damn thing. I only had a requirement before choosing it: it had to be fun!
So, what language did I choose? None other than LOLCode.
I know what’s going through your mind now. “Why the eff is this guy even thinking about learning a new language?”, “useless”, or even “OH HAY I CAN HAS CODEZ?”. There’s a reason for that.
I tend to browse lolcats whenever I need a bit of extra motivation, romance, feeding or even inspiration. So, whenever I look at bits of code that read:
-
HAI
-
CAN HAS STDIO?
-
VISIBLE "HAI WORLD!"
-
KTHXBYE
or even
-
ON CATURDAY
-
IM IN YR BED
-
I IZ SLEEPIN!!10
-
VISIBLE "Z!"
-
KTHX
-
KTHXBYE
I can’t stop thinking that it’s PURE GENIUS (right before bursting into tears of laughing so hard). So, for starters, I’m going to try to understand a Brainfuck compiler written in LOLCode. Want to tag along?
-
HAI
-
BTW This is a BrainFuck interpreter written in LOLCode
-
BTW It accepts as input a BF program, followed by a "!", followed by any input to the BF program.
-
BTW Since BrainFuck is turing-complete, this proves that LOLCode is too
-
-
I HAS A INSTRUCTIONS BTW Array for BF instructions
-
I HAS A IPTR BTW Pointer to first empty element in INSTRUCTIONS
-
IPTR R 0
-
I HAS A LOOPZ BTW Array of loop start/end addresses
-
I HAS A LOOPSTACKZ BTW Loop stack for building the above two
-
I HAS A LSPTR BTW Pointer to first empty element of LOOPSTACKZ
-
LSPTR R 0
-
-
BTW Read in BF instructions, terminated with "!"
-
IM IN YR CODE
-
GIMMEH IPTR IN MAH INSTRUCTIONS
-
-
BOTH SAEM IPTR IN MAH INSTRUCTIONS AN "[", O RLY?
-
YA RLY
-
LSPTR IN MAH LOOPSTACKZ R IPTR
-
LSPTR R SUM OF LSPTR AN 1
-
OIC
-
-
BOTH SAEM IPTR IN MAH INSTRUCTIONS AN "]", O RLY?
-
YA RLY
-
I HAS A STARTPTR
-
LSPTR R DIFF OF LSPTR AN 1
-
STARTPTR R LSPTR IN MAH LOOPSTACKZ
-
STARTPTR IN MAH LOOPZ R IPTR
-
IPTR IN MAH LOOPZ R STARTPTR
-
OIC
-
-
BOTH SAEM IPTR IN MAH INSTRUCTIONS AN "!", O RLY?
-
YA RLY
-
GTFO
-
NO WAI
-
IPTR R SUM OF IPTR AN 1
-
OIC
-
IM OUTTA YR CODE
-
-
BTW Variables for BF's tape
-
I HAS A LTAPE
-
I HAS A RTAPE
-
I HAS A LPTR
-
LPTR R 0
-
I HAS A RPTR
-
RPTR R 0
-
I HAS A CELL
-
CELL R 0
-
-
BTW Reset instruction pointer to start
-
IPTR R 0
-
-
BTW Start interpreting
-
IM IN YR LOOP
-
I HAS A THING
-
THING R IPTR IN MAH INSTRUCTIONS
-
-
BTW Move tape head right
-
BOTH SAEM THING AN ">", O RLY?
-
YA RLY
-
LPTR IN MAH LTAPE R CELL
-
LPTR R SUM OF LPTR AN 1
-
BOTH SAEM RPTR AN 0, O RLY?
-
YA RLY
-
CELL R 0
-
NO WAI
-
RPTR R DIFF OF RPTR AN 1
-
CELL R RPTR IN MAH RTAPE
-
OIC
-
OIC
-
-
BTW Move tape head left
-
BOTH SAEM THING AN "<", O RLY?
-
YA RLY
-
RPTR IN MAH RTAPE R CELL
-
RPTR R SUM OF RPTR AN 1
-
BOTH SAEM LPTR AN 0, O RLY?
-
YA RLY
-
CELL R 0
-
NO WAI
-
LPTR R DIFF OF LPTR AN 1
-
CELL R LPTR IN MAH LTAPE
-
OIC
-
OIC
-
-
BTW Increment
-
BOTH SAEM THING AN "+", O RLY?
-
YA RLY
-
CELL R SUM OF CELL AN 1
-
OIC
-
-
BTW Decrement
-
BOTH SAEM THING AN "-", O RLY?
-
YA RLY
-
CELL R DIFF OF CELL AN 1
-
OIC
-
-
BTW Output produces numbers instead of ASCII characters
-
BOTH SAEM THING AN ".", O RLY?
-
YA RLY
-
VISIBLE CELL!
-
VISIBLE " "!
-
OIC
-
-
BTW Input doesn't work because we can't convert characters to integers
-
BTW Oh well, it doesn't stop it being turing complete
-
-
BTW Start of loop
-
BOTH OF BOTH SAEM THING AN "[" AN BOTH SAEM CELL AN 0, O RLY?
-
YA RLY
-
IPTR R IPTR IN MAH LOOPZ
-
OIC
-
-
BTW End of loop
-
BOTH OF BOTH SAEM THING AN "]" AN DIFFRINT CELL AN 0, O RLY?
-
YA RLY
-
IPTR R IPTR IN MAH LOOPZ
-
OIC
-
-
BTW End of program!
-
BOTH SAEM THING AN "!", O RLY?
-
YA RLY
-
GTFO
-
OIC
-
-
IPTR R SUM OF IPTR AN 1
-
IM OUTTA YR LOOP
-
KTHXBYE
Fun times await.
How to build your on-demand video site with PHP
Wednesday, June 4th, 2008Browsing DZone today I found an interesting article from IBM’s developerWorks site, which supposedly teaches you how to build an on-demand video site with CakePHP.
My first thought was that, being Belacena built with the same technology, I could learn one thing or two and make it run 10x as fast (OK, maybe not, but you get the point). So, I signed in (AKA got a user and password from BugMeNot), and started reading part 2 (part 1 covers the basics about video optimization for the web, creating the database tables, and extracting CakePHP). Let’s just say I was disappointed, because I have big expectations on everything that comes from IBM.
So, in sum, their 3 part tutorial teaches how to scaffold in CakePHP, tweak the views a bit, and that’s pretty much it. You can see the resulting site here. If you feel that article is worth reading, you can start here.
If you have any suggestions on more advanced topics, let me know, and I’ll consider writing about it.
Rails, migrations and validations
Friday, May 9th, 2008Well, it was a busy day for me in Ruby on Rails land. After picking up on a few new requirements for a project I’m working on (Agile Development rocks eh?), I’ve decided to refactor a lot of the existing codebase to make it a bit cleaner and, while I was at it, migrate the project to Rails 2. It wasn’t hard or very time consuming, thanks to Ben’s tips, since it took me about 20 minutes to go through the offending lines.
One of the things I was able to extract from that refactoring was validations. Some models have to validate data that can’t be validated by a simple regular expression, and since these validations are specific in Portugal, I thought I’d share them with the portuguese Ruby on Rails developers. You can grab them following the link in the end of the post. After dropping the file on your project’s lib folder, all you have to do is add the following line to your environment.rb file:
-
require 'validations'
And you’ll be ready to go. Documentation is included in the file (in Portuguese). Feedback is appreciated.
