Archive for the ‘Programming’ Category

Reddit Hover Craft Update v1.3

I put the finishing touches on the Reddit Hover Craft Google Chrome Extension.  This version, 1.3, addresses some of the issues that were brought up in previous releases.  Mainly this extension fixes the images popup location so that the image will either popup above or below the link that is being hovered over.  Previously it would only popup below the link cause and link that we was located low in browser window to not be fully shown.

I am hoping to address some other concerns that were brought up such as a not showing NSFW links (this will be able to be turned on and off in the options menu) and adjust the width of certain images and not just the height. Stay tuned

If you already have it installed then Google Chrome will automatically update you to the latest version.  If you don’t have it installed already you can get it here.

Python Wrapper For The Phish.net API

While browsing the Phish.net API documentation I noticed that it was missing a Python wrapper.  So I said to my self, this sound like a quick and fun project to test out my Python <cough> skills </cough>.

Just update the method variable to which ever method you are using and add the remaining parameters if necessary.  Here is more docuemtation on the Phish.net API and where to apply for one.

While you are at it check out Adam Scheinberg and my official Phish.Net Google Chrome Extension.

FYI, This is only been tested on Python 2.7.1.  I am pretty sure that it will not work in Python 3.

#Query Phish.net API via Python 2.71.
 
import urllib, json, sys
 
url='https://api.phish.net/'
js='api.js'
 
apikey = 'Your API Key'
format = 'json'
apiver = '2.0'
method = 'pnet.shows.setlists.latest'
 
#Build parameters to send via GET to api.js
params = urllib.urlencode({
  'api':apiver,
  'method':method,
  'format':format,
  'apikey':apikey
  })
 
#Attempt to open a connection and get the JSON formated data
try:
  f = urllib.urlopen(url + js + "?%s" % params)
 
#Do this for invalid URL
except IOError:
  print 'Error: Unable to connect. Invalid URL. '
  sys.exit(1)
 
#Get the response code
rsp = f.getcode()
 
#If the HTTP response is 200 (OK) then proceed
if rsp == 200:
 
  #Read the data
  data =  f.read()
 
  #Decode the data as JSON
  decoded = json.loads(data)
 
  #Print the Decoded JSON
  print 'DECODED: ', decoded
 
  #Print an individual JSON Record
  print 'GET INDIVIDUAL RECORD: ', decoded[0]['showdate']
 
else:
  #Do this if the not an HTTP response of 200
  print 'Error: ',  rsp
 
#close the connection
f.close()

I have submitted this to the Phish.net administrators and if it gets the Ok then it will be uploaded here.

Update: The code has been posted on Phish.net site.

Update 2: I forgot to give proper credit to Adam for his help on the Phish.net Chrome Extension.

Installshield: File Contents Find and Replace.

Now I am still new to Installscript so go easy on me if there is an easier way to do this.  Also please let me know.

I know that under a Basic MSI project there is a graphical way to do find and replaces inside of text files.  But I could not find a way to do this with an Installscript.  I little Google searching found this.  It worked great until the string I was searching for was  inside of double quotes.  Therefore I was forced to be creative and write one myself.

Here is a function that needs 4 parameters; the file’s path, the file’s name, what to search for, and what to replace it with when it is found.

/***************************************************************/
//  Written By: Terry Moore
//  Email:motersho(at)gmail.com
//  Date last modified: 2010-10-21
//  Description: Find a string in a file and replace
//                    it with another string
/****************************************************************/
 
prototype FindReplace(STRING, STRING, STRING, STRING); 
 
function FindReplace(szPath, szFile, szFind, szReplace)
 
NUMBER nvFileHandle, nvResult;
STRING svString, szResult;
 
begin
  OpenFileMode (FILE_MODE_BINARY);
  GetFileInfo ( szPath ^ szFile, FILE_SIZE, nvResult, szResult);
  if OpenFile(nvFileHandle, szPath, szFile) &lt; 0 then
      MessageBox ("OpenFile failed.", SEVERE);
      abort;
  endif;
 
  SeekBytes (nvFileHandle, 0, FILE_BIN_START);
  if (ReadBytes (nvFileHandle, svString, 0, nvResult) &lt; 0) then
    // Report an error.
    MessageBox ("Failed to read file.", SEVERE);
    abort;
  else
    StrReplace(svString, szFind, szReplace, 0);
    CloseFile (nvFileHandle);
    DeleteFile(szPath ^ szFile);
    OpenFileMode (FILE_MODE_BINARY);
    CreateFile(nvFileHandle, szPath, szFile);
    //The 10000 below it to create a buffer larger than the orginal files
    //size. I dont know if this is need or the best method. YMMV.
    if (WriteBytes(nvFileHandle, svString, 0,nvResult + 100000) &lt; 0) then
        MessageBox ("Failed to write file.", SEVERE);
        abort;
    endif;
  endif; 
 
  // Close the file.
  CloseFile (nvFileHandle);
end;

Installshield

I have been asked it learn Installshield at work to start writing the Windows installers for our some of our companies applications.  I have written AutoIT scripts to automate most of the installations and configurations including an AutoIT Installshield clone that from a users perspective, looks and feels just like Installshield.  (I still need to post that code for ya’ll) However we are looking to officially ship these installers out on our media DVDs so I suppose it is better to write them in an industry standard such as Installshield rather that a bad ass scripting language such as Autoit.

That being said, start looking for Installshield code snipits to start showing up on this site.

Life Before Visio

Jambase.com Chrome Extension

Hot on the heals of the Phish.net Chrome Extension I have also release my Jambase.com Show Finder Chrome Extension.  This will give will give you quick access to local show in you area and others.