Category Archives : General Computing


ANTLR4: So awesome it makes Java look good

I have been trying to write my own programming language off and on for about 5 years now. That doesn’t mean I have spent 5 years on a single project. Only that I have been toying with the idea and educating myself for that amount of time. Writing your own language is kind of the Holy Grail of computer science. Well, writing a language that is actually useful. Over the years, my experience in Ruby, PHP, C/C++, Python and even LISP, has informed my idea of what a good language would look like. Note I didn’t say perfect language. There is no such thing. I have come to believe that all languages are good in some way or another, and bad in other ways. Emotionally I like Ruby, and I like C. The elegant syntax of Ruby makes you happy to program, while the Do-Anything attitude of C makes it the ultimate language. I have been looking at Java( due to it’s cross platform nature ) and have to say at first I hated it. Now I hate it less. The number one reason I hate it less is ANTLR. I love the code generated by ANTLR because it looks like code that a human being would actually write. It’s very dense, but it’s alive. It’s hackish and clever. I have been following along the book The Definitive ANTLR4 Reference. This is a first time for me. Normally I, quite wrongly, just jump in and get it done. This time I am going to RTFM. […]


Lexical Analysis: You should use FLEX…right?

It’s been a hobby of mine for that last few years to try to create my own programming language. Don’t ask why, I just want to. Over the years I have tried and failed multiple times. This is mainly due to the fact that I am a self taught programmer with no CS background, or Math background, or any real education. When you set out to learn how one makes a programming language you will receive a series of answers similar to this: Use flex to generate a lexical analyzer. Use Bison to generate a Parser Forget both of those and use ANTLR To understand what you need to do to create a programming language, you will need to understand that in general all programming languages have a set of modules that take turns with the users input (i.e. the script). The Lexer The Lexer, or Scanner is the first component of a programming language. It reads a stream of characters and groups them together into meaningful parts. The Lexer adds no semantic meaning to the stream. Lexers create “meaningful” tokens. They generally, but not always, do not create whitespace tokens, they “ignore” them in the sense that they do not lead to the emission of a token, but they “use” them to delineate tokens. Flex has a simple interface for creating a lexer, a simple Scanner will look like this: If we save that as test.y and run: flex test.y cc lex.yy.c -o example -lfl ./example We can then start entering in some text. […]


Apache2/MySQL on Ubuntu Configuration

Once you’ve installed apache2 and mysql on your server, you might want to try these configuration changes to make it perform a bit better: In /etc/mysql/my.cnf key_buffer = 16K max_allowed_packet = 1M thread_stack = 64K table_cache = 4 sort_buffer = 64K net_buffer_length = 2K And in Apache2′s config, /etc/apache2/apache2.conf, find the section for MPM prefork if yo have it and: StartServers 1 MinSpareServers 3 MaxSpareServers 6 ServerLimit 24 MaxClients 24 MaxRequestsPerChild 3000 The above are just some things to try if you encounter a situation where apache is using too much memory, or the same for mysqld.


Never Again! Backing up your rails .sqlite3 dbs

Well, with mysql, it’s pretty hard to overwrite your dbs, but with sqlite, it’s real easy. I did this, luckily I only lost about a days worth of work, but nevertheless, I have instituted a new rule for sqlite3 dbs: Hourly backups. Here’s the script: #!/bin/sh D=`date +%H` cp -f /var/www/app/db/production.sqlite3 /var/www/fapp/db/production.sqlite3.bak.$D


Deploy Ruby on Rails to the Desktop (Ubuntu), as a Debian Package 1

Introduction to deploying Rails Applications to the Desktop Some things you’ll learn in this series of articles: How to distribute a Rails App to an Ubuntu Desktop How to Compile a custom Ruby installation to avoid conflicting with an existing Ruby install Get automatic updates to all users for free by virtue of being a Debian Package How to organize a build environment to make and distribute all Debian packages with a single command. How to build your own custom dumb browser in QT C++ (QT Creator now includes the ability to generate an HTML5 App, it didn’t when I started building Salor…) This is not a step by step tutorial, it’s a broad discussion, though I plan to make an example video with a hello world style app at a later date. Deploying Rails applications to the desktop, specifically unbuntu, though I plan to figure out how to do it with windows very soon, turns out to be much easier than I ever thought. While deploying Rails apps can kind of suck in comparison to other types of web-applications, it’s hardly any more difficult than any other kind of executable deployment. The reasons for using Rails for a desktop application are pretty obvious, ease of development, ease of maintenance, and Ruby can pretty much do anything you need it to do. For instance, in our application we use ruby to connect to a receipt printer and print out receipts, reports, labels and barcodes and more. Before you deploy a Rails app, you might give […]

salor point of salor

Ruby on Rails Session in Models: Not So Evil Actually 3

I just finished reading this post from m.onkey.org on how to put your session into your models. First off, I love this guy, and his site, and most of what he says, but I’ve had it up to here with this nonsense. I also kind of felt a little dissed by the PHP comment. I understand he was joking, and it was kind of funny, PHP programmers are NOTORIOUS for using $_SESSION to store EVERYTHING. At the same time, as Voorhaus says, all comedy is truth and pain, and the truth is that PHP programmers do that, and the pain is that many programmers coming to Ruby and Rails feel alienated by that community because they are so opinionated (And not always right). Rails is kind of Opinionated by design, and that’s okay, but more often than not, the Rails and Ruby community is uneccessarily sadistic in its treatment of contradictory opinions, they have a “my way or the highway” kind of speech when in fact, you can do it anyway you want, and all they are doing is looking like douche bags for treating you as a sub-human for having a contradictory opinion. As I see it, at the core of the above issue, sessions in the model, is global variables, and the irrational fear of them. Phear Globalz There is some practicality in not depending on global variables, especially when you are TALKING about programming. When you are doing it, it’s another story. They can theoretically be the source of problems. Yes I […]


RubyGems 1.2+ Index not found, gems fail to install/update slow/sluggish

I had this problem while running sudo gem install anything, like sudo gem install sqlite3-ruby or what not, albeit while running Ubuntu in VirtualBox. The fix that worked for me was editing /etc/resolv.conf and using google’s public dns nameservers of 8.8.8.8 and 8.8.4.4 Now it works fine… Go figure.


HowTo: C Function Pointers for a Linear Search, void star pointer trick, comparison using memcmp, string replace

Well, I was messing around in C again today, sometimes I just love C, it’s a fun language when you understand it, which I really don’t, but am beginning to grok it. Anyway, I was checking out a little tutorial on C and saw this cool little trick that I thought I would share. It’s the beginnings of a generalized linear search algorithm. #include #include #include int linearSearch (void * key, /* pointer to the data to compar*/ void * base, /* base of the data*/ int n, /* number of elements */ int size, /* quantum of data*/ int ( * cmpfunc)(void * e1,void * e2, int size) /* comparison function */); int simpleCompare(void * e1, void * e2, int size); int main ( int argc, char *argv[]) { int array[5]; /* a simple array of ints*/ int i; for (i = 0; i < 5; i++) { array[i] = i; /*load the array so we can search*/ } int s = 24;/* this is the search value, change it around to test */ /*we pass in the addresses of s, the array, which is a pointer already, the number of elements, the sizeof the data, and the address of the function*/ if (linearSearch(&s, array, 5, sizeof(int), &simpleCompare) != -1) { printf(“%i was found in array. \n”,s); } else { printf(“%i was not found in array.\n”,s); } } int linearSearch (void * key, /* pointer to the data to compar*/ void * base, /* base of the data*/ int n, /* number of elements […]