devbox@COMPUTEC The Computec development blog

22Sep/0913

BuddyPress – Activity comments plugin

This plugin will enable posting comments on activity stream items, similar to Facebook. By default, comments are limited to 150 characters.

Only logged in users can leave comments on activities and delete that comments. Also, if user is "owner" of the activity stream he/she will be able to delete all unwanted comments on that activity no matter who posted a comment. Admins can delete any comments.

11Sep/095

ColdFusion UDF to test if a Java Class implements a method

I recently started implementing a couple of our full text search requirements using Sphinx. I am extremely happy with this search engine, as it's lightning fast and provides some quite easy integration with the data we store in our PostgreSQL databases, is highly scalable and fairly easy to implement in ColdFusion via the Sphinx Client API. 

9Sep/091

FYI: Function returning Void kills Variables

I recently discovered some interesting behaviour in Coldfusion. If you ask for a result of a function in a variable and you set returntype void, the variable is destroyed and cant be found after this.

Example:

<cffunction name="getSomething" returntype="void">
 
     Do something here, like updating a database 
     or increasing a counter value
 
</cffunction>
 
<cfset VARIABLES.RecieveSomething = "">
 
<cfset VARIABLES.RecieveSomething= getSomeThing()>
 
<cfif IsDefined("VARIABLES.RecieveSomething")>
     still there
<cfelse>
     cant found this variable anymore
</cfif>

Returntype Void is kinda tricky, so use it well-considered.

4Sep/090

UDF to grab a frame from an FLV to JPG

This requires FFMPEG to be installed on your server. Here's the UDF:

<cffunction name="flvgrabber" access="public" output="no" returntype="void" hint="grabs a frame from an FLV at a specified second and renders it as a JPG">
	<cfargument name="strPathToFLV" type="string" required="yes" hint="absolute path to the source flv">
	<cfargument name="strPathToJPG" type="string" required="yes" hint="absolute path to the target JPG; if file exists and is writeable, it will be overwritten">
	<cfargument name="strFrameAtTime" type="string" required="no" default="00:00:05" hint="time at which frame should be grabbed in format hh:mm:ss">
	<cfscript>
		var strTMPPath = '/tmp/';
		var strUniqueFname = CreateUUID();
		var strPathToFFMPEG = '/usr/bin/ffmpeg';
		var strArguments = '';
		var qTempFile = '';
	</cfscript>
 
	<cfif not DirectoryExists(getDirectoryFromPath(arguments.strPathToJPG))>
		<cfthrow message="target directory does not exist">
	</cfif>
	<cfif not FileExists(arguments.strPathToFLV)>
		<cfthrow message="source FLV does not exist">
	</cfif>
	<cfif not RefindNoCase('\.flv$',arguments.strPathToFLV)>
		<cfthrow message="source file must be an .flv">
	</cfif>
	<cfif not RefindNoCase('\.jpg$',arguments.strPathToJPG)>
		<cfthrow message="target file must be a .jpg">
	</cfif>		
	<cfif not RefindNoCase('^\d\d:\d\d:\d\d$',arguments.strFrameAtTime)>
		<cfthrow message="time must be set as hh:mm:ss">
	</cfif>
	<cfset strArguments = "-i ""#arguments.strPathToFLV#"" -an -ss #arguments.strFrameAtTime# -an -r 1 -vframes 1 -y #strTMPPath##strUniqueFname#-%d.jpg">		
 
	<cfexecute name="#strPathToFFMPEG#" arguments="#strArguments#" timeout="30"></cfexecute>
	<cfdirectory name="qTempFile" action="list" directory="#strTMPPath#" filter="#strUniqueFname#-*.jpg" listinfo="name" recurse="no" type="file">
	<cffile action="move" source="#strTMPPath##qTempFile.name#" destination="#arguments.strPathToJPG#">		
</cffunction>

And here's how to use it:

<cfscript>
flvgrabber(strPathToFLV='/some/path/some.flv',strPathToJPG='/some/path/some.jpg',strFrameAtTime='00:00:03');
</cfscript>

Have fun!

Tagged as: , , , , No Comments