Posts Tagged ‘mysql’

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.');
 			}
 		}

Ruby Hiccups

Posted in Libraries on January 28th, 2010 by Jamie – Be the first to comment

I decided to try out some Ruby stuff this weekend. I wanted to do a quick little game with the rubygame gem, but I got some weird error attempting to install it on my 64-bit Snow Leopard Intel Mac Powerbook. I abandoned the effort, since I hate to expend time in system administration and installation.

Next, I decided to try running through a Rails demo. I wanted to use MySQL instead of the default SQLite, but got an error, whose text is below, when I tried installing the mysql gem. I resolved it by using the command string that follows, which I found on a MySQL website forum post.  I think the main issue was that I had a non-standard installation of mysql on my machine via macports, so I had to specify the locations of the various MySQL directories in the gem install command.

Error:
cdERROR:  Error installing mysql:
ERROR: Failed to build gem native extension.

/usr/local/bin/ruby extconf.rb --with-mysql-dir=/opt/local/bin
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lm... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lz... yes
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lsocket... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lnsl... no
checking for mysql_query() in -lmysqlclient... no
checking for main() in -lmygcc... no
checking for mysql_query() in -lmysqlclient... no
*** extconf.rb failed ***
Could not create Makefile due to some reason, probably lack of
necessary libraries and/or headers.  Check the mkmf.log file for more
details.  You may need configuration options.

Command:

sudo gem install --include-dependencies mysql -- --with-mysql-dir=/opt/local/bin --with-mysql-config=/opt/local/bin/mysql_config5

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.

Facebook Thirteen Application

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

This application was written primarily as an exercise in creating Facebook Applications. It was very instructive! Here is the project blog if you’d like more details http://thirteengame.blogspot.com/.

It is an adaptation of a web app I originally wrote in 2007. You may play either by logging into Facebook and trying it out, or logging in here http://www.angelforge.org/thirteen/LoginPage.php. To login outside of Facebook, you may either use the user name and password guest or login with your Facebook credentials using Facebook Connect.


Switch to our mobile site