Archive for the Category » General «

Friday, April 23rd, 2010 | Author: ranok

It’s been quite a while since I’ve posted here, and to my devout readers I apoligize. As many of you know, this has been my last semester of my undergraduate studies, so I have been very busy over the past few months. This post will hopefully act as a dump of what I’ve been up to and what I will be doing until my next post.

Things I did:

  • Developed a method for calling parts of functions to minimize/obfuscate programs
  • Worked with Ryan on OSP to get a web based cluster management system integrated into the cluster administration page
  • Played with return-to-libc attacks and got them working on the latest version of Ubuntu Linux

Things on the horizon:

  • Working full-time for AIS
  • Traveling to Iceland for 3 weeks
  • Working on a computer security textbook
  • Running a marathon in August

It is very weird to me to think that today is the last day of classes for me as a traditional full-time student. I’ve been going to school since I was 5 and it is very weird to think that come August I will not be returning to the classroom as my primary past-time. I am excited to travel and get away from the normal swing of things for a while to reflect on the new changes in my life, and excited to begin working, especially due to the extra leisure time after work.

Peace and chow,

Ranok

Wednesday, October 14th, 2009 | Author: ranok

Today in my Advanced Concepts in Operating Systems class I led the discussion on the Mnesia paper from PADL’99, while this paper has numerous typos it does do an excellent job highlighting the features and advantages of Mnesia. For those of you who are unaware, Mnesia is a distributed, fault-tolerant object DBMS written in Erlang. One thing about Mnesia that I have found to be lacking is a tutorial written for the lay person from the ground up, this gap I intend to try and fill. This multi-segment tutorial assumes you have knowledge of Erlang, and the basic  concepts of manipulating data with DBMSes, other than that, I hope to provide enough information and code to demystify a fairly complex system. However, I still am on the road to mastery, so if I make any errors, or you have any tips for improvement, I’d be happy to add them in.

To get started, start up the Erlang shell (erl) with a name, I will use -sname foo in the following examples. Below is a transcript of starting up and creating a disk-based

ranok@orion:~/Desktop$ erl -sname foo
Erlang R13B01 (erts-5.7.2) [source] [smp:2:2] [rq:2] [async-threads:0] [hipe] [kernel-poll:false]

Eshell V5.7.2  (abort with ^G)
(foo@orion)1> mnesia:create_schema([node()]).
ok
(foo@orion)2> mnesia:start().
ok

The most important call made here, create_schema, takes a list of nodes to replicate the schema table to on disk. You can add additional disk-based nodes or ram-based copies later (we’ll get to the details later). After you’ve created the schema (this will make a folder for all the Mnesia table data), you can start the application with the start function.

Now that we have the database running, we need at least one table to store the data in, we will start with a very simple record to just store simple key/value data. The nice thing about Mnesia, is that the data we store can be pretty much anything, from a simple atom to a function. We will start learning the basics from the mnesia_test module, which I have uploaded here.

The first few lines of the module start off like any Erlang code, a module declaration, what functions to export, including the QLC (Query List Comprehensions) include file (you may need to find it for your system) and a record definition:

-record(data, {key, value}).

Which will define our record for the table also named data. In the function setup_and_start/0, we tie in what we already went over with the create_table function, which in our case looks like

mnesia:create_table(data, [{disc_copies, [node()]}, {attributes, record_info(fields, data)}])

The create_table function has a number of options, the most basic of which we will deal with at the moment: the name of the new table, where and how the table will be stored and what fields the table has (this code used the record_info() function to pull those out of the data record for us). Now that we have our table, we need a way to get the data in and out of it.

Many databases provide the ability for multiple queries to be joined into one transaction to be executed atomically. Mnesia is no different, but for the most part, all queries are executed through the transaction manager (there is a dirty interface which will be discussed later), this makes working in a distributed environment much easier. The way to perform a transaction in Mnesia is to pass a fun to the mnesia:transaction() function that will atomically run.

The actual function to enter data (both insert and update) is write(Record). We wrap this into the mnesia_test:insert(Key, Val) function displayed below:

insert(Key, Val) ->
Record = #data{key = Key, value = Val},
F = fun() ->
mnesia:write(Record)
end,
mnesia:transaction(F).

To now retrieve this data back from the database, the read function is now used, the read function takes two arguments: the table name (in this case, data) and the key to retrieve. The mnesia_test retrieve function wraps this nicely for us, and is shown below:

retrieve(Key) ->
F = fun() ->
mnesia:read({data, Key})
end,
{atomic, Data} = mnesia:transaction(F),
Data.

mnesia:transaction will either return {aborted, Reason} or {atomic, Rows}, where Rows is a list of all the retrieved data. If the key we tried to retrieve could not be found, then it will return an empty list.

Say however, we want to search the table for certain values that are not the index of the table. For that there is the matching functions, the simplest of them is the match_object whose usage can be seen here:

search(Val) ->
F = fun() ->
mnesia:match_object(#data{key = '_', value = Val})
end,
{atomic, Data} = mnesia:transaction(F),
Data.

As you can see, simply fill in all the values that are known and that you want to search for, and use the ‘_’ unmatched value for all the other values. This transaction will return the same forms as the read transaction.

There is another method for filtering through Mnesia tables, which is very similar to the list comprehensions builtin to Erlang which is called QLC. The QLC version of the above function is below:

search_qlc(Val) ->
F = fun() ->
qlc:eval(
qlc:q(
[X || X <- mnesia:table(data), X#data.value == Val]
))
end,
{atomic, Data} = mnesia:transaction(F),
Data.

What the query here is doing is is returning a list of Xs where every possible X comes from our data table, and X#data.value == Val. This should be very intuitive for those of you who are familiar with list comprehensions. What qlc:q() does is form a query handle (much like a function object) which gets evaluated by qlc:eval() inside of our transaction object. Again, this will return the same values from mnesia:transaction.

Well, that about covers the basics of Mnesia, you now should be able to setup Mnesia on your computer, create a table and insert/retrieve data from it. In the next installment, we will look at distributed Mnesia and the dirty interface, which provides faster queries by bypassing the transaction manager. After that we will put all of what we’ve learned into creating a system that will take advantage of Mnesia and give a pseudo real-world problem a fitting solution. Please check back soon for the next installment!

Peace and chow,

Ranok

Category: General, Technical  | Tags: , , ,  | Leave a Comment
Saturday, September 05th, 2009 | Author: ranok

Now that I’ve had a chance to settle into my new apartment above Misty Hollow on Market Street, and I have all the needed utilities, I thoughts I take a break and reflect on my first two weeks of my senior year. My schedule this semester has me in class for 11 hours Monday and Wednesday, and practically without class the other week days (I do have class every few Saturdays). This schedule is requiring some work to get used to, either I’m feeling rushed to make it to my next class and keep everything straight (philosophy to statistics) or I’m wondering what to do with all my spare time. I have however found a few things to keep myself occupied on my off days, I’m working for Clarkson as a campus photographer, shooting lots around the area for brochures, the website or mailings. This is a great way for me to practice and improve my photography skills and work with a professional! I will update my Flickr when I have some great shots, so keep checking it out! Of course I’m also still the co-director of COSI, which has a large amount of interest this year, and I’m hoping for good things to turn up. naturally I’m still working on my baby, OSP (a post on that soon). Lastly, I’ve joined the Potsdam Rescue Squad, and am enrolled in the NY state EMT course, which I am enjoying, and excited to become a more useful member as my knowledge grows.

Well, I think that about covers all in my life for the time being.

Peace and chow,

Ranok

Category: General, Personal  | Tags: , , , , ,  | Leave a Comment
Monday, June 08th, 2009 | Author: ranok

As many of you know, I usually spend my summers in northern Ontario paddling the beautiful lakes and rivers. Since I will be leaving for Canada in a few days, I figured I should post an entry letting my many (ha!) readers know that I will be off until late August. This means that progress on my projects will stall until I return and get situated, and any emails will not be responded to for a while.

I hope that everyone has a wonderful summer, and can find some time to relax and enjoy nature’s beauty when we are all surrounded by man made structures. I plan on taking many pictures during my summer sabbatical and am excited to swap stories in the fall.

Peace and chow,

Ranok

P.S. Seitan tastes much better than it looks!

Tuesday, March 24th, 2009 | Author: ranok

I admit it, I’ve finally jumped on the Git bandwagon. After toying with SVN and Darcs, I was convinced when I saw a screen-cast about branching and merging and how it makes the kind of random, skitzo programming that I do very easy and very maintainable. I started using it at work to keep track of some files as a test and finally bit the bullet and signed up for a GitHub account. Once I had gotten setup, I made a few repositories to upload some code I had made for my high school senior project, code that I haven’t looked at in years and probably never will again. Then I decided to share something a bit more exciting, Wiki Wide Web’s bleeding edge source code. After some quick review to ensure I cleared the code of any hard coded passwords, I committed the source.

One thing I like about putting your code on a site like GitHub is that it guilts you into cleaning it up. If you hope that people are going to see it, then you feel slightly pushed to make an effort to clean it up. That pressure lead me to add some installation instructions and a make file for the Firefox extension, and clean up some code.

Peace and chow,

Ranok