Software

Word Jumble Game: Part 1

Posted in Software on March 14th, 2010 by Jamie – Be the first to comment

For a recent Regular Expressions Tech Talk at Wharton, I wrote a Word Jumble game.  I will be describing the game and some of the key concepts used in making the game. Here’s the github repo.

Game Screenshot

Game Screenshot

The premise of the game is to transform one word into another by replacing a single letter in the starting word to form a new word and repeating until you match the last word.

So, let’s say we have the word baked, which we want to transform into the word water. We do this by changing one letter in the word baked and forming a new word, repeating the single-letter replacement until we have the word water.

  • baked <- start
  • bated
  • batea
  • bater
  • water <- end

The rules are:

  • You are only given a starting word and ending word
  • Change only one letter to form a new word
  • The new word must be a real word (in some dictionary)
  • The same word cannot appear twice
  • Each word must be the same length

Based on these rules, I sat down one evening and spit out an implementation of the game which has the following features:

  • randomly generates a puzzle of 5-letter words
  • generates a puzzle of max length n, where n is the number of words in the puzzle
  • accepts an initial starting word
  • accepts user guesses for the intermediate words

Bubble Breaker Using Canvas!

Posted in Programming, Software on March 2nd, 2010 by Jamie – 2 Comments

I wanted to try out some canvas element functionality, given that I have a feeling it will steal a lot of Flash’s thunder. I whipped up a bubble-breaker game (the mechanic should be very familiar to you) in a few hours. Enjoy the demo! I may do a quick write up at a later point.

I’ve only tested it in Firefox 3.6. I do not know whether it will work in other browsers.

Demo
Project site

bubble breaker 13x13

bubble breaker 13x13

bubble breaker 30x30

bubble breaker 30x30

Drupal Org Chart – Graph Viz Update

Posted in Programming, Software on February 24th, 2010 by Jamie – Be the first to comment

I have updated the Google Code repository with updates to integrate GraphViz. It expects the PEAR GraphViz package to be installed.  To install it, issue command:

# You must install the beta package.

sudo pear install Image_GraphViz-beta

If you’d rather not mess with PEAR, download the package, extract the class Image_GraphViz, and alter two two lines of code that depend on the PEAR::System package. It should be trivial to change these. They are both basically calls like this:

// create a temporary file with the prefix "graph_"
$file = System::mktemp('graph_');

One possible replacement:

// will use default tmp dir
$file = tempnam('', 'graph_');

Stikked Patch

Posted in Software on February 16th, 2010 by Jamie – 4 Comments

We’ve been using Stikked for an internal pastebin. The current version on Google Code has a few bugs. I modified this code to fix two problems specifically:

  1. The Download Code link was not working properly
  2. The Short URL functionality was not working, as Snipr had deprecated the version of the API that the program was using

Below is a consolidated diff of the changes. You should be able to use it to apply a patch to 0.5.4 if you are having these issues.

stikked.diff

Index: trunk/system/application/models/pastes.php
===================================================================
--- trunk/system/application/models/pastes.php	(revision 1)
+++ trunk/system/application/models/pastes.php	(revision 2)
@@ -156,14 +156,55 @@
 			$data['snipurl'] = false;
 		}
 		else
-		{
-			$target = 'http://snipr.com/site/snip?r=simple&link='.site_url('view/'.$data['pid']);
+		{
+			// this next blob just copied from snipr's examples,
+			// with some modifications of course
+
+			// REQUIRED FIELDS
+			$sniplink  = site_url('view/'.$data['pid']);
+			$snipuser  = $this->config->item('snipr_user');            // YOUR USER ID REQUIRED
+			$snipapi   = $this->config->item('snipr_apikey');               // FIND IN YOUR "SETTINGS" PAGE
+
+			// OPTIONAL FIELDS
+			$snipnick   = '';            // MEANINGFUL NICKNAME FOR SNIPURL
+			$sniptitle  = $data['title'];  // TITLE IF ANY
+			$snippk     = '';                      // PRIVATE KEY IF ANY
+			$snipowner  = '';                      // IF THE SNIP OWNER IS SOMEONE ELSE
+			$snipformat = 'simple';                      // DEFAULT RESPONSE IS IN XML, SEND "simple"
+			                                       // FOR JUST THE SNIPURL
+			$snipformat_includepk = "";            // SET TO "Y" IF YOU WANT THE PRIVATE KEY
+			                                       // RETURNED IN THE SNIPURL ALONG WITH THE ALIAS
+
+			//----------------------------------
+			// NO NEED TO EDIT BEYOND THIS POINT
+			//----------------------------------
+			$URL        = 'http://snipr.com/site/getsnip';
+			$sniplink   = rawurlencode($sniplink);
+			$snipnick   = rawurlencode($snipnick);
+			$sniptitle  = rawurlencode($sniptitle);
+
+
+			$post_data =  'sniplink='  . $sniplink  . '&' .
+			              'snipnick='  . $snipnick  . '&' .
+			              'snipuser='  . $snipuser  . '&' .
+			              'snipapi='   . $snipapi   . '&' .
+			              'sniptitle=' . $sniptitle . '&' .
+			              'snipowner=' . $snipowner . '&' .
+			              'snipformat='. $snipformat. '&' .
+			              'snippk='    . $snippk
+			  ;
+
+
+			$target = $this->config->item('snipr_link');
 			$ch = curl_init();
 			curl_setopt($ch, CURLOPT_URL, $target);
+			curl_setopt($ch, CURLOPT_POST, true);
+			curl_setopt($ch, CURLOPT_HEADER, 0);
+			curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data);
 			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

 			$data['snipurl'] = curl_exec($ch);
-
+
 			curl_close($ch);

 			if(empty($data['snipurl']))
@@ -189,6 +230,7 @@

 	function checkPaste($seg=2)
 	{
+
 		if($this->uri->segment($seg) == "")
 		{
 			return false;
Index: trunk/system/application/config/routes.php
===================================================================
--- trunk/system/application/config/routes.php	(revision 1)
+++ trunk/system/application/config/routes.php	(revision 2)
@@ -46,6 +46,7 @@
 $route['cron/:any'] = "main/cron";

 $route['view/raw/:any'] = 'main/raw/';
+$route['view/download/:any'] = 'main/download/';
 $route['view/options'] = 'main/view_options';
 $route['view/:any'] = 'main/view';
 $route['lists'] = 'main/lists';
Index: trunk/system/application/config/config.php
===================================================================
--- trunk/system/application/config/config.php	(revision 1)
+++ trunk/system/application/config/config.php	(revision 2)
@@ -308,4 +308,16 @@
 $config['rewrite_short_tags'] = FALSE;

+/*
+|--------------------------------------------------------------------------
+| Snipr Settings - Used for short URL
+|--------------------------------------------------------------------------
+|
+| Settings for Snipr API
+|
+*/
+$config['snipr_link'] = 'http://snipurl.com/site/getsnip';
+$config['snipr_user'] = ''; // snipr user name
+$config['snipr_apikey'] = '';
+
 ?>
\ No newline at end of file
Index: trunk/system/application/views/view/download.php
===================================================================
--- trunk/system/application/views/view/download.php	(revision 1)
+++ trunk/system/application/views/view/download.php	(revision 2)
@@ -1,6 +1,6 @@
 <?php

-header('Content-disposition: attachment');
+header('Content-disposition: attachment;filename='.$title.'.'.$lang_code);
 echo html_entity_decode($raw);

 ?>
\ No newline at end of file
Index: trunk/system/libraries/URI.php
===================================================================
--- trunk/system/libraries/URI.php	(revision 1)
+++ trunk/system/libraries/URI.php	(revision 2)
@@ -186,8 +186,15 @@
 	{
 		if ($str != '' AND $this->config->item('permitted_uri_chars') != '')
 		{
-			if ( ! preg_match("|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i", $str))
+			$matches = array();
+			$pattern = "|^[".preg_quote($this->config->item('permitted_uri_chars'))."]+$|i";
+			if ( ! preg_match($pattern, $str, $matches))
 			{
+				echo '<pre>*'.$str.'*<br>';
+				echo 'allowed: '.$pattern.'<br>';
+				var_dump($matches);
+				var_dump(debug_backtrace());
+				echo '</pre>';
 				exit('The URI you submitted has disallowed characters.');
 			}
 		}

Stikker

Posted in Programming, Software on February 11th, 2010 by Jamie – Be the first to comment

Some coworkers and I have been working on Stikker, a cli interface for the Stikked FOSS php pastebin. I haven’t used it for awhile, but we recently set it up at work to facilitate code sharing. Unfortunately, it hasn’t been updated recently and there are some things which are broken which I’ll need to address. One of the great things about OSS is that fixing things yourself is possible!

CiteThis! Update 0.17

Posted in Software on February 3rd, 2010 by Jamie – 4 Comments

I modified CiteThis! with the following features this weekend:

  • Added a citation list box, where you can queue all your citations.
  • Removed the custom citation box from the preferences pane (it was not of use anymore)
  • Fixed APA citation format to include last accessed date.
  • Added some handling of author/titles:
    • If title includes the host name of the site such as “news blah blah – CNN”, then the host name will be removed from the title.
    • If the author ends with any special characters, they will be removed
    • If author contains AP, or Associated Press, that will be stripped.
  • Author determination:
    • Added handling of some common author classes, like when an element has a class called “byline” or “author”
  • Site-specific handling
    • Added handling of some more sites: ABCNews, Fox, CNet, Yahoo News

https://addons.mozilla.org/en-US/firefox/addon/7972

CiteThis! Update 0.16

Posted in Software on January 18th, 2010 by Jamie – Be the first to comment

I made an update at the request of someone who e-mailed me.  This post describes this version:

  • Custom citation formatting broken! (Will be addressed in next update.)
  • Added variable citations depending on what fields are specified
  • Added custom date formatting based on datejs
  • Added custom handling of Wikipedia citations

https://addons.mozilla.org/en-US/firefox/addon/7972

Thirteen Facebook Application

Posted in Programming, Software on December 24th, 2009 by Jamie – Be the first to comment

Update to CiteThis!

Posted in Programming, Software on December 6th, 2009 by Jamie – Be the first to comment

I updated my CiteThis! Firefox Extension with a few of the following features:
Several updates including:

  • Created preferences pane to allow selection of different reference styles
  • Provided option for a customized citation string
  • Implement some automatic author discovery for the page
  • Improved performance by avoiding updates when hidden

https://addons.mozilla.org/en-US/firefox/addon/7972

Sicbo Facebook Application

Posted in Software on June 12th, 2009 by Jamie – Be the first to comment

This is a Facebook application I wrote after the Thirteen application. It improves upon the first Facebook App with a new architecture. Animation uses the Facebook Animation library, and rendering is done via Smarty PHP Template engine. Lots of work went into the architecture, and there is even a localization scheme built in.


Switch to our mobile site