Code

Blog posts with PHP, Javascript and other code snippets

Status.net Word Filter Plugin (Wordfilter)

The TWiT Network has pretty strict rules about profanity across all channels including the netcasts, chatrooms and the TWiT Army Canteen. There are usually moderators lurking the IRC and microblog but once in a while some profanity gets through the cracks. Therefore I wrote a little word filter to preempt the profanity.

Roll your own search engine plugins

In response to Willscrlt's comment here's a short guide to creating search plugins for Firefox.

Add the new Google Caffeine search engine to your Firefox search bar

Update 11/11 Sandbox closed

It was fun while it lasted but Google has officially closed the Caffeine search sandbox. I will leave the code below for reference but be advised the search plugin will not work.

Google announced a new search engine preview today called "Caffeine" that can be found at http://www2.sandbox.google.com, and while it looks the same on the surface the results are certainly different. To simplify using this new engine I whipped up a plugin to add the new engine to the Firefox search bar.

CodeIgniter CSRF (XSRF) library

They say a lot of developers work on things to scratch their own itch. This is me scratching.

I'm a fan of the CodeIgniter project but I find it odd that such a well developed framework lacks CSRF protection in the core. There are a few CI CSRF libs but most of them are outdated so I wrote my own. A few ideas came from Michael Wales' toolkit but this library is written from scratch. One of the major differences is that this toolkit uses form IDs instead of a timer to handle forms in different tabs which I find more robust since it doesn't rely on time.

Download csrf-v4.tgz

iMacros script to "test" Spymaster tasks

Important update 6/2/2009 14:20 JST

Many Spymaster accounts have been blocked and or reset without warning because, according to the company, someone found and used an exploit in the wire transfer service which led to those accounts receiving huge sums of money. Many of those affected did nothing wrong but were punished simply because their accounts were affected by the exploit. Read the company's official statement.

Spymaster is not shy about banning users even though they have no terms of use so I warn you, use this script at your own risk!.

-- Original post --

Just a simple script for testing Spymaster tasks. It does so by automatically clicking the available Spymaster tasks at random intervals. This script has the unfortunate side effect of increasing your Spymaster liquid assets and experience level while you sleep.

Requires iMacros

Friendfeed Beta Redirector Greasemonkey Script

Very simple greasemonkey script to redirect all Friendfeed requests to the new beta site.

Updated to exclude paths that do not work under the beta.friendfeed.com domain.

Download the script

"Friendfeed Mini" Greasemonkey Script

Download the script

5/30/2009 Updated to work http://friendfeed.com (non-beta)

The new Friendfeed UI beta opened to the public on Monday 2009/4/6 and has been getting great reviews from many tech pundits. The UI is so good that I'm thinking of switching from my current favorite FF tool Twhirl to the web UI. The only problem with the web UI is that it's designed to be used in a large browser window. I prefer this type of content in a slim window off to the side of my desktop. Resizing the window results in the sidebar menu squeezing out the content.

New Friendfeed UI doesn't work in a slim window

friendfeed default

To remedy this I wrote this "Friendfeed Mini" Greasemonkey script. This is my first GM script so please comment if you find bugs or have any suggestions. It's a work in progress but it's usable. Note: The script is for the beta site. I'll probably need to update the script when the new UI comes out of beta.

Status.net Plugin Developer Helper Plugin (PDhelper)

As with most open source projects, the Laconica (now Status.net) team focuses much more on development than documentation. That's not necessarily a bad thing for the project but makes it harder for third party developers. I had to use a lot of trial and error when working on the TWiT Army Laconica Plugin.

Here's where I had some trouble:

  • Finding the right hook to insert elements in specific places
  • Determining the 'action' name for the loaded page
  • Figuring out how to remove elements

For the last one, it turns out that returning bool FALSE for some hooks will prevent the default output. That was a good idea by the dev team. As for the first two, I decided to create another plugin that just spits some markers and useful PHP object data. You can see a demo of this plugin on my Status.net test site: status.kylehasegawa.com. Some of the markers are not in the body element so these markers are added as HTML comments. View the source of the test site to see these markers.

Comments, feedback, and suggestions are more than welcome. Full source code below the break.

Update v0.3 2010/01/05

  • Status.net v9.0 support (tested on 0.9.0rc2)
  • XHTML now mostly valid (<!DOCTYPE is not on line 1)
  • Other minor enhancements

TWiT Army Laconica Plugin

I was recently asked by my friends over at the TWiT Army to checkout the new Laconica plugin system in version 0.7.2.1. They wanted to know if it could be used to modify the default Laconica output on the TWiT Army Canteen, a feature currently handled by Javascript after the page is loaded. Javascript was used because it saves them from having to modify core code since core changes complicate upgrades. The downside of Javascript is that users see a brief flash of the original output before the JS runs. Another problem with JS modifications is that users who disable JS won't see the page as intended. I doubt anyone besides the TWiT Army will actually use this plugin but it's a decent example of how to use the plugin system so I hope it will be helpful for someone.

What the plugin does

  • Inserts 'apple-touch-icon' link in <head>
  • Adds 'helmetlink' and 'logolink' divs
  • Adds 'toplinks' and 'toplinks2' divs and lists (Live, Leoville, ODTV etc.)
  • Adds 'watermark' and 'bugle' div
  • Replaces nav links (tabs) on some pages

Custom "source" fields in Laconica posts using Curl

Some of my friends on the Twit Army have been asking how I was able to override the source string when posting microblogs. Here's an example of what I mean.

This is a normal post from the web


Notice that it says "from web".

This is a post from curl with the custom source


In this case it's "from a land down under ♫"

This is easily done with the command line tool "Curl" and the Laconica API

All code on this site is free for use at your own risk and provided as-is under the WTFPL license unless otherwise stated. Attribution is appreciated but not required.
Blog content, with the exception of externally quoted material, is licensed under the Creative Commons Attribution 3.0 license