At work I’ve been asked to brainstorm solutions to a problem where a user’s session and application information is lost when they get kicked off of one server and are moved to another. Essentialy we have a load balancer with “sticky session” support, so a user, once logged into our application, goes onto a web server, and stays there. Should that web server crash, however, they will get moved to the next web server. That next server, however, has no knowledge of this user’s application and session information, thus forcing them to log in to our application again. This isn’t optimal.
Read more…
psykoprogrammer ColdFusion, Development ColdFusion, Development
This last Friday I attended the ColdFusion track at the Dallas Techfest. I went with a coworker and ex-coworker specifically to see the ColdFusion 9 preview. It was a good presentation that I must admit I’m a little excited about.
For me, this is the most exciting ColdFusion release in a long time. In my eyes ColdFusion, with the version 9 release, is well on its way to becoming a programmer’s language. Allow me to elaborate.
Read more…
psykoprogrammer ColdFusion, Development, General ColdFusion, Technology
Last night I did it. I took the plunge. I formatted and installed 64-bit Windows 7 Release Candadite. The experience, thus far, has been fairly painless. The installer was the simpliest installer for Windows I’ve used to date (and the prettiest).
Once in Windows I began the search for drivers to make everything work. Windows 7 automatically showed me a driver download from nVidia for my geForce 275 GTX, but I opted to visit the eVGA site instead, and sure enough they have a Windows 7 driver.
From here I payed a visit to the Creative Labs site for my sound device. Again I was fortunate to discover that my Sound Blaster X-Fi Gamer card has beta Windows 7 driver support. After a reboot everything played nice and clear.
Very quickly I proceeded to download Firefox so that I didn’t have to use IE anymore. I must note here that I do wish that Firefox had a 64-bit version to take full advantage of my hardware and newest OS, but I can live with the smaller 32-bits.
All while doing these tasks I also began the LONG update of Lord of the Rings Online: Mines of Moria. The game install is big enough, but the update currently sits at 4,000 plus files. That took a few hours to finish.
Now I am in the process of restoring backups from my Mozy Home account to get back my email, code, and documents.
psykoprogrammer General, White and Nerdy Operating System, Software
In my ongoing effort to further enhance my PHP framework I started recently working on a caching mechanism. For the time being I am using the PEAR library’s Cache_Lite (I’ve blogged on this before, so check it out) to handle the details of persisting the cache data, locking, and all that fun jazz. Cache_Lite, however, is a pretty simple library and does not implement any particular algorithm regarding how much cache to keep, or what stays in cache and what goes. It offers an expiration mechanism, but that’s about it.So with that in mind I set off to learn about various caching and paging algorithms. They range, I found out, from simple to complex.
Read more…
psykoprogrammer Development, PHP Development, PHP
Had a situation at work today where I needed a quasi-random ID to store as a “key” in the database. This key would be handed to users for their use over a given session for webservices.
At first I started with a UUID using the following code, but it occured to me that for my audience that string was a bit long, so I wanted something a little smaller.
-
<cfset key = createObject("java", "java.util.UUID").randomUUID().toString() />
I then came across a snippet of code, and decided that I could move that over into a CF component and use that. It would allow me to generate a quasi-random 8-digit string to use as a key. Here is that code.
-
<cfcomponent name="RandomId">
-
-
-
-
<cffunction name="generate" returntype="string" access="public" output="false">
-
-
<cfargument name="numCharacters" type="numeric" required="false" default="8" />
-
-
-
-
<cfset var chars = "abcdefghijklmnopqrstuvwxyz1234567890" />
-
-
<cfset var random = createObject("java", "java.util.Random").init() />
-
-
<cfset var result = createObject("java", "java.lang.StringBuffer").init(javaCast("int", arguments.numCharacters)) />
-
-
<cfset var index = 0 />
-
-
-
-
<cfloop from="1" to="#arguments.numCharacters#" index="index">
-
-
<cfset result.append(chars.charAt(random.nextInt(chars.length()))) />
-
-
</cfloop>
-
-
-
-
<cfreturn result.toString() />
-
-
</cffunction>
-
-
-
-
</cfcomponent>
The usage of this component is similar to the method above:
-
<cfset key = createObject("component", "RandomId").generate() />
Happy coding!
psykoprogrammer ColdFusion, Development ColdFusion, Development
Swithin write:
Can the “width” and / or “height” parameters be passed in the
o.getCode128()
call?
I am successfully passing the “#url.data#” as
o.getCode128(’#url.data#’)
but would like to also decrease the overall size of the barcode, while keeping the “data” the same. So I will need to decrease the “width” of the narrowest “bar”, and the “height” of the overall image. It appears that these have default settings that are built-in, and which cannot be passed in.
Is that correct?
If that is correct, and they cannot be sent in, then do you have any recommendation of another barcode generator that might allow such size adjustments?
Thanks for the question Swithin. I took a look into the API provided by Barbecue Barcode and there is a way to control the individual bar’s width and height. There are some things to be aware of. First off each barcode type may have minimum height requirements, so you might not always get the results you expect.
The next noteworthy item is that you don’t really have control over the actual image’s overall width and height. As you have probably noticed just changing the image tag’s width and height will invalidate the barcode. I did try messing with the actual JComponent’s setMaximumSize and setPreferredSize methods, but those were completely overlooked.
So here is an updated component that allows you to specify the bar width, height, barcode resolution (for non-screen output, such as a printer), and output format (gif, png, jpeg).
-
<cfcomponent name="Barcode" displayname="BBQ Barcode" output="false">
-
-
-
-
<cffunction name="getBarcode" returntype="any" access="remote" output="true">
-
-
<cfargument name="data" type="string" required="true" />
-
-
<cfargument name="barWidth" type="numeric" required="false" default="0" />
-
-
<cfargument name="barHeight" type="numeric" required="false" default="0" />
-
-
<cfargument name="resolution" type="numeric" required="false" default="0" />
-
-
<cfargument name="outputFormat" type="string" required="false" default="jpeg" />
-
-
-
-
<cfset var barcode = __getBarcode(argumentCollection: arguments) />
-
-
-
-
<cfsetting showdebugoutput="false" />
-
-
<cfset getPageContext().getOut().clearBuffer() /><cfcontent type="image/#arguments.outputFormat#" variable="#__getBarcodeImage(barcode, arguments.outputFormat)#" /><cfreturn />
-
-
</cffunction>
-
-
-
-
<cffunction name="__getBarcode" returntype="any" access="private" output="false">
-
-
<cfargument name="data" type="string" required="true" />
-
-
<cfargument name="barWidth" type="numeric" required="false" default="0" />
-
-
<cfargument name="barHeight" type="numeric" required="false" default="0" />
-
-
<cfargument name="resolution" type="numeric" required="false" default="0" />
-
-
-
-
<cfset var barcode = createObject("java", "net.sourceforge.barbecue.BarcodeFactory").createCode128(arguments.data) />
-
-
-
-
<!—
-
-
If we have barWidth and barHeight data, pass that on. 0 indicates
-
-
that we don‘t want to change the width/height.
-
-
—>
-
-
<cfif arguments.barWidth GT 0>
-
-
<cfset barcode.setBarWidth(javaCast("int", arguments.barWidth)) />
-
-
</cfif>
-
-
-
-
<cfif arguments.barHeight GT 0>
-
-
<cfset barcode.setBarHeight(javaCast("int", arguments.barHeight)) />
-
-
</cfif>
-
-
-
-
<!—
-
-
Set the resolution. 0 indicates that we don’t wish to change
-
-
the default, which is usually 72 dpi. One may wish to change
-
-
this for non-screen devices, such as a printer.
-
-
—>
-
-
<cfif arguments.resolution GT 0>
-
-
<cfset barcode.setResolution(javaCast("int", arguments.resolution)) />
-
-
</cfif>
-
-
-
-
<cfreturn barcode />
-
-
</cffunction>
-
-
-
-
<cffunction name="__getBarcodeImage" returntype="any" access="private" output="false">
-
-
<cfargument name="barcode" type="any" required="true" />
-
-
<cfargument name="outputFormat" type="string" required="true" />
-
-
-
-
<cfset var outStream = createObject("java", "java.io.ByteArrayOutputStream").init() />
-
-
<cfset var bufferedImage = "" />
-
-
-
-
<!—
-
-
Write the barcode out to the output stream as a series of encoded bytes.
-
-
The format is based on outputForamt. jpeg, gif, png.
-
-
—>
-
-
<cfswitch expression="#arguments.outputFormat#">
-
-
<cfcase value="jpeg">
-
-
<cfset bufferedImage = createObject("java", "net.sourceforge.barbecue.BarcodeImageHandler").writeJPEG(barcode, outStream) />
-
-
</cfcase>
-
-
-
-
<cfcase value="gif">
-
-
<cfset bufferedImage = createObject("java", "net.sourceforge.barbecue.BarcodeImageHandler").writeGIF(barcode, outStream) />
-
-
</cfcase>
-
-
-
-
<cfcase value="png">
-
-
<cfset bufferedImage = createObject("java", "net.sourceforge.barbecue.BarcodeImageHandler").writePNG(barcode, outStream) />
-
-
</cfcase>
-
-
</cfswitch>
-
-
-
-
<cfreturn outStream.toByteArray() />
-
-
</cffunction>
-
-
-
-
</cfcomponent>
And usage similar to before:
-
<cfoutput>
-
-
-
-
<p>
-
-
Displaying a barcode with the text "My First Barcode"
-
-
</p>
-
-
-
-
<p>
-
-
<img src="barcode.cfc?method=getBarcode&outputFormat=gif&data=My First Barcode&barWidth=1&barHeight=50&resolution=72" alt="My First Barcode" />
-
-
</p>
-
-
-
-
</cfoutput>
psykoprogrammer ColdFusion, Development ColdFusion
Here’s a nifty plugin written Davide Ficano that allows you to control what application(s) that is used to view the HTML source on a given page in Firefox. I use a nice text editor called Boxer that I prefer over the default, and this plugin allows me to use it. Web developers should give it a download.
psykoprogrammer Development Plugins, Software
Yes, that is the interestingly ambiguous message I recieved today while developing on a particularly large CFC. In this particular component there was a function that was excessively long, so I decided to be cool and break it apart a little bit. To start I took out a 523 line query and moved it to a new function. When I then ran the code I recieved the following error: “Branch target offset too large for short”.

Ok… I’ve not quite heard of this one before, so I turned to the ever trusty Google. Turns out that there is a limitation in the JVM where branch statements (like GOTO) cannot reach an address (or offset) in the code past 32,767 bytes, or a SHORT integer. In short (pun intended) one of my functions, or some branch condition in an IF or SWITCH statement, cannot be reached because it is at an offset that exceeds 32,767 bytes. Code is too big!!
UPDATE: To fix this issue I moved a large branch of code that contained a large number of IF/ELSE statements to a new function. This apparently solved the issue and the code ran happily along again.
psykoprogrammer ColdFusion, Development ColdFusion, Development