Friday, January 15, 2010

New Year's Python Meme

So I'm a bit late to the party, but there's meme going around python developers to discuss what they've done/discovered in the past year in a q/a manner. So here's mine.

1. What’s the coolest Python application, framework or library you have discovered in 2009 ?


Would have to be Twisted. I've avoided Twisted for a while now since I was always told that it'd hurt your head if you tried to get into it and that it wasn't very pep8 friendly, but it turns out it has some pretty good tutorials (the Finger tutorial) and that a lot of the stuff is useful right off the bat (such as the chatserver).

Non-Python:
The Lua language. It's not that it's all that cool, it's just another language and not as nice as python, but it's pretty cool in that it lets you create mods for games pretty quickly (in this case Demigod.. which is a great game that needs some help at this point).

2. What new programming technique did you learn in 2009 ?3. What’s the name of the open source project you contributed the most in 2009 ? What did you do ?
New programming technique would have to be constructor patterns that I learned from a very good Flash developer and the Refactoring book that he introduced me to. I mainly learned it by working through the refactoring example with my girlfriend on a automation project she had for her work.

The open source project I contributed the most to would have to be the PIL and python-payflowpro and only in the sense that I submitted bug reports (tho I submitted work around code for the issue with PIL).

For 2009, I worked entirely on two large web projects. One an online trivia game, and the other a credit offset reseller site. The credit offset site was fantastic in that the code was completely developed with TDD and had about 10-15 tests per function. I didn't start a single class or function without having the test code written beforehand. The trivia game had the potential to be fun, but I had to make accommodations for stupid managers and constant changes to what was wanted. I simply should have said 'No' more often, but it's hard to do when your excited and want to make everything cool.

4. What was the Python blog or website you read the most in 2009 ?

I read Planet Python which is an aggregation blog of a bunch of well known Python bloggers... so I guess I've been reading lots of blogs. Also, lots of StackOverflow.

5. What are the three top things you want to learn in 2010 ?

3 things for python in 2010?
  1. Hadoop and map/reduce. I'm already familiar with the concepts, but I'd like to get some actual experience with it
  2. pyGTK and pyGame. I'd really like to get into gui programming.. even tho cli rules.
  3. Ctypes.. I've been meaning to read up or do a tutorial on ctypes for a long time.
Non-Python:
  1. How to make mods for games (in particular, Demigod). For a long time I've played games and kept notebooks on what was cool, what was stupid and what I would do differently in the hopes that I would eventually learn how to create a mod of a game. I've been investing a lot of time in games and there's a lot of stuff that I'd like to tweak. Demigod is very open to modding with the Lua language so I'd like to finally start and complete a mod for a game.

Monday, January 4, 2010

Decemeber 2009: my month of quiescent perseveration

We repeat ourselves. The mind perseverates. The road is rutted and grooved, and beside the road are familiar ditches.
-- Eric Maisel

Monday, November 30, 2009

github, ssh config file and ssh-agent

Github makes use of ssh-keys for checking out your stuff via git. I also have several different keys and store them with different names such as github_rsa or some such. In order to get this to work, you have to create a config file that stores the location of the private key.

For github, in the .ssh/ directory, create a file `config` and enter in the following:
From github's help page:

Host github.com
User git
Hostname github.com
PreferredAuthentications publickey
IdentityFile path-to-private-key


In several situations I've had to set up ssh keys for remote machines that only provide me with terminal access. Thus I keep getting pestered to enter the passphrase for the ssh key. ssh-agent takes care of having to keep entering in the passphrase.

After setting up the ssh-keys do:
eval `ssh-agent`; ssh-add ~/.ssh/github_rsa

It will then ask for the passphrase the one time when it adds the key to the agent, and then wont ask again.

The 'let go' command

I was recently let go from the place where I plied my craft (I left on ok terms). The only real issue I had was that the computer I used there was a company computer, and during the time I had spent there, I had done things such as purchase stuff on amazon.com, save passwords to various email accounts in browsers, etc. So to rectify this situation and ensure that nobody using the computer after me had access to my data, I rebooted the machine in recovery mode (this was an ubuntu box) and ran

find /home/tfdml/. -type f | xargs shred -fu ; rm -rf /home/tfdml/ ; shutdown -h now

then gathered my belonging's and left. Note that I could have just as easily switched to an alternate terminal with ctrl-alt-f1 and ran the command there.

This ensured, at least to my level of paranoia, that all my personal information was secure. Now, all documentation, code and notes were all stored in the company repo, so it's not like I was being malicious and destroying all the work I had done for the company. This removed all of my own personal information from the machine without having to reformat the drive or any other such drastic measures and allowed for the company to quickly turn the machine around for another worker to use.

(Edit: It turns out this command didnt work as well as I planned as apparently it took quite some time to run. Eventually one of the other dev's there saw the machine was on and simply turned it off since there was nobody using it anymore. This allowed the guy who got the computer after me access to some of the files in my account. In retrospect, I should delete all the huge files (anything over a gig, music directory, vm images) before running this command and ensuring that the command is only going to operate on a set of files that amount to at most a gig.)

Tuesday, November 17, 2009

"so that" vs "such that"

So that or such that? Found a nice article that covers these issues, as well as a few other cool grammar bits for mathematicians.

From the article:

Here are the definitions.

so that

  1. In order that, as in I stopped so that you could catch up.
  2. With the result or consequence that, as in Mail the package now so that it will arrive on time.
  3. so ... that. In such a way or to such an extent that, as in The line was so long that I could scarcely find the end of it.
From dictionary.com

such that

  1. adj : of a degree or quality specified (by the "that" clause); their anxiety was such that they could not sleep. (dictionary.com)
  2. A condition used in the definition of a mathematical object. For example, the rationals can be defined as the set of all m/n such that n is nonzero and m and n are integers . (mathworld.wolfram.com)

Examples

  1. We require x to be a rational number so that mx is an integer for some m. [Correct]
  2. We require x to be a rational number so that 3x is an integer. [Incorrect; should be such that 3x is an integer.]
  3. Let H be a discrete subgroup of the Lie group G so that G/H is compact. [Incorrect --- not all discrete subgroups of Lie groups have compact quotient; this is from the Annals of Math., 107, p313.]
  4. Let N and N' be submodules of a module M such that N contains N', so that N/N' is a submodule of M/N'. [Correct! From Steps in Commutative Algebra.]

Briefly, if omitting the "that" from "so that" renders the sentence nonsense, then it was already nonsense, and you should have used "such that". You won't find "so that" among lists of commonly misused expressions because only mathematicians commonly misuse it. Probably the error arose from the influence of German on American (mathematical) English, since the two are not distinguished in German.


Mathlish

Wednesday, November 4, 2009

da Vinci quote

Those who are enamored of practice without science are like a pilot who goes into a ship without rudder or compass and never has any certainty where he is going. Practice should always be based upon a sound knowledge of theory.

Wednesday, October 28, 2009

Displaying and Configuring Character Sets in MySQL

Display all character sets:

show variables like 'character_set%';

Change the character set for a table:

ALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name;

BUT with the caveat that
The CONVERT TO operation converts column values between the character sets. This is not what you want if you have a column in one character set (like latin1) but the stored values actually use some other, incompatible character set (like utf8). In this case, you have to do the following for each such column:

ALTER TABLE t1 CHANGE c1 c1 BLOB;
ALTER TABLE t1 CHANGE c1 c1 TEXT CHARACTER SET utf8;

The reason this works is that there is no conversion when you convert to or from BLOB columns.

The process to completely change all mysql's character sets from latin-1 and make this garbage:
(using the show variables command from above)
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | latin1 |
| character_set_connection | latin1 |
| character_set_database | latin1 |
| character_set_filesystem | binary |
| character_set_results | latin1 |
| character_set_server | latin1 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
look beautiful like this:
+--------------------------+----------------------------+
| Variable_name | Value |
+--------------------------+----------------------------+
| character_set_client | utf8 |
| character_set_connection | utf8 |
| character_set_database | utf8 |
| character_set_filesystem | binary |
| character_set_results | utf8 |
| character_set_server | utf8 |
| character_set_system | utf8 |
| character_sets_dir | /usr/share/mysql/charsets/ |
+--------------------------+----------------------------+
involves simply adding the following to the [mysqld] section of your my.cnf (or /etc/mysql/my.cnf if you like, and are on a debian based machine)

collation_server=utf8_unicode_ci
character_set_server=utf8

and adding the following to BOTH the [client] section AND the [mysqld] section:

default-character-set=utf8


This is simply in case you cannot go back and re-compile mysql using
./configure --with-charset=utf8 --with-collation=utf8_general_ci