In searching how to do conversions recently, I found some nice code for this, using bit shifting: [...] But then I learned there is now a built-in bin function included in 2.6: [...] And now in 2.6, the binary literal (0b) removes the need for a function at all: [...] I was interested to find Guido Van Rossum’s comment opposed to a bin function, from a 2006 posting: [...] Which is sensible, but I still like having the bin function and I’m glad they added it anyway.
tag archive: code
Scott Rosenberg wrote last week about the “mutability of online content” and the challenges news organizations face in handling changes and corrections to stories, and concluded that versioning made sense in journalism as a way to build trust. Readers can see all of the changes since publication so that there’s no sense of something being swept under the rug. The Drupal CMS has modules for making revisions publicly viewable, and of course this is a key feature of Wikipedia.
Scott noted that WordPress already stores revisions, and suggested a plugin could make old versions accessible to visitors. Looking to demo the idea on his blog, he later asked if any WordPress developers …
The French are a fine people, but you should be aware that this plugin has nothing to do with France or the French.
Month Grid Archive
I wanted to be able to display my monthly archives in a grid:
With post counts for each month, but wasn’t finding a plugin for it. I did find Rob Marsh’s Compact Archives plugin which gave me a good starting place. (Thanks Rob!)
Along the way, it seemed like it would be nice to have post count totals for each year and a grand total. I think this table gives readers a nice snapshot of posting activity over the years.
It’s simple to use: put the_french_archives.php in your plugin dir, activate it, and put <?php month_grid_archive(); ?> in your template file.
You can optionally specify the month header …
This is a plugin/widget to show random quotes on your blog. Frank van den Brink originally created it and Christian Beer has also contributed. The wordpress.org homepage is here: Yet Another Random Quote.
I like this plugin, even if very few people around here can be bothered to actually click on a link to see my random quotes. Really, it’s okay. It’s just fine if you care not one bit about my collected pearls of wit, wisdom, and pop culture ephemera. (You probably won’t care to read my old YARQ post either.)
It appeared that the plugin hadn’t been actively maintained, but through the miracle of free software I was able to make my own fixes and enhancements, and now I can share them with you and the world. (And I did get in contact with …
Updated, 11 December 2010
Here’s some code to generate an arbitrary unique sequence of any combination of numbers, letters, or any character other than whitespace. (See also “Old Post” below for more on the what and why.)
I turned this into a class that implements the iterator protocol, and added a unit test module. I may have went overboard with the unit testing, but I looked at it as a learning exercise, and it’s kind of rewarding in a deep and meaningful way to be able to press a button and put a module through its paces. Final code counts:
The code is now released with the GNU GPL license v3:
It’s written for Python 2.6, but I ran the files through the 2to3 tool with an eye to an easy conversion to Python 3.
The constructor takes …
This isn’t really specific to WordPress, but it preserves the first comment for WordPress theme management, WordPress is awesome, and I’m specifically using this for WordPress style sheets, so I’m making the connection.
I wrote this script to condense my style sheets into smaller files for faster download times. I’m all about customer service here.
And it’s pleasing to me to distill the CSS into a purer essence and reduce network overhead. (Not that the throngs of visitors to this site are noticeably plugging the tubes.)
One benefit of using compression this way is that I can be more liberal in my stylesheet comments, knowing they won’t burden the “production” .css file delivered to my patrons.
I didn’t go for maximum shrinkage, but this provides sufficient minification for my tastes. Read below for additional commentary and …
I was reading slashdot yesterday and some (inane) comments about people’s user ID numbers made me curious about the overall distribution of IDs in slashdot discussions. It didn’t take long to take what I’d learned about the Beautiful Soup screen-scraping library from writing my Twitter status backup script to get some simple information.
Here’s a quick and crude little Python script that does the job as of yesterday’s slashdot HTML/CSS scheme. It spits out the ID number and username, which you then might send through the Unix sort command with various options, e.g.:
slashdot_info.py ‘[slashdot story url]‘ | sort -un
I’m placing this code into the public domain after disclaiming any responsibility for your use of it. Suggested enhancement: Add option to get number of comments for each user and allow sorting by that variable also.
(Update: This only grabs the …
More fun with Python and regular expressions. Following up on a previous post, I wanted to share a little test regex function I wrote in Python to help me as I work through the regular expression book.
I’m mostly working at the interactive prompt and had been running commands from Python re (the regex module) as I experimented with different regular expressions. This was good as I spent time in help(re) and built up some muscle memory for Python regex functions, but it was becoming repetitious to keep typing the commands for analyzing the results of a match. Once I started learning about writing functions in Python, I realized it was time to enhance my …
An objection I’ve had to many programming books and web sites is that they don’t make sample code available under a free software license. This is within the rights of the author, of course, but it seems counter to the spirit of teaching and sharing knowledge to restrict the use of example code.
A writer of instructional material may be doing so to earn some money, but I hope he or she is also motivated by the desire to help others. I think the best authors and teachers are motivated strongly by this desire. And if this is the case, I think it reasonably follows that the author of a programming work should want their students to be able to freely use their source code in the students’ own creations.
I was happy to exchange words recently with an …
To celebrate this great day, here’s a little bit of free software, released under the terms of the GNU General Public License, version 3: a Java class I wrote to find all permutations for a given string. I may later post some more in the way of documentation, but for now, por ejemplo: