7 comments | Leave a comment
Sameer Siruguri
My Journal
26 December 2008 @ 02:03 am
20 December 2008 @ 02:54 am
Backups are good, like vitamins and anti oxidants.
mysqldump --result-file <filename> --host=<hostname> --user=<username> --password=<password> --create-options --compact <dbname>
See, was that hard? Why don't you back your database up more often? (Or should that be "backup your database"?) Wouldn't it save a whole lot of headaches if you did?
And oh, if you've been a good person and backed your database up (I am pretty sure it isn't "backupped your database") then here's your Christmas gift: how to restore it.
Login to MySQL and run the following
CREATE DATABASE <databasename>
Logout, and then run this via the command prompt:
mysql --host=<hostname> --user=<username> --password=<password> < <backup filename>
Oh, here's the help page for Mysqldump on MySQL.org, if you are curious about more options.
mysqldump --result-file <filename> --host=<hostname> --user=<username> --password=<password> --create-options --compact <dbname>
See, was that hard? Why don't you back your database up more often? (Or should that be "backup your database"?) Wouldn't it save a whole lot of headaches if you did?
And oh, if you've been a good person and backed your database up (I am pretty sure it isn't "backupped your database") then here's your Christmas gift: how to restore it.
Login to MySQL and run the following
CREATE DATABASE <databasename>
Logout, and then run this via the command prompt:
mysql --host=<hostname> --user=<username> --password=<password> < <backup filename>
Oh, here's the help page for Mysqldump on MySQL.org, if you are curious about more options.
04 December 2008 @ 03:53 pm
Here's how you perform CGI magic in Python. First, you import the cgi module, that's simple enough:
import cgi
Then, it gets hairy.
form=cgi.FieldStorage()
FieldStorage()! Sounds like the armaments division of a Communist-era Hungarian military unit --- Magyar veni Field Stőragesi ki Léniva Toszőr. Or something like that.
It gets a little less complicated after that, but not by much. These Hungarians are twisty characters:
import urllib
if form.has_value('q'):
print "The query is %s" % urllib.unquote(form['q'].value)
Urk. Not form['q'], not form['q'].value, but urllib.unquote(form['q'].value)
Damn you, Communism.
import cgi
Then, it gets hairy.
form=cgi.FieldStorage()
FieldStorage()! Sounds like the armaments division of a Communist-era Hungarian military unit --- Magyar veni Field Stőragesi ki Léniva Toszőr. Or something like that.
It gets a little less complicated after that, but not by much. These Hungarians are twisty characters:
import urllib
if form.has_value('q'):
print "The query is %s" % urllib.unquote(form['q'].value)
Urk. Not form['q'], not form['q'].value, but urllib.unquote(form['q'].value)
Damn you, Communism.
01 July 2008 @ 10:03 am
It's tough to figure out what combination of keywords needs to go into the title, so that people who are facing this problem I just solved, can find this webpage on Google. I hope the one above works.
The issue I had was sending an URL parameter that was constructed from user input. My first thought was to use the setAttribute() function in Javascript to set the value attribute of the FORM's text INPUT tag, and create an onClick event that called the function with the setAttribute() call in it.
Problem 1: It didn't work in a very mysterious way on FF3 (I didn't even bother checking on IE*). My input text box had a default value set. If I simply clicked Submit, the setAttribute() worked correctly. When I changed the value in the text box via my browser and clicked Submit, the value attribute still did change but get this --- the browser sent the unchanged value attribute in the GET call! Weird. So I fixed this problem by creating a hidden form INPUT tag whose value attribute I constructed from that of the text INPUT tag's value. How's that for weird browser/JS complications, eh?
Problem 2: This ingenious solution didn't work when I tried accessing the page on the IE version on my Windows CE installation on the HTC Touch I possess. Bah. I scratched my head and then changed the setAttribute() call to a "dot" reference to the value property --- document.forms[0].url.value, where url is the parameter I am passing to my CGI script.Voila! Ça marche!
The issue I had was sending an URL parameter that was constructed from user input. My first thought was to use the setAttribute() function in Javascript to set the value attribute of the FORM's text INPUT tag, and create an onClick event that called the function with the setAttribute() call in it.
Problem 1: It didn't work in a very mysterious way on FF3 (I didn't even bother checking on IE*). My input text box had a default value set. If I simply clicked Submit, the setAttribute() worked correctly. When I changed the value in the text box via my browser and clicked Submit, the value attribute still did change but get this --- the browser sent the unchanged value attribute in the GET call! Weird. So I fixed this problem by creating a hidden form INPUT tag whose value attribute I constructed from that of the text INPUT tag's value. How's that for weird browser/JS complications, eh?
Problem 2: This ingenious solution didn't work when I tried accessing the page on the IE version on my Windows CE installation on the HTC Touch I possess. Bah. I scratched my head and then changed the setAttribute() call to a "dot" reference to the value property --- document.forms[0].url.value, where url is the parameter I am passing to my CGI script.Voila! Ça marche!
28 June 2008 @ 09:11 pm
Struggling now with conversion between POSIX time and the date/time objects on Python. Here's the simple magic that's needed to get a datetime object that corresponds to the time right now. Note that the datetime module provides the following objects, date, time, timedelta and datetime. Each behaves differently and has to be separately imported.
And these modules are different than the time module, which is essentially what you will need to interface with POSIX times.
>>> from datetime import datetime
>>> import time
>>> datetime.fromtimestamp(time.time())
This returns a datetime object that looks like this: datetime.datetime(2008, 8, 14, 17, 20, 29, 780911) So for example, for printing out the date in YYYY-MM-DD format, use the expression returned by this function:
>>> d=datetime.fromtimestamp(time.time())
>>> # Note also that the above statement can be written as date.today()
>>> "%d-%02d-%02d" % (d.year, d.month, d.day)
Now play around getting other dates:
>>> from datetime import timedelta
>>> yesterday=d-timedelta(days=1)
I am not quite sure yet, why I have to import time --- is it platform/installation dependent? No idea...
>>> # To get the datetime object from the UTC time in the time zone (TZ) of your current locale:
>>> datetime.fromtimestamp(timestamp)
Going the other way is a little more complicated. Bah.
>>> dt=datetime.now()
>>> print time.mktime(dt.timetuple())
You need that time_struct returned by timetuple to get the POSIX goodness.
And these modules are different than the time module, which is essentially what you will need to interface with POSIX times.
>>> from datetime import datetime
>>> import time
>>> datetime.fromtimestamp(time.time())
This returns a datetime object that looks like this: datetime.datetime(2008, 8, 14, 17, 20, 29, 780911) So for example, for printing out the date in YYYY-MM-DD format, use the expression returned by this function:
>>> d=datetime.fromtimestamp(time.time())
>>> # Note also that the above statement can be written as date.today()
>>> "%d-%02d-%02d" % (d.year, d.month, d.day)
Now play around getting other dates:
>>> from datetime import timedelta
>>> yesterday=d-timedelta(days=1)
I am not quite sure yet, why I have to import time --- is it platform/installation dependent? No idea...
Working with UTC time formats
If you want to work with UTC time formats, you can easily switch back and forth.>>> # To get the datetime object from the UTC time in the time zone (TZ) of your current locale:
>>> datetime.fromtimestamp(timestamp)
Going the other way is a little more complicated. Bah.
>>> dt=datetime.now()
>>> print time.mktime(dt.timetuple())
You need that time_struct returned by timetuple to get the POSIX goodness.
28 June 2008 @ 08:35 pm
Struggled with these problems in Emacs today:
- Want my mini buffer history saved across sessions (answer: savehist-mode)
- Want my init.el to load from a different place than the default
- Forgot how to get font-lock turned on for any mode that supports it.
- Didn't realize savehist was already available in my XEmacs packages (should have first looked under the packages directory.)
- I knew I had to use load-file, but it wasn't clear that to use MS-DOS style pathnames, I needed to use the forward slash separator, othewise, the entire path was getting appended to some default initial directory.
- On the Emacs reference pages, you are advised to use global-font-lock mode, which doesn't exist (as a variable?) on XEmacs 21.4.21. I had to use the mode hook for Python --- (add-hook 'python-mode-hook 'turn-on-font-lock)
26 March 2008 @ 03:52 pm
Rumo And His Miraculous Adventures, Walter Moers (A review)
Moers' Rumo story, ostensibly the second in a series based in the fantastic world of Zamonia, is a friendly and captivating read. It's a thick book of about six hundred pages, but they go by fast --- when I was about five hundred and seventy through, I found myself contemplating the dwindling thickness on the right side of the spine with a tinge of sadness. Moers is an illustrator as well as a writer and his talent is displayed amply in the pages of the book --- carefully detailed drawings help you get a sense of the more ostentatiously hideous or bizarre characters in his world.
The book centers around Rumo, a "Wolperting," and his adventures from the day he's born to the day he achieves his heroic quest, which is to follow his "Silver Thread" to its end. The story is served up as pretty straight forward fantasy, without much in the way of moral conflicts or reflections on the "real" world. There are no conflicts, past or coming, with humans in any form, and most characters are, in some sense, either good or evil, without anything in between to encourage the reader to indulge in any soul searching about what the true nature of moral responsibility is. It's a fairy tale that rarely deviates from its desire to wrap everything up in a fairy tale ending.
What got me the most about the book was the exhaustive nature of Moers' story telling. Every landscape Rumo wanders through, every weapon he uses, every enemy he fights, and every organ he dismembers or is sprayed with the blood or bile of, is listed and labeled carefully. Where the names might not convey the nature of the being, a simple drawing finishes the job. Alongside the drawings and the invention of monikers for everything, Moers dabbles in cogitations on Death, Love, Evil, Knowledge and other sundry topics, though without ever taking more than a gentle swipe at the subject, rather as one would run a hot butter knife health-consciouly over a slab of butter to get the merest teaspoonsful, instead of finishing the entire block with by scooping out shovelfuls of it. What is more interesting is the matter-of-fact way in which Moers, and his characters, treat these issues -- many things in the novel simply Are, and taken as such, without any analysis to slow the characters' lives down. Moers slyly calls this attitude of his characters into question at the very end, through characters who take matter-of-factness to a rather amusing extreme.
Sometimes the attention to detail can meander into a stultifying style, something I last felt when reading the description of each new circle of Hell in the Inferno. Yes, people are wretched here, we get it, I would have liked to say to Dante, can we move on? But you know that moving on is precisely what Dante, and Moers, don't want you to do. You have chosen to be in this world, and you have to stick with it till the end. I guess this is also what Rowlings did with the soap opera minutiae of the Gryffindor teenagers' lives but somehow, Moers' exhaustiveness is different. It is like a charming defect, one that grows rather than grates on you. In fact when you realize that none of the characters (except a few that immediately meet a gruesome end at the very beginning) in Rumo are expected to behave in ways that are remotely human, contra, say, Rowlings, Tolkien, Pratchett, Pullman, Herbert, Clarke and Asimov, among others, you encounter the unexpected pleasure of not having to relate to the characters any more than you did with the animals in Aesop's Fables or Andersen's tales.
Rumo is a satisfying story of heroism, that leaves open the question of who true heroes are, and what combination of their destiny, talents and environments leads them to the successful ends of their heroic quests. Moers playful and yet weighty style is something I'm looking forward to reading more in the first of his Zamonia series, The Thirteen and a Half Lives of Captain Bluebear.
The book centers around Rumo, a "Wolperting," and his adventures from the day he's born to the day he achieves his heroic quest, which is to follow his "Silver Thread" to its end. The story is served up as pretty straight forward fantasy, without much in the way of moral conflicts or reflections on the "real" world. There are no conflicts, past or coming, with humans in any form, and most characters are, in some sense, either good or evil, without anything in between to encourage the reader to indulge in any soul searching about what the true nature of moral responsibility is. It's a fairy tale that rarely deviates from its desire to wrap everything up in a fairy tale ending.
What got me the most about the book was the exhaustive nature of Moers' story telling. Every landscape Rumo wanders through, every weapon he uses, every enemy he fights, and every organ he dismembers or is sprayed with the blood or bile of, is listed and labeled carefully. Where the names might not convey the nature of the being, a simple drawing finishes the job. Alongside the drawings and the invention of monikers for everything, Moers dabbles in cogitations on Death, Love, Evil, Knowledge and other sundry topics, though without ever taking more than a gentle swipe at the subject, rather as one would run a hot butter knife health-consciouly over a slab of butter to get the merest teaspoonsful, instead of finishing the entire block with by scooping out shovelfuls of it. What is more interesting is the matter-of-fact way in which Moers, and his characters, treat these issues -- many things in the novel simply Are, and taken as such, without any analysis to slow the characters' lives down. Moers slyly calls this attitude of his characters into question at the very end, through characters who take matter-of-factness to a rather amusing extreme.
Sometimes the attention to detail can meander into a stultifying style, something I last felt when reading the description of each new circle of Hell in the Inferno. Yes, people are wretched here, we get it, I would have liked to say to Dante, can we move on? But you know that moving on is precisely what Dante, and Moers, don't want you to do. You have chosen to be in this world, and you have to stick with it till the end. I guess this is also what Rowlings did with the soap opera minutiae of the Gryffindor teenagers' lives but somehow, Moers' exhaustiveness is different. It is like a charming defect, one that grows rather than grates on you. In fact when you realize that none of the characters (except a few that immediately meet a gruesome end at the very beginning) in Rumo are expected to behave in ways that are remotely human, contra, say, Rowlings, Tolkien, Pratchett, Pullman, Herbert, Clarke and Asimov, among others, you encounter the unexpected pleasure of not having to relate to the characters any more than you did with the animals in Aesop's Fables or Andersen's tales.
Rumo is a satisfying story of heroism, that leaves open the question of who true heroes are, and what combination of their destiny, talents and environments leads them to the successful ends of their heroic quests. Moers playful and yet weighty style is something I'm looking forward to reading more in the first of his Zamonia series, The Thirteen and a Half Lives of Captain Bluebear.
18 July 2007 @ 03:14 pm
From the NYT, here are 101 Summer Recipes, purportedly preparable in less than 10 minutes.
Bon Appetit.
Bon Appetit.
01 May 2007 @ 10:11 am
06 April 2007 @ 04:51 pm
I posted a question on Craig's List's Cooking forum, asking if I could avoid using aluminum foil for packing in a salmon fillet. I hate the idea of contributing to the creation of strip mines in developing countries, just so that my salmon fillets come out nice and juicy. On attempting to find alternatives on the web, I found that there is also the potential of toxic interactions between the metal and the meat. So what was I to do? There was precious little information on the web, actually, so I turned out Craig's List.
Here's what I asked:
I think the responses were both very instructive and amusing, so I decided to put them up on my blog. The original thread on the Craig's List forum is there right now, but might be deleted in the future.
Here's what the responses broke up as:
Alternatives to Using Foil
General Baking Tips
General Amusement

Here's what I asked:
- Parchment paper, or greaseproof paper. Does any one know if this works as well? How can I get it to seal in the food, as well as by crimping the aluminum? Also, is it as easy to get greaseproof paper at grocery stores, as it is to get foil?
- Using recycled aluminum: Where would I recycle my existing aluminum, in the Bay Area, and where can I purchase foil made from 100% recycled aluminum?
I think the responses were both very instructive and amusing, so I decided to put them up on my blog. The original thread on the Craig's List forum is there right now, but might be deleted in the future.
Here's what the responses broke up as:
Alternatives to Using Foil
- banana leaf, lotus leaf, or just use a metal lid to cover the item when it's cooking in a baking pan.
- get a steamer
- Parchment was a big winner:
- include using parchment covered by aluminum foil, which you can wash and reuse more easily if it is not in contact with the food. A casserole dish with a lid can work for some dishes.
- Yes, parchment can work. You just need to use the proper crimping method to keep the moisture in, with a tutorial on how to crimp properly.
- most food stores sell it though at ridiculous prices. Try to get it at restaurant supply stores, I've found it by the pound at a Mexican market in San Bruno at about 1/10 of what it costs at a supermarket. Here is a link to a step by step of how to fold it to make packets It's actually better than foil because it's not as good a conductor.
- For salmon try baking or wrapped in kelp. Kelp is the traditional salmon cooking wrap used by indigenous peoples up and down the West Coast and believe me, the flavors the kelp imbues really add to the fish.
General Baking Tips
- Ok, u don't NEED tight lids to bake or roast. a loose metal lid keeps the surface of the roast from getting too dark. It's not necessary to seal moisture in with roasting. Roast at lower temperatures, and do not overcook.
- For roasts, use a curved pot lid to prevent your turkey or ham from getting to dark on top. No need to tent your roasts with foil. We do a lot of roasts. Reserve drippings to make delicious gravy. If you have dogs, they also love pan drippings. Animal fat is a good supplement for dogs. Otherwise, birds and other wild animals enjoy animal fat presents, especially in winter. These can be chilled in a can, and distributed to wildlife in your area. We keep several roasting pans. I got mine from the second hand shop. Enamel Roasting pans were frequently included with a stove purchase. These pans are easy to find. There is a slotted rack, with the shallow pan underneath. These are GREAT for roasts as most of the fat falls thru the slots in the rack. This leaves a tender, succulent roast. Clean up is easy; pour drippings into a container and soak the pan in water overnight. I have a spot outside where the pan can soak for a day or two. Then just hose it off.
General Amusement
- but how will we prevent the aliens from stealing our brains? [Ed. I think the poster mean, "our salmon fillets."]
