In most cases where you want to have a set of items on one row, you use floats to make things work. The truth is, floats are not meant to do this and they create all sorts of strange behavior, even in good browsers if you don't know what you're doing.
This article tells an interesting story on how you could use inline-block in all major browsers.
I want to add a few tricks to the mix I learned in the past few years.
Use case 1: You want a horizontal menu with more items than fit on the screen, but with a flexible width. Floats are not up to the job; They would just wrap to the next line instead of creating a scrollbar.
Use case 2: You want to center something vertically. You could use a mix of position and margin statements to achieve this, but not if you don't know the width and height of the object.
Since the elements are in the text flow now, we can apply text-specific CSS!
The first example is achieved by setting whitespace: no-wrap; and overflow: auto; which makes all the items stay on one line and create a scroll bar.
The second example is achieved by adding ‌ before the item to make it behave like a real line of text, that has vertical-align: middle; applied to it.
When I made PyMouse I did so because I had the idea to make an iPhone mouse. Today I had another crazy idea for moving the mouse: with a joystick!
It turns out it's quite easy to use the joystick via PyGame, so that is what I did this evening.
I plugged in the joystick from my brother, copied some PyGame example, imported my own PyMouse module and here is the result. You might need to tweak it a little to make it work with your joystick or game controller.
importpygamefrompymouseimportPyMousefromtimeimportsleep# edit this to reflect your joystick axis and buttons
action={'x':0,'y':1,'multiplier':3,'left':0,'right':1}pygame.init()j=pygame.joystick.Joystick(0)# first joystick
j.init()m=PyMouse()print'Initialized Joystick : %s'%j.get_name()state=[0,0]try:whileTrue:pygame.event.pump()sleep(0.1)# check if any button state has changed and change mouse state accordingly
ifj.get_button(action['left'])andnotstate[0]:state[0]=1print"left press"m.press(*m.position())elifnotj.get_button(action['left'])andstate[0]:state[0]=0print"left release"m.release(*m.position())elifj.get_button(action['right'])andnotstate[1]:state[1]=1print"right press"m.press(*m.position(),button=2)elifnotj.get_button(action['right'])andstate[1]:state[1]=0print"right release"m.release(*m.position(),button=2)x,y=m.position()m.move(# get_axis returns a value between -1 and 1
# fumble a bit here to reverse axis
x+(j.get_axis(action['x'])*50*abs(j.get_axis(action['multiplier'])-1)),y+(j.get_axis(action['y'])*50*abs(j.get_axis(action['multiplier'])-1)))exceptKeyboardInterrupt:j.quit()
I recently started using Delicious, and while they have a nice Firefox plugin and a bunch of bookmarklets, there is no easy way to get Delicious bookmarks into the Safari bookmarks bar.
To get this done I wrote an Applescript with a little piece of Python to get Delicious bookmarks right in Safari. Here is how it looks:
Here is how to do it:
Get the 2 scripts below and save them to a suitable location. You might want to place it in ~/Library/Scripts/Applications/Safari
Edit the Applescript with the location of the Python script and the URL of your Delicious feed.
Run the Applescript.
Drag the resulting bookmarks folder or its content anywhere you want.
This will work for any RSS and maybe even Atom feed, you could even bookmark the feed of your Twitter account, for... *hum* easy access to individual tweets.
This is the Python code:
import feedparser
print "<dl>"
for e in feedparser.parse( "http://feeds.delicious.com/v2/rss/pepijndevos" ).entries:
print '<dt><a href="%s">%s</dt>' % (e.link, e.title.encode('ascii','ignore'))
print "</dl>"
Don't ask me why, but Safari needs broken html to import. Maybe because it is meant to import IE bookmarks? Anyway, this is the Applescript, the real thing:
do shell script "python ~/bin/feed2html.py > ~/Documents/delicious.html"
tell application "Safari"
activate
tell application "System Events"
tell application process "Safari"
click menu item "Import Bookmarks…" of menu "File" of menu bar item "File" of menu bar 1
keystroke "g" using {shift down, command down}
keystroke "~/Documents/delicious.html"
keystroke return
keystroke return
end tell
end tell
end tell