Monday, August 27, 2012

Session and cookies

Aurum uses Pyramid. I am not familiar with Pyramid but it's very flexible because unlike Django, Pyramid does not come with a User system by default when you activated the setup. It just doesn't. You can create a User model and use the Session abstraction built into Pyramid (and the Auth policy that comes with Pyramid).

As a Django user, I don't need to worry about how session was managed. It just works for each user. Now I knew I have to care about it.

I still don't know much about the whole architecture, but basically I was using pyramid-beaker and added a key to session. But the next time I access session and asks to read the key, it raises KeyError.

I made this post, and I am not embarrassed to show. I actually have several Stackoverflow accounts.

Why is that? As the answer pointed out, to get the same session back, it needs to have the same cookies. That's pretty much the way to identity "oh so I see you again."

Then I asked myself: what if I lose that cookies or cookies changed? Wouldn't that mean I will lose the session information? My requirement is to store user actions into the session / cache so I can retrieve them on demand.

When a user runs the code, we do short-polling at the moment to requests "build, run, generate report". Each of these steps will require / make some ids or status code. I need to keep track of these things. I can't afford asking GCS "oh by the way can you please give me that build_id again?" Instead, I can go right into session / cacher and ask "given this task id, what's the build_id if any?"

What about use memcache and forget about session. Make a key/value pair in memcache that uses the task id and when we request the resource could look like /aurum/api/task/status/<task_id>

That's how we do it currently. But that's really bad. Any one with this task id can actually query the status. If I knew my classmate is really smart, and I knew he did it right. I am going to steal that task id as he's running it, and then put it in my javascript, then when I make the next request, it will blindly asks for <my-friend-task-status> because the task id is his. What's next? When it's completed, I get all green on my test output and a big fat 100 for my homework!!!!

Session is the way to go. With cookies, there is a barrier over getting that cookies. I am not sure whether copying a cookies over to a new browser will actually invalidate the cookies. It might? But with session, I can guarantee that anyone who looks that this session and using the data from this session are the user who created this session last time.

So I am sticking with Session, although I still prefer to use Memcache because it looks more professional? I don't know.

invalid date format in specification: "2011-08-25 00:00:00.000000000Z"

This is an annoying problem with the outdated Ruby installation on many of the Debian/Ubuntu apt-get.

Invalid gemspec in [/var/lib/gems/1.8/specifications/tilt-1.3.3.gemspec]: invalid date format in specification: "2011-08-25 00:00:00.000000000Z"

One fix is to upgrade to ruby1.9 but I don't want to. What if it messes up my other configuration? A quick way is this:

sudo sed -i 's/ 00:00:00.000000000Z//' /var/lib/gems/1.8/specifications/*

This solution is taken from here. But every time when you install a new gem (pip package, in Python's world), the problem will appear. But it's safe to do it again.


openshift folks are helpful

So recently I was looking for free PHP instance online, similar to Heroku if possible. Then I found RedHat's OpenShift.

After signing up, I created a Wordpress right away. The interface looks simple and awesome actually. Here are two screenshots of the creating application console:
http://imgur.com/a/5CDyE

The OpenShift folks were very helpful, even though I was a free user. The IRC channel is not dead. People actually can respond, although they would point you to some blog posts about how to do things (written by the community / OpenShift people). But it's great.

The command-line client `rhc` looks cool too. It takes care of the ssh stuff for you. If you want to access the database for example, you could port-forward it and run a command-line option to call phpmyadmin, and the actual GUI runs very smoothly.

You also get to accessed to the local machine. I guess that's the trend these cloud companies are doing.

It also provide Jenkins! Oh wow.

I recommend it if you are considering a mini site.


Here are links I want to keep:

https://openshift.redhat.com/community/faq/how-can-i-test-my-database-connection-from-my-local-client
https://openshift.redhat.com/community/get-started

Wednesday, August 22, 2012

Chef's python cookbook

I am quite impressed with the Chef's Python cookbook. Initially I thought that python_pip does not come with the ability to install packages using requirements.txt.

It turns out it does:
[19:19] <jameson_> Guest94181: you can use the "option" parameter to say "-r"
[19:19] <jameson_> and then you can pass in the requirement.txt as the package name
In another word,s, in your recipe you can write something like this:

python_pip "/var/lib/natrium/requirements.txt" do
  virtualenv "/path/to/virtual-env/"
  action :install
end
 
I was about to write a new resource in ruby like this:

File.open('requirements.txt').each(spe="\n") do |line|
        if line.start_with?("#")
                print "i got a bad one \n"
                print "#{line}"
                print "\n continue \n"
        else
                # line.index("#") != 0
                print "#{line}"
        #if line.index("#") != 0
                print "#{line}"
        end
end

This snippet above is just to show you how you do readlines in ruby, for given content as the one shown below:
Django==1.2.1
#Pinax==0.9a1
PyYAML==3.10
Pygments==1.5
certifi==0.0.8
chardet==1.0.1
decorator==3.3.2

What the actual cookbook will do is this:

---- Begin output of /var/lib/shared/graphyte-virtualenv/natrium-env/bin/pip install -r /var/lib/natrium/requirements.txt ----

The whole Python cookbook is very useful. It can create virtualenv as specified.

Tuesday, August 21, 2012

Why blogging again? I am too old for this.

I touched HTML the first time when I was about eight, nine years old in Hong Kong. I am twenty-one now, and I can you that I suck at front-end development. I can barely write any good Javascript function without constantly looking up on Mozilla Developer Network, Stackoverflow or basically, everything from Google. I can't make any HTML layout with HTML or CSS because I just don't have the fundamental skill baked into my head. I tried, but I found them boring. I still do, although I love the enticement when I see that beautiful webpage I created.


Nonetheless, here I am, in my fourth year of computer science degree, I am still picking up so many tools and skills that are considered fundamentals by computer science education standard. The first time I started using version control was when I started working in my lab.

That's about 8 months ago.

I have to admit that in the last eight months I've learned so much that no one was able to teach me in any form. Ask me how to deal with a legacy system and fix bugs as seen? Ask me how to debug a system? Ask me how to become a duck-tape programmer rather than a perfect all-rounded programmer? How to scalable? Understand why testing is important? You have to pick up these things from doing a real project that isn't done under your own blanket.

Recently I watched Google I/O - The Myth of the Genius Programmer and these two Googlers were so damn right about "real genius" are very rare. The point is a good working environment is crucial to success. One interesting part was "don't hide your commits". It's so true that hiding commits are indication of perfections. The only reason why I have to erase the history if my lab work ever get open-sourced is to remove hardcoded credential.

The talk was really funny. I love it. It taught me, or I should say, remind me of who I should become. I admit that I don't like people entering my comfort zone and tell me "you are wrong, stop, stop, stop, you know nothing about X,Y,Z." That hurts because I am so desperate to become a good and skillfull programmer. I want my presentation to have credibility. It is so sad to see "oh wow, it's August and I haven't done much."

Who to blame? What to blame? Me? The new people who came to the lab? Or all the problems I ran into?

Let's not blame. Let's just say I am still learning, and I really need to manage my time better. I mean sleep early and really get to work more, because with school I am going to have less free time to work on everything at once.

Oh by the way, why should I be blogging? I am too old. Because I want to document what I am learning. I always want to make a blog about it, but I always feel so tired to update blog.... let's hope I won't give up, for the last time.