Shortly after the initial release of the first iPhone SDK, Apple quickly followed it up with a second release just one week later that includes the interface builder.
Seriously:
http://developer.apple.com/
March 28th, 2008 — ruby
Shortly after the initial release of the first iPhone SDK, Apple quickly followed it up with a second release just one week later that includes the interface builder.
Seriously:
http://developer.apple.com/
March 12th, 2008 — ruby
I’ve moved to LA, finally! Hurray
Check out my recent works either at:
http://blog.xnot.org
http://guerillaimprov.com
http://iowest.com
http://sohotandsexyionlyneedoneshoweraweek.com
Oh yeah, and the iPhone SDK is OUT!
February 20th, 2008 — code, ruby, rails, tutorial
We’ve (Ron Evans and myself) have been working hard to release a new gem called ProcessorPool that uses EC2 and S3 to run your processor heavy-lifting!
Check it out at Blog @ CitrusByte
January 2nd, 2008 — code, rails
So, I got and interesting error when I installed and updated my rubygems on my slicehost account
sudo gem update --system
caused
uninitialized constant Gem::GemRunner (NameError)
The solution:
Add require “rubygems/gem_runner” on line 23
Change it from:
require 'rubygems'
Gem.manage_gems
To:
require 'rubygems'
require 'rubygems/gem_runner'
Gem.manage_gems
December 29th, 2007 — code, ruby, rails
Despite all other options, I decided to write a small project in Rails. But, this project is so small, there is really no need to store any information in a database!
Now, with Rails 2.0, it’s easy to accomplish!
The only real thing you have to do is add this line to your config/environment.rb:
config.frameworks -= [ :active_record ]
Cake!
I tend to remove the database.yml file, just to remind myself I’m not using a database!
November 14th, 2007 — Blogroll, code, tutorial
In writing a compiler, I’ve come across a sleek part of the standard c library that I just can’t help and a take a few minutes to write a blog post about it!
You can send any number of arguments to a method / macro that you want. It’s called Variadic methods and they have a crazy syntax. Here is a piece of code that I am using in the compiler. It’s super similar to the printf method (the printf method itself is a variadic method, if you’ve ever wondered…)
char *stringerize(const char *fmt, ...) {
char *buf = safe_malloc(sizeof(char)*BUFSIZE);
va_list args;
va_start(args, fmt);
if (args && strlen(args) > 0)
(void) vsnprintf(buf, BUFSIZE, fmt, args);
va_end(args);
return (buf);
}
Kind uninteresting, huh? I’ll show you a much more interesting one at the end of the post thatallows you to safely concatenate any number of strings.
The basic idea is that you define a method with the … syntax, such as
char *stringerize(const char *fmt, ...)
...
There are two two ways to access those variables.
One by one
First, you declare all your variables that you are going to use in the method. That has to be before accessing the list. Then, you start the list with
va_list args;
Make sure you don’t forget to declare the args as a list otherwise C will throw a fit.
Then, when you are ready to get the variables, call
va_start(args, fmt);
The second parameter is the last required argument in the command. You do need at least one required argument in a function. The same requirement does not hold true for macros, though.
Then, to get to the variable you call
va_arg(args, const char *);
The second parameter is the type you are expecting to come back. This gives C a heads up as to what to expect.
Then, when you are done and want to move on to the next one in the list, simply call:
va_end(args);
That’s it!
Accessing the variables all at once
You can either do this in a macro that would look something like (untested):
#define VARGS(...) fprintf(stderr, __VA_ARGS__)
// or
#define VARGS(fmt, args...) fprintf(stderr, fmt, args)
There are other ways as well, but those are the ones that stood out to me. In a method, you can do this as I had done in the example above. Just call list and all the arguments are accessible to you, right there in your shirt pocket!
And now, finally for the more important snippet that:
char *concat_commands(const char* str,...) {
va_list args; char *s; size_t held_memory = 100;
char *res = safe_malloc(sizeof(char)*held_memory);
if (res != NULL) {
char *new_pointer, *word_pointer;
va_start(args, str);
word_pointer = res;
for (s=str;s!=NULL;s=va_arg(args, const char *)) {
size_t len = strlen(s);
if (word_pointer + len + 1 > res + held_memory) {
held_memory = (held_memory + len) * 2;
new_pointer = (char *) realloc (res, held_memory);
if (new_pointer == NULL) { free(res); return NULL; }
word_pointer = new_pointer + (word_pointer - res);
res = new_pointer;
}
word_pointer = memcpy(word_pointer,s,len);
word_pointer = word_pointer + len;
}
*word_pointer++ = ' ';
new_pointer = (char *) realloc(res, word_pointer-res);
if (new_pointer != NULL) {res = new_pointer;}
va_end(args);
}
return res;
}
I hope this helps someone out there save a few hours and remember how cool C even in the midst of the ruby we all love so much. On that note, I urge you to look at the ruby interpreter source code. It’s a tad jumbled up, my guess is because there are a few people working on it, but it is sure damn sexy code. Thanks once again matz!
I’ll be back more in a week or so for more fervent posts after my compiler is done.
November 12th, 2007 — code, random, life, events
I’ve gotten a few emails about the lack of posts, so rather than reply to everyone, I figure I’ll set it straight:
I’ve been working on a compiler for class. Boom!
Something kinda cool though:
I can take code that looks like this:
extern void print_int(int x);
extern void print_string(char x[]);
int two[2];
int five[5], one;
void love_me(void) {
print_string("You love me, don't you?n");
}
void main( void ) {
two = 4;
love_me();
}
And turn it into code that looks like this:
.data
two: .space 8
five: .space 20
one: .space 4
_string_0: .asciiz "You love me, dont you?n"
.text
jal love_me
la $sp, 4($sp)
love_me:
# Function prologue
sw $fp, -4($sp) # save old $fp
sw $ra, -8($sp) # save return address
la $fp, 0($sp) # set up frame pointer
la $sp, -12($sp) # Update stack pointer and allocate stack frame
# Load variables on to the stack
la $t9, _string_0
sw $t9, -4($sp)
la $sp, -4($sp)
# Call the method
jal print_string
la $sp, 4($sp)
# Function epilogue
la $sp, 0($fp) # Restore stack pointer
lw $ra, -8($sp) # Restore return address
lw $fp, -4($sp) # Restore frame pointer
jr $ra # Return
jal main
la $sp, 4($sp)
main:
# Function prologue
sw $fp, -4($sp) # save old $fp
sw $ra, -8($sp) # save return address
la $fp, 0($sp) # set up frame pointer
la $sp, -12($sp) # Update stack pointer and allocate stack frame
li $4, 4 # Load _tmp_0
sw $4, -16($fp)
lw $4, -16($fp) # Load two
sw $4, two
# Load variables on to the stack
# Call the method
jal love_me
la $sp, 4($sp)
# Function epilogue
la $sp, 0($fp) # Restore stack pointer
lw $ra, -8($sp) # Restore return address
lw $fp, -4($sp) # Restore frame pointer
jr $ra # Return
print_int:
li $v0, 1
lw $a0, 0($sp)
syscall
jr $ra
print_string:
li $v0, 4
lw $a0, 0($sp)
syscall
jr $ra
When I get it done, I’ll open-source it and be back for more ruby joy! So stay tuned amigos!
November 2nd, 2007 — life
For those of you who don’t know, I have been working in Japan for the last two weeks. This is why the blog has not been updated in a while. Look for more content in the next few days and you shall find it!
For now… enjoy:
October 18th, 2007 — ruby
A thread-friendly, super-speedy Ruby web-application framework can now be built faster than heating a burrito!
read more | digg story
October 18th, 2007 — ruby
The blazing-fast, thread-safe micro-framework was released last week! A new Sinatra resource page has been put up here at http://www.xnot.org/sinatra/
Great for facebook apps and other speed-necessary web-apps. An entire application can be contained in one file!
read more | digg story