Leo's Journal

Ramblings from around the world

No Internet, no fun

Once again, for some random reason, I have been disconnected from Princeton’s wireless network. It feels as if part of me was missing. I mean half my life happens one way or the other through the internet: from reading the news and working to keeping in contact with my friends and family it all happens on the cloud. In any case, regardless of what it means for me to have Internet (or not) is not that relevant. What shocks me though is the way Princeton manages it’s network. I mean, to begin with in order to get connected a paper application must be filled out giving a bunch of data (some of which could actually be accessed automatically if this was done by a computer program – like the MAC address). Not only that, but it takes the university an average of 4 days to process each application! I mean really?! I am tempted to think that I’m spoiled with MIT Internet services, but still a paper application??!! I had never seen such an inefficient system in the era od information and I even less expected it from a tier 1 university in the US.

Besides that, not much has changed. I’m still studying like crazy to learn some of the contents tought at the seminar I’m at and in general enjoying the summer in this afkwardly technological place. Hopefully tomorrow (or in four days) it will get fixed. Until then (hopefuly soon).

Filed under: Computers, Internet, Life

Automate and Conquer

Today my friend Alan came to me with a problem: “Suppose you have 100 students in a math seminar and you to give two books to each student as the seminar ends. Furthermore, each ranks all the available books. The question is, how do you find an efficient way of distributing the books so that overall ‘happiness’ is maximized”. Also, you want to  have a sense of “fairness” so that no student gets screwed over with two books that he didn’t want at all.

During the past four years, the seminar in which I work at has proceeded to solve this problem by manually assigning books to kids and hopefully, after many hours of tedious work, get to a distribution that is reasonable. Alan and I decided that there had to be a better way and started to think on a systematic solution for this problem. After a while of thinking, it came to me. This problem could be though as a Linear Program! – meaning that it could be solved using a standard algorithm, the simplex algorithm (used heavily in  hedge funds, operation research and many other fields). Somehow after almost failing 6.046 – the de facto algorithms class at MIT – I was thinking about this problem without all the pressure of a grade using what I had learned and was enjoying it a lot.

The interesting part is that, not only were we dedicated to solve this problem using an algorithmic solution, but we were also competing to see if it was worth it. Wendy, another staff member, was not too much a fan of our approach. Instead, she decided to attempt solving the problem once again, manually. In order to compare which of the two approaches was best, we set the following rules of comparison: we would compare the total time it would take to solve the problem 5 years in a row (the seminar happens annually). What this means is that we would take whatever time it took Wendy to solve the problem manually and multiply it by five. However, for our approach, we would consider the time it took us to come up with a solution and add it to five times the time it would take a computer to execute the code. The idea was that, once the code was developed it could be reused as is in the following years.

We spent part of the night brainstorming, learning about .mps (an extremely old file format inspired by punch cards that apparently is used as a standard input for Linear Program solvers), looking for code that we could reuse from the internet, etc. At around 2 a.m. we finally did it. It took us around 5 hours to develop the whole thing and it took the computer 10 milliseconds to execute it. It worked amazingly. Wendy, on the other hand spent about two and a half hours to come up with a solution which did not compare with ours in terms of overall “happiness”. You do the math: 5 hrs+5*(10 milliseconds) < 5*2.5 hrs = 12.5 hrs.

I know, I’m such a nerd. I just think its really awesome to tell the kids at the seminar that they got assigned books by a simplex. Well, I think is enough nerd-ism for a post. Cool though. See you ’round.

Filed under: Computers, , , , , , , , , , , , , , , ,

Computer Headache

I think by now I should just stopped mentioning how much work I’ve had in the past weeks. Ok, I’ll complain once more, it’s a LOT. Even today, Sunday, when it is supposed my weekend break, I still have to grade tests, prepare classes and organize course materials. I spent most of the day doing this and just about when I was about to call it a day, my computer started to behave funny. It first said that it had no internet connection, although there was clearly other people connected to the wireless network.

The system started to feel slower and unresponsive at which moment I decided to restart the computer. When it came back on, nothing worked. Certain windows just wouldn’t open, I couldn’t connect to the internet and the Finder (Mac OSX‘s equivalent of Windows Explorer) was completely irresponsive. Restart again, and again, and again. I tried a bunch of commands done at restart that are sometimes recommended to troubleshoot macs. Nothing.

I was starting to freak out. All my work – and all the work of everyone else at this seminar – is stored in my computer. I had done a backup a week ago and was about to do one today. After around 2 hours of fighting with my laptop, I gave up. I though “Well, I’ll go tomorrow to the Apple store and hopefully they’ll fix it”. Went upstairs to my room and was about to go to sleep. I actually hadn’t even had the opportunity to blog today, so I thought of writing all of this in my iPhone – sort of a pain. I said to myself, I need to try one more time. I turned the laptop on I though “YOU HAVE TO WORK NOW”. For no real good reason, this time it worked. I have no idea what was different, or what caused it to behave so weirdly. The good thing is that I have now backed up everything. I will still bring it to be checked. Now, there is one even weirder thing. When I finally was able to operate my laptop normally again, I opened the trash folder and there was a directory called “Recovered Files”. Inside it was one file which I don’t remember ever throwing away. It was a song – I don’t have any music stored in my laptop. I don’t know how it got there, maybe some error while using Pandora, or something. It was labeled “FlashTmp”. I don’t even know the artist who plays it – if you know please send a comment telling me. Whatever, I just know that I have a really horrible headache and I want to get to sleep. It has been enough for today. Good night.

Filed under: Computers, Internet, Music, Technology, , , , , , , , , , , ,

Understanding Disorder

Right now I am half way done with my summer job. I had worked in this program twice before, but unlike past years, this time my hob has involved much more logistics and organization rather than teaching “per se”. It all started by setting up a smart way of retrieving and formatting all of the documents produced, which I described in the article “Smart Latex Typesetting”. It was the first time for me to engage in such a big project.   As such I have learned tons of things, specially by looking at my mistakes. If I had to say only one thing of what I’ve learned: Organize EVERYTHING perfectly from the beginning – think of the unthinkable and prepare for it.
Although it might sound somewhat trivial, it is amazing how much what may appear as small details can potentially become huge pains to deal with if not tackled in a timely fashion. This is specially true when whatever you are doing will eventually be distributed to a public. In this case any bug left behind will reproduce exponentially and hunt you down. My project is puny compared to anything done by a software company, say, Firefox. Still just after finishing it, I can now barely imagine the level of organization and care required in order to maintain such complex systems. In the bottom line this is just a reflection of the mathematical fact that starting from a small environment (or a project, or anything) and keeping organized as it grows is a lot easier than trying to organize a big environment that is disorganized. I guess that I should start applying that same principle to my room :P .

Right now I am half way done with my summer job. I had worked in this program twice before, but unlike past years, this time my hob has involved much more logistics and organization rather than teaching per se. It all started by setting up a smart way of retrieving and formatting all of the documents produced, which I described in the article “Smart Latex Typesetting”. It was the first time for me to engage in such a big project.   As such I have learned tons of things, specially by looking at my mistakes. If I had to say only one thing of what I’ve learned: Organize EVERYTHING perfectly from the beginning – think of the unthinkable and prepare for it.

Although it might sound somewhat trivial, it is amazing how much what may appear as small details can potentially become huge pains to deal with if not tackled in a timely fashion. This is specially true when whatever you are doing will eventually be distributed to a public. In this case any bug left behind will reproduce exponentially and hunt you down. My project is puny compared to anything done by a software company, say, Firefox. Still just after finishing it, I can now barely imagine the level of organization and care required in order to maintain such complex systems. In the bottom line this is just a reflection of the mathematical fact that starting from a small environment (or a project, or anything) and keeping organized as it grows is a lot easier than trying to organize a big environment that is disorganized. I guess that I should start applying that same principle to my room :P .

Filed under: Computers, Internet, Life, Technology, , , , , , ,

Smart Latex Typesetting

Before I even start I will give a disclaimer: Today’s post is way more technical than those you have found thus far in this blog.

Almost anybody who is somewhat involved into science, especially mathematics,  is very likely to have ran across the Latex typesetting system. It is an extremely powerful and versatile markup language that allows for scientific (and non-scientific) formatting of documents.

I have been familiar to Latex for about five years already, however, since starting my job at Dallas I confronted the biggest Latex project I have ever been in. The program I am has 12 mathematics classes going on every day. Each day every class has at least one hand out, which in general is typed using Latex. However, these handouts are to be stored and later made into booklet containing all of them. The question is, what is the best way of doing this?

Well, the first solution to come into mind is to make a new latex file and copy/paste manually the code of each of the individual handout and then compile. This may work for small projects, however, considering that the program I am in lasts for 3 weeks, by the end of it we would have 180 handouts at the very least. That would take a while to do, not to mention the possibility of mistakes and the tediousness.

Another alternative is to use the command \input. It should be as simple as making a ‘master file’ where the command \input is called to get the code of all the individual handout files. However this solution is still not perfect. Whenever we call \input, the whole code of the handouts is read by the compiler and as soon as it reads the header commands of the handouts (\documentclass{article}, begin{document}, etc) it will start complaining. So this solution, as is, would require to manually delete the header declarations of each handout. For my project this is still not feasible.

You may think “there should be a better way” – I thought this myself – and fortunately there is. First let’s make clear what we want: We want to make Latex files that compile normally separately, however we also want to be able to use a ‘master file’ where we can call all of them and also compile without problems. After asking my friends and googling for around this past 2 days I have finally solved it. Here it goes:

We will have three main files: header.tex, footer.tex and master.tex. I will explain all of what I will write – just follow on me for now:

In header.tex we will write the following:

\providecommand{setflag}{\newif \ifwhole \wholefalse}
\setflag
\ifwhole\else
% Here you write your declarations, usepackages, etc
\begin{document}
\fi

The footer.tex file should say

\ifwhole\else
\end{document}
\fi

The master.tex file should have

\input{head.tex}
\renewcommand{\setflag}{\newif \ifwhole \wholetrue}
\input{handout-1.tex} //put as many inserts here as needed
\renewcommand{\setflag}{\newif\ifwhole \wholefals}
\setflag
\input{footer.tex}

And finally, individual handout should look like

\input{header.tex}
% handout text here
\input{footer.tex}

So let’s explain what’s going on. First of all look a the header.tex file. We have \providecommand which checks if a command already exists, if it does, it leaves it alone otherwise it defines it as specified. . Here we provide the command ‘\setflag’ and defines a new boolean variable by calling ‘\newif \ifwhole’. This boolean (‘whole’) can be set to true or false by calling \wholetrue or \whofalse respectively. In this case we set it to true. Conditional statements can be written using this boolean using the command

\iswhole
%Type here what should be executed if 'whole' is true
\else
%Type here what should be executed otherwise
\fi

With this we can explain how individual handouts compile. The compiler reads \input{header.tex} goes to the file and reads \providecommand{setflag}. Since \setflag does not exists, it creates it. Afterwards \setflag is run (as defined by \providecommand) creating a boolean ‘whole’ and set to false. After we get a conditional statement, but since ‘whole’ is false, we get to the else and read all of the declarations, definitions and \begin{document}. Similarly, the compiler reads the footer.tex in the individual handouts.

Now, when we run the master.tex file the \input{header.tex} works the same as before. However, just after reading header.tex the compiler encounter \renewcommand which overrides the definition of \setflag. From this point on \setflag is set to define the boolean variable ‘whole’ and set it to true. Afterwards, when the input{handout.tex} are read the first thing the compiler sees is \provide{seflag}. The catch is that now \setflag is defined, so \providecommand doesn’t do anything to it. Next, \setflag is run returning a boolean ‘whole’ with value true. Hence this time the conditional statement goes through the first clause (instead of the else). This way all of the declarations, headers, begin{document} and all of those things that the compiler would complain if it were to read them in the middle of the document, are magically skipped. The handouts as I defined them here will compile both individually and inside the master.tex file with no hiccups. That’s how it works.

Sorry, again, to most of you for the technicality of this post. However this might prove extremely useful for the more scientifically oriented out there. If you have a big project this may help to save tons of time. Hope you liked it and let me know if you have any troubles implementing it. As for me, I need to go sleep as I have to wake up early tomorrow to continue my work. See you ’round.

Filed under: Computers, Technology, , , , , , ,

WordPress is WHAT?!

As you may recall from a recent post, I have been in contact with many of my Chinese friends through Skype. It came to me that starting a Blog in Chinese would be a great way to practice my written Chinese besides keeping in contact with my friends and sharing my opinions with them. I also mentioned tha I was originally afraid of not being able to contact my friends using Skype due to the Golden Shield Project but later realized that this is (apparently) not a problem (although I wouldn’t be surprised if they were actually letting calls but monitoring all of them).
It turns out that my fears were justified, not by Skype, but by WordPress. Yes, apparently the Chinese government has blocked all of the domains hosted by WordPress. So my Chinese friends won’t be able to access neither the blog 魏立宁的日记 nor this one.Although this sucks, I think I can still manage to make a blog that they can acces, I just need to find the righ place to host it. Currently I have a bunch of options and I will be working to set it up these days. As soon as its don, I’ll let you guys know. See you ’round.

As you may recall from a recent post, I have been in contact with many of my Chinese friends through Skype. It came to me that starting a Blog in Chinese would be a great way to practice my written Chinese besides keeping in contact with my friends and sharing my opinions with them. I also mentioned that I was originally afraid of not being able to contact my friends using Skype due to the Golden Shield Project but later realized that this is (apparently) not a problem (although I wouldn’t be surprised if they were actually letting calls but monitoring all of them).

It turns out that my fears were justified, not by Skype, but by WordPress. Yes, apparently the Chinese government has blocked all of the domains hosted by WordPress. So my Chinese friends won’t be able to access either the blog 魏立宁的日记 nor this one. It’s a pity that such a good blogging software is totally prohibited by a country. Although this sucks, I think I can still manage to make a blog that they can access, I just need to find the right place to host it. Currently I have a bunch of options and I will be working to set it up these days. As soon as its done, I’ll let you guys know. See you ’round.

Filed under: Computers, Technology, , , , ,

The Technology in our Hands

I’ve had an idea stuck in my mind for a while and I thought it would be interesting to share it and check out other points of view. It all originated from the following situation: Imagine you had a computer with no operative system installed. Actually imagine it to be a computer that just came fresh out of factory. It has absolutely no software in it (no drivers, no BIOS, nothing). The question is, how do you make this device into a working computer? Well, many people would say “simple, connect it to another computer and install the BIOS and everything else the same way it would be done with any other computer that just came out of a factory”. Great, but wait a minute, does that mean that the only way to get this computer working is resorting to an already working computer? Apparently this so (to the best of my knowledge).

What strikes me about this situation is that, even though we may know the exact inner workings of the computer at hand, without another computer to assist us we are confronted with an impossible task. If this is so, how did computers appear in the first place? Well, originally digital computers were manually programmed, in a way we used an already working computer – our brains. Punched cards were used as the main source of input and output of information. So the way the story goes is that, we created computers and manually programmed them using punched cards. Later on when new computers came along, we used the older – already programmed – computers to help us program the new computers. This continued in the same fashion to the point at which we are faced today. It is impossible to manually program a modern computer due to the vast complexities found in it. Only existing computers can handle such a thing.

The way I see it, its as if we had given a piece of life to computers. People created them using nothing but wires, silicon and metal. But it was until the genius of geeks who sat down and manually programmed the earliest computers that these stopped being inert pieces of junk and became useful tools. These computers later reproduced there “piece of life” into newer computers and son on. Every computer today has traces of the original manually programmed computers. This can only make me think about slightly apocalyptic thoughts. If after a 3rd World War all computers were destroyed, even if some survivor knew the exact workings of modern computers, he would still have to go back and start by using punched cards to slowly move on to more advanced computers, etc. It is actually very likely that somewhere in some secret bunker there are instructions of how to restart computing technology using punched cards… weird. What do you think?

Filed under: Computers, Technology, , , , , ,

Delivery Fail

For the last two days I have been waiting for an important package to be delivered to my house. I kept tracking the package online checking how it flew from Shanghai, Chicago, Memphis and slowly but surely getting closer and closer to its destination. I couldn’t wait. Finally the day came, I woke up, followed my usual routine, but in unlike other days I was particularly aware of the door. In any moment the package would get here. The time went by and nobody showed up. I checked online to see where the package was now and to my surprise -BAM- the page said “Delivery Exception: There was nobody to sign the package” WHAT?!?! I had been home the whole time!!! There was not even a trace of a delivery driver anywhere near my door! Apparently they are supposed to leave a door-tags or something of the sorts in case I am not home.

After calling the company, they assured me that another driver would reattempt to deliver anytime between 2p.m. and 7p.m. (this meant that I pretty much had to be at the door during the whole 5 hours in between as you never know when these sneaky drivers might show up). This time in lieu of a door-tag I posted a piece of paper at the door: It had my data, signed by me and said that I was at home and they rang the doorbell I would be there promptly. I waited and waited and waited. Nothing… I checked again online and there it was once again: “Delivery Exception: There was nobody to sign the package“. O.k. I must be going crazy… I was at the door the WHOLE TIME! There was no door-tag, nothing to prove that they had been there. There could have been only one explanation – are these drivers Ninja Drivers? Maybe they practice some obscure delivery-martial-art. They make no sound – they leave no traces. This drivers are so fast nobody has ever seen them. Or at least nobody has survived to tell the tail. I mean, seriously?!?!

By no means I want to degrade the hard work of any delivery driver. However, how hard can it be?  1) You go into the door, 2) Ring the bell (this part is important); 3) Wait; 4) Repeat steps 2 and 3 until you have waited a reasonable amount of time, say, 2-3 minutes; 5) If nobody shows, leave a door-tag (this is also important)  and continue to deliver the next package.

Pretty complicated stuff huh? You would even expect this (or any other algorithm following this fashion) from experts in delivery whom you are paying a premium for getting your packages on time. To top it all off, the next day I got a call from an angry-toned representative explaining me that they would not deliver the package to my house again because, according to them, they had already tried ‘too many times’. WHAT?! So I payed extra for getting this package fast and now I have to drive 50 minutes out of Boston to pick a package that is now almost three days delayed? The best was that she made it sound as if I had been completely careless and this was all my fault. This was getting more and more bizarre by the second.

In any case, I had to put myself together, ignore all of the nonsense and call once more and explain what was going on. At least the person I talked was more reasonable and told me they would send the package once more. This time I left no chances for any driver, ninja-driver or any mythical creature to get in between my and this package. I sat in the doorsteps to wait -these people were testing how much I wanted this package, they were testing my determination- I didn’t move, nor flick, I didn’t go to the bathroom -nothing- I just waited.

A couple of hours swung by and I saw it coming -FINALLY- it was here. I couldn’t believe my eyes. I got the box, signed it and ran to open it. After all, I finally had it. All these days I had been waiting for my new laptop, a brand-new MacBook Pro. I wouldn’t necessarily say that it was worth all of the delivery pain, including the adventures fighting the ninja-delivery drives and all… but in a way… it was :P . Having it with me made me forget all of what I went through to get it. Here it is:

Now I am more motivated than ever to find cool stuff to write here (and also in my Chinese blog). But for now I’m just too excited about my new lappy to think about anything else exciting to say today (in any case it’s hard to find anything more exciting than a story involving ninja drivers). Tomorrow once the “new” factor has worn off a bit I will write something more meaningful. See you then.

Filed under: Computers, , , , ,

Follow

Get every new post delivered to your Inbox.