Install the Elasticfox Firefox Extension for Amazon EC2: http://developer.amazonwebservices.com/connect/entry.jspa?externalID=609
Follow Arope's instructions for setting up Amazon EC2 accounts and Elasticfox. I used the alestic/ubuntu-8.04-hardy-base-20080628.manifest.xml machine image.
In Elasticfox, right-click on your running instance and select "Copy Public DNS Name to clipboard". Then, paste that address in your browser. You should see Apache's "It works!" page.
In Elasticfox, right-click on your running instance and select "SSH to Public Domain Name"
I wanted to replace items in a list based on a specific condition. For example, given a list of numbers, I want to replace all items that are negative with zero.
At first, I thought of something like this:
mylist = [111, -222, 333, -444]
newlist = []
for item in mylist:
if item < 0:
item = 0
newlist.append(item)
mylist = newlist
print mylist
Which gave me the expected results:
[111, 0, 333, 0]
Then I tried using Python's enumerate
(see my
previous example) built-in function
to replace the item in-line. This seems to be a more elegant ...
I've finally added automatic code highlighting to my blog. It
uses Pygments to do the
syntax highlighting and
Beautiful
Soup to find all the <pre> blocks
to highlight. I still write my blog posts in HTML, but now
add a class attribute to my <pre>
tags to specify the Pygments lexer to use. For example,
for python code, I use:
<pre class="python">
import this
def demo():
pass</pre>
Which turns into:
import this
def demo():
pass
I bought James Bennett's book, Practical Django Projects about a month ago and it has good information about creating a blog ...
Read more...Here are some notes on some basic tasks dealing with users, groups,
and permissions on Ubuntu Linux. All these commands (except passwd)
are done as root.
If you are not root, prepend sudo to all the commands.
# adduser sofeng
$ passwd
# addgroup developer
# adduser sofeng developer
sudo power:/etc/sudoers:
%developer ALL=(ALL) ALL
# chown -R sofeng:developer mydir
Here is a simple Python example using recursion to navigate a nested Python data structure. Each node in the data structure contains 0 or more children. In this simple example, I look at each node and print the "text" indented according to the nesting level within the data structure.
Update 2008-09-15: Nihiliad posted an improvement to my example in the comments. It is much simpler. I have updated my example below.
data = {'count': 2,
'text': '1',
'kids': [{'count': 3,
'text': '1.1',
'kids': [{'count': 1,
'text': '1.1.1',
'kids': [{'count':0,
'text': '1.1.1 ...Here are some quick notes on using the
Digg API
with a Python script. Note, there is a
Python
toolkit for Digg but I just used urllib2
and the Digg API endpoints for the sake of simplicity.
I wanted the output in JSON format so I specified the response type as JSON. To decode JSON directly to a Python data structure, I used simplejson.
Here is a simple example which returns the JSON output for
the Digg story
Dell
vs. Apple: This Time it's Personal
which has a "clean title" of
Dell_vs_Apple_This_Time_it_s_Personal.
#!/usr/bin/env python
import urllib2
APPKEY ...Open ID is a new technology that allows you to use one set of login credentials to access many sites. This is good because you don't have to remember yet another password or go through yet another Web 2.0 community registration process.
Simon Willison wrote a simple, clear
explanation on how to
turn your blog in to an OpenID. I followed his instructions, and now
http://www.saltycrane.com/ is my new Open ID! I look forward to
putting it to good use. (In case you're wondering, yes, I am planning to add
Open ID support to ...
As I install new python packages, I sometimes see instructions
which say something like "check out the code, and place it somewhere
on your Python path". These are very simple instructions, but
since it is not automatic like a Windows installer, or Ubuntu's
package management system, it causes me to pause. Where on my
Python path should I put it? I could put all my packages in
random places and update my PYTHONPATH environment variable every time. I also
thought about putting new packages in Python's site-packages
directory. This is probably a good option. However, I tend to ...
I've been using the Django 0.96 release for this blog, but I've been thinking about switching to the SVN trunk version since it is recommended by the Django community. Django 1.0 alpha was released a couple weeks ago, so now seems like a good time to migrate.
Here are the changes I had to make. There were suprisingly few changes required-- probably because I'm not using a lot of the Django functionality. For a complete list of changes, see the Backwards-incompatible changes documentation.
Note, I am using trunk revision 8210. (2 weeks post Alpha).
Here are my notes for moving my wubi Ubuntu install to a dedicated ext3 partition. I used the Loopmounted Virtual Partition Manager (LVPM) to do the transfer. From the webpage:
The Loopmounted Virtual Partition Manager allows users to upgrade their existing Wubi or Lubi installation to a standard Ubuntu system by transferring all data, settings, and applications from the original install to a dedicated partition. The advantages of upgrading using LVPM are better disk performance and reliability, and the ability to replace the original operating system with Ubuntu.
My hard disk had only 1 partition containing ...
Read more...$ tar -zxvf gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e.tar.gz
$ mkdir ~/src/python/gnip-example $ mv gnip-gnip-python-028364a70bd40dda0069ecdd3e7f6fff23bb985e/*.py ~/src/python/gnip-example
~/src/python/gnip-example/gnip-example.py:
#!/usr/bin/env python
from gnip import *
gnip = Gnip("yourgniplogin@email.com", "yourpassword")
for publisher in ["twitter", "digg", "delicious"]:
activities = gnip.get_publisher_activities(publisher)
print
print publisher
for activity in activities[:5]:
print activity
$ python gnip-example.py
twitter [derricklo, 2008-08-01T22:49:59+00:00, tweet, http://twitter.com ...
Here is a quick post on how I added support for multiple users on my blog.
~/src/django/myblogsite/myblogapp/models.py:
import re from django.db import models from django.contrib.auth.models import User class Post(models.Model): author = models.ForeignKey(User) title = models.CharField(maxlength=200) slug = models.SlugField(maxlength=200, prepopulate_from=['title'], unique_for_month='date_created') date_created = models.DateTimeField(auto_now_add=True) date_modified = models.DateTimeField(auto_now=True) tags = models.CharField(maxlength=200, help_text="Space separated.") body = models.TextField() body_html = models.TextField(editable=False, blank=True) lc_count = models.IntegerField(default=0, editable=False) def get_tag_list ...Read more...
aws
(4)
bison_flex
(1)
blogger
(4)
c
(10)
cardstore
(5)
colinux
(2)
concurrency
(8)
conkeror
(2)
cygwin
(17)
dell
(3)
django
(31)
eclipse
(30)
emacs
(18)
email
(1)
error
(11)
gnip
(1)
json
(1)
keyboard
(3)
linux
(31)
matplotlib
(5)
mercurial
(3)
openid
(1)
personal
(4)
preferences
(4)
pyqt
(18)
python
(88)
rails
(1)
ratpoison
(3)
recursion
(1)
rsync
(3)
ruby
(2)
sql
(10)
subversion
(4)
twisted
(5)
ubuntu
(33)
untagged
(7)
urxvt
(3)
vxworks
(26)
wmii
(3)