New Stuff!

Programming — Jeff Eske on February 6, 2018 at 12:45 pm

I’m starting in on a new project at work.  It’s going to be learning all new stuff!  We’re in the nebulous stages of looking into DevOps in general and containerization in particular.  I’m getting a chance to get in on the ground floor of the research and implementation.  I’m hoping to use this space to record my observations along the way.

Javascript – Submitting a form by hitting “Enter”

Programming,Snippets — Jeff Eske on September 6, 2013 at 9:41 am

I’m working within a commercial web-based application that uses a lot of forms, none of which can be submitted by simply hitting the Enter key.  Users were wanting to be able to at least submit a particular search form by simply hitting Enter, rather than having to click the “Search” button, so I decided to do some checking.  I found a pretty simple javascript function that can handle what I need done.  Basically, it watches key presses and when it sees the Enter key pressed (keyCode 13) it runs my search function (some_function_here).  The nice thing is that the default Search button is still available and works the same as always.

Simply add this code to the HEAD code on your page, and change the actions within the if statement to match what the current button does “onClick” and you should be good-to-go.


<script language=”Javascript”>
function detectEnterKey(e) {
var evt = e || window.event;
if(evt.keyCode == 13){
return document.defaultAction;



Jeff Eske

OTRS – Parsing Out the Variables in a SOAP Response

OTRS,Programming,Snippets,Web Services,Web Stuff — Jeff Eske on March 5, 2013 at 5:16 pm

Unlike some web services, the OTRS web services don’t return the values in specific xml tags; it uses generic “s-gensym” tags.  Also, it returns field name within a set of generic tags, followed by the field value in a set of generic tags.  Here’s part of the SOAP response:

<s-gensym1558 xsi:type="xsd:string">PriorityID</s-gensym1558>
<s-gensym1560 xsi:type="xsd:int">3</s-gensym1560>
<s-gensym1562 xsi:type="xsd:string">ServiceID</s-gensym1562>
<s-gensym1564 xsi:type="xsd:string" />
<s-gensym1566 xsi:type="xsd:string">Type</s-gensym1566>
<s-gensym1568 xsi:type="xsd:string">Failure</s-gensym1568>

Makes a lot of sense, doesn’t it?  Here’s an example of one that actually uses the field name as the enclosing tag name.  It makes it easier to understand:

<fusion:BusinessUnit><fusion:v>Some Business Unit</fusion:v></fusion:BusinessUnit>

In this example, you can see that the ServiceDown field(fusion:ServiceDown) has a value(fusion:v) of “false”.  With OTRS, every time you run your SOAP request, you some random-ass “s-gensym” field name for everything.

To actually pull the SOAP response data out, you can use a foreach() loop and dump the field names and values into a more useful array.  In addition to that, the array will be setup as a key/value pair, so you can actually get the field value by referring to the field name.  I’m sure that there’s a much better, more elegant method to do the same thing, but this way works.  First the code, then an explanation of what’s going on:

$ticketInfo = array();
$i = 0;
foreach ($TicketDetails as $name => $value){ 
 if (false !== strpos($name, "s-gensym")){
 $temp[$i] = $value; 
 $v = $temp[$i-1]; 
 if($i % 2 != 0){ 
 $ticketInfo[$v] = $value; 

Basically, what this code does is take your SOAP response array ($ticketInfo) and run it through a foreach() loop.  The OTRS SOAP response includes to entries for each field.  The first entry is the field name and the second entry is the field value.  So, what I want to do is combine both entries into a key->value pair in an array.

The foreach() explodes the values of the s-gensym variables out and adds the value to 2 different arrays.  This is where the elegance is definitely lacking.  I’m first saving the value into the $temp[] array to refer back to it later.  Then, if the row is divisble by two – basically every other, or every second row, I grab the previous value from temp[] and write it to $ticketInfo[] as the key and write the current value as the value.  What I end up with in the end is an array ($ticketInfo[]) that has the field name as the key and the field value as the value.

You can then pull the desired value by referring to the appropriate key, such as:

$ticket_age = $ticketInfo[Age];
$ticket_title = $ticketInfo[Title];

A simple way to print out all of the values in your array is, again, with the foreach() loop.  All you need is this little piece of code:

foreach ($ticketInfo as $name => $value){
 echo "<b>".$name.":</b> ".$value."<br>";

The foreach() will loop through the array and explode out the key/value pairs, then echo them out.  It can be handy for troubleshooting, to see what everything actually looks like in the array.

Jeff Eske

PHP Script to Display SOAP Requests and Responses

Programming,Web Services,Web Stuff — Jeff Eske on March 5, 2013 at 10:15 am

Some time back, while working out web services on another project, I put together a janky little snippet of PHP code that’s actually pretty handy when dealing with SOAP-based web services.  For me, the hardest part of working with web services is trying to figure out exactly what the request needs to look like to work correctly.  The other thing is figuring out exactly what I got back!  This little snippet actually shows you what the xml-formatted SOAP request and SOAP response each look like.  The REALLY nice thing is that it only takes 4 lines of code.

Here’s what it looks like:

print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";

Basically, all you do is plug this in after you’ve created your new SoapClient() object and performed the soapCall().  A basic example would look like the code below.  Please note, this isn’t a working piece of code, just an illustration of how it would look.

$client = new SoapClient(
 some client specifics here
$SomeSoap = $client->__soapCall(
  do some SOAP function
print "<pre>\n";
print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
print "</pre>";


What this should get you, when you run the script, is two separate, preformatted lines of text.  The first line will be the XML-formatted request that PHP sent to the web service.  The second line should be the XML-formatted response returned.  Granted, this doesn’t necessarily give you the final format that you need, but it will get you names of all of the XML variables that have been returned.  With that information, you can proceed to find a way to extract the information that you need.

Stay tuned for more on this subject.

Jeff Eske

OTRS – Mobile Front-end

OTRS,Programming,Web Stuff — Jeff Eske on February 19, 2013 at 1:30 pm

I’m in the process of creating a mobile front-end for OTRS.  There are a couple of decent apps out there that can be used on iOS and Android, but I decided to create a completely HTML-based version, just because I can.  I’ll post a video of the progress so far.

Stay tuned.

UPDATE: I have a link to a short video that shows it in action below.  Click on the image to view the video.

In the video, I’m accessing the mobile pages on my old Motorola Droid X.  I’ve tested it on the Droid, as well as an iPhone 4S (being used to take the video) and an iPad.  Since it’s really basic HTML, it works great on all of them.


OTRS Mobile front-end walkthrough

OTRS Mobile front-end walkthrough

It’s still very much a work-in-progress.  Currently, it’s “read-only”.  I’m in the process of adding two-way functionality, utilizing OTRS web services.

Jeff Eske

PHP – Poor Man’s Data Export/Combine Script

Programming,Snippets — Jeff Eske on February 5, 2013 at 4:50 pm

I ran into a situation a while back where I needed to merge some information from 2 separate tables into one table.   Basically, I was sort of breaking normalization rules in favor of simplicity.  I basically had a table full of helpdesk tickets with a field for customer numbers, but no customer names.  I also had a customer table that contained all of the customer information.  Since I was making a system that’s going to be “read-only” for looking up the old tickets, I wanted to be able to query a single database, when looking for the old tickets.

So, basically, I cobbled the basics of this script together to pull information from the two different tables and combine it into one single record.  I pulled the ticket record, then did a sub-search on the customer table to find the customer name in the customer table associated with the customer number from the ticket table.

Then, once that was done, I cleared the ticket table and turned around and imported my brand-spanking new csv file BACK into the ticket table, with the customer number field adjusted to be the customer name.

There’s probably an easier way to accomplish this, but when all you have is a hammer (PHP programming experience), everything looks like a nail.

Here’s the basic code.  It’s a little confusing since I’m just using generic field1, field2, etc.


#### Variables to Set
$db_host = “localhost”; // Database server name
$db_user = “db_user_username_here”; // Database Username
$db_pass = “db_user_password_here”; // Database User’s Password
$db_table1 = “your_first_table_here”; // Table name, written as database.table
$db_table1 = “your_second_table_here”; // Table name, written as database.table
$csv_filename = “csv_filename_here”; // name of the output file

#### Database Connection
$db_connect = mysql_connect($db_host, $db_user, $db_pass) or die(“couldn’t connect to DB server”);

#### Open the csv text file for writing
$csv_file_out = fopen($csv_filename,”w”); // name of the output file

#### Query the first database
$sql1 = “SELECT field1,field2,field3 FROM $db_table1”;
$result1 = mysql_query($sql1, $db_connect);

#### Pull each record from the first database then do a subquery for the related record from the second database.
while($data1 = mysql_fetch_object($result1)){ // cycle through first database’s records
// Find the record in database2 that is related to the record in database1 via field1 in both
$sql2 = “SELECT field1 FROM $db_table2 WHERE field1 = $data1->field1″;
$result2 = mysql_query($sql2, $db_connect);
// Write out field1, field2, and field3 from database1, plus field1 from database2
$write_line = $data1->field1.”,”.$data1->field2.”,”.$data1->field3.”,”.$data2->field1.”\n”;
fwrite($csv_file_out, $write_line);
#### Close the text file when finished


Jeff Eske

PHP – Cheesy Little PHP Script

Programming,Snippets — Jeff Eske on February 5, 2013 at 4:04 pm

Here’s a cheesy little script that parses a block of text and “linkifies” URLs.  It basically breaks the text into individual “words” and stores them in an array.  It then checks each array element to see if it appears to be a web address.  If it appears to be, it encloses address in the appropriate link code, so that it will be clickable.  If not, it simply spits it back as-is.



$content = “This is some test content.”;
#### Parse content for URLs ####
$shrapnel = explode(” “,$content); // break the text string into pieces and place them in an array.
$total = count($shrapnel); // count the pieces of shrapnel
for($i=0;$i<=$total;$i++){ // step through the array, looking at the pieces to see if they start with http
if(preg_match(“/^http./”, $shrapnel[$i])){
echo”<a href=’$shrapnel[$i]’>$shrapnel[$i]</a> “;
echo”$shrapnel[$i] “;


You could also add a regexp for “www”, if you wanted to catch websites that don’t include the http or https.  Obviously, this has no error handling or anything else included.  It came in handy in a particular situation, so I decided to post it.

Jeff Eske

New TODO List Manager

Programming,Web Stuff — Jeff Eske on August 13, 2012 at 1:00 pm

I’m starting work on a new TODO List Manager.  The hope/plan is that it will be available online via website and available offline via a mobile app.  I’m hoping for a very simple, minimalist design that will do what I need it to do.  I know that there are several good ones out there, but they’re all more cumbersome than what I’m looking for.   I’ve wanted to learn some new stuff (HTML5, jquery, mobile app development, etc.), so I figure I’ll use this as an opportunity to try to incorporate it all!

Jeff sounds good but…

General,Programming,Web Stuff — Jeff Eske on August 3, 2012 at 1:32 pm founder Dalton Caldwell’s Audacious Proposal to create a paid-for messaging service sounds fine, but I think there’s a “but” that hasn’t been brought up yet.  I’m not sure what the “but” is, but my guess is that there will be more revenue generation than just membership fees.

Dalton proposes charging his users/developers for use of the service.  On the signup/promotional page, he lists 3 tiers – Member, Developer, and Pro with corresponding prices.  He talks about supplying APIs, documentation, etc. to differing degrees, depending on Tier.  That’s all well-and-fine, but I don’t understand who covers the infrastructure costs as things ramp up.  What happens if I build the next Twitter, or Facebook, using his API(s) and it’s a huge success.  Suddenly, I, the $100/year developer am incurring thousands of dollars a day in bandwidth usage, due to all of the non-paid users accessing my Twitter-killer service.  Who eats those costs?  Or, are all of my users going to have to stump 50 bucks to access my app, to cover there usage?  Is the membership price just padded to cover that?

Don’t get me wrong.  I hate being poked, prodded, and stalked all over the internet.  I really and truly hope it works, but I’m just not sure without seeing more specifics, like an actual business plan.

Anyway, just my 2 cents.



Installing Eclipse for Android Development on Ubuntu

Programming — Jeff Eske on May 10, 2012 at 1:58 pm

I decided that I’m going to try building my first “real” Android app.  To do that, I decided that I’d use the Eclipse IDE.  Well, the simplest way to do that is to just use apt or Synaptic and install it.  Easy Peasy.  Using the instructions from the Android Developers site, I downloaded/extracted the latest Android SDK that they listed, and then went to install the ADT Plugin for Eclipse.  I inserted the appropriate URL to download the plugin, but when it got to the point that it was to install them, it bombed.  Eclipse told me that there were things missing.  After a little Googling, I found out that can happen when installing via apt.

My solution was to just go out to the Eclipse site and download the “Classic” environment.  After downloading/extracting the Classic version, I was able to get everything to install with no problems.

Now, all I have to do is figure out how to actually DO something with it…


Next Page »
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 2.5 License. | Jeff's Meanderings*