Enjoy the code shared with you from your fellow developers.
Post By: ryan.everhart
Post Date: 7/3/07 9:31 PM est.
Expires:
Never
Comments:
<cffunction name="onRequest" returnType="void" output="true" >
<cfargument name="page" type="string" required="true" />
<cfset var pagePath = "" />
<cfset request.page = arguments.page />
<cfset pagePath = listDeleteAt(request.page,listLen(request.page,"/" ),"/" ) />
<cfif isDefined("form.fieldnames" )>
<cfinclude template="#arguments.page#" />
<cfelse>
<cftry>
<cfinclude template="#pagePath#/config.cfm" />
<cfcatch> </cfcatch>
</cftry>
<cfinclude template="index.cfm" />
</cfif>
</cffunction>
Post By: tomcornilliac
Post Date: 7/12/07 1:13 PM est.
Expires:
Never
Comments:
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7 ,0 ,0 ,0 " width="217" height="180" id="badge" align="middle" >
<param name="allowScriptAccess" value="all" />
<param name="movie" value="badge.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#FFFFFF" />
<param name="FlashVars" value="appname=My%20Application&appurl=http://www.mydomain.com/myAirApp.air&airversion=1.0.M4&buttoncolor=CC0000&messagecolor=000000&imageurl=test.jpg " />
<embed src="badge.swf" quality="high" bgcolor="#FFFFFF" width="217" height="180" name="badge" align="middle" allowScriptAccess="all" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer " FlashVars="appname=My%20Application&appurl=http://www.mydomain.com/myAirApp.air&airversion=1.0.M4&buttoncolor=CC0000&messagecolor=000000&imageurl=test.jpg " />
</object>
Post By: ryan.everhart
Post Date: 7/16/07 5:56 PM est.
Expires:
Never
Comments:
These two functions work together to generate a password. The first function generates a random password then based passes back the clear password and an encrypted version. The encrypted version is created using the section function.
<!---
+++++++++++++++++++++++++++++++
+ GENERATE RANDOM PASSWORD
+++++++++++++++++++++++++++++++
--->
<cffunction name="generatePassword" access="public" returntype="struct" displayname="Generate Password" output="false"
hint="function to generate a random password for a user, plain and encrypted values" >
<cfscript>
var passStruct = structNew();
var randNum = 0;
var randChar = 'a';
var passList = '';
var passLength = 8;
var alphaLower = 'a|c|e|g|i|k|m|o|q|s|u|w|y|b|d|f|h|j|l|n|p|r|t|v|x|z';
var alphaUpper = 'A|C|E|G|I|K|M|O|Q|S|U|W|Y|B|D|F|H|J|L|N|P|R|T|V|X|Z';
var numeric = '0|2|4|6|8|9|7|5|3|1';
//create a list of characters
var charlist = alphaLower & '|' & numeric & '|' & alphaUpper;
//create the password
for (i = 1; i lte passLength; i = i + 1)
{
randNum = randRange(1 ,listlen(charlist,'|')); //random number for the list location
randChar = listGetAt(charList,randNum,'|'); //get character located at randNum position
passList = listAppend(passList,randChar,' '); //list of characters delimited by space
}
//remove all the spaces from the passList variable to set the new password
passStruct.plainPass = reReplace(passList,' ','','all');
//take the new password and encrypt it
passStruct.encryptPass = encryptPassword(passStruct.plainPass);
//return the structure
return passStruct;
</cfscript>
</cffunction>
<!---
+++++++++++++++++++++++++++++++
+ ENCRYPT PASSWORD
+++++++++++++++++++++++++++++++
--->
<cffunction name="encryptPassword" access="public" returntype="string" displayname="Encrypt Password" output="false"
hint="take a password string and encrypt the value using the password key" >
<cfargument name="plainPass" type="string" required="true" default="all" >
<cfscript>
//DO NOT CHANGE
//this is the random key used to create and read passwords. if you change it all the exisiting passwords will break.
var passwordKey = 'YUndjke395jdiD3j';
encryptPass = trim(encrypt(arguments.plainPass, passwordKey));
return encryptPass;
</cfscript>
</cffunction>
Post By: r.d.wilkerson
Post Date: 9/26/07 1:06 PM est.
Expires:
Never
Comments:
Simple PHP singleton
<?php
class FileHandler {
private static $_instance = null;
private function __construct() {
// restrict access to the constructor
}
public static function getInstance() {
if ( is_null ( self::$_instance ) ) {
self::$_instance = new self();
}
return self::$_instance;
}
/**
* Convenience function for testing.
* Clears the current instance so that it can be reinstantiated rather
* than retrieving the existing instance. Helpful when testing new
* properties, etc.
*/
public function clear() {
self::$_instance = null;
}
public function save ( $rootPath, $source, $fileName, $isTemporary ) {
...
}
public function delete ( $file ) {
...
}
protected function getBinDir() {
return chr ( ( rand ( 0 , 25 ) ) + 97 );
}
public function checkFileSize ( $file, $max ) {
...
}
}
?>
Post By: r.d.wilkerson
Post Date: 9/26/07 5:23 PM est.
Expires:
Never
Comments:
<?php
class DAOFactory {
private static $_instance = null;
private static $_dbhost;
private static $_user;
private static $_password;
private static $_dbname;
private function __construct ( $host, $user, $pwd, $dbname ) {
self::$_dbhaost = $host;
self::$_user = $user;
self::$_password = $pwd;
self::$_dbname = $dbname;
}
public function clear() {
self::$_instance = null;
}
public static function getInstance() {
if ( is_null ( self::$_instance ) && func_num_args() == 4 ) {
$host = func_get_arg ( 0 );
$user = func_get_arg ( 1 );
$pwd = func_get_arg ( 2 );
$dbname = func_get_arg ( 3 );
self::$_instance = new self ( $host, $user, $pwd, $dbname );
}
return self::$_instance;
}
public function createDAO ( $classname ) {
switch ( strtoupper ( $classname ) ) {
case 'SURVEY':
include ( 'com/adcom/creativesurvey/surveydao.php' );
return new surveyDAO ( self::$_dbhost, self::$_user, self::$_password, self::$_dbname );
break;
case 'CREATIVE':
include ( 'com/adcom/creativesurvey/creativedao.php' );
return new creativeDAO ( self::$_dbhost, self::$_user, self::$_password, self::$_dbname );
break;
}
}
}
?>
Post By: brian.rinaldi
Post Date: 9/27/07 11:39 AM est.
Expires:
Never
Comments:
Updated code for TLA.cfc setInventory() function that integrates text-link-ads in ColdFusion. This code wraps the http call in a try to prevent errors when there are outages.
<cffunction name="setInventory" access="public" output="false" returntype="void" >
<cfargument name="referrer" type="string" required="false" default="" />
<cfargument name="userAgent" type="string" required="false" default="" />
<cfset var tlaResponse = "" />
<cfset var tlaURL = "http://www.text-link-ads.com/xml.php?inventory_key= " & variables.inventoryKey />
<cfif len(arguments.referrer)>
<cfset tlaURL = tlaURL & "referer=" & arguments.referrer />
</cfif>
<cfif len(arguments.userAgent)>
<cfset tlaURL = tlaURL & "user_agent=" & arguments.userAgent />
</cfif>
<cftry>
<cfhttp url="#tlaURL#" method="get" result="tlaResponse" timeout="30" />
<cfset variables.xmlInventory = xmlParse(tlaResponse.fileContent) />
<cfcatch type="any" >
<cfset variables.xmlInventory = xmlNew() />
</cfcatch>
</cftry>
</cffunction>
Post By: aqlong
Post Date: 11/5/07 4:55 PM est.
Expires:
Never
Comments:
A gereral-use way of dynamically
creating SQL to easily paginate the results;
also includes a total record count based on
the search criteria in the WHERE clause
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
-- ==================================================
-- Author: Aaron Longnion
-- Create date: 10/18/2007
-- Description: A gereral-use way of dynamically
-- creating SQL to easily paginate the results;
-- also includes a total record count based on
-- the search criteria in the WHERE clause
-- ==================================================
ALTER PROCEDURE [dbo].[sproc_pagination]
-- Add the parameters for the stored procedure here
@SqlColumns VARCHAR(MAX),
@SqlFriendlyColumns VARCHAR(MAX),
@SqlTableClause VARCHAR(MAX),
@StartRow INT,
@EndRow INT,
@SqlWhere VARCHAR(MAX),
@SqlRowNumOrderBy VARCHAR(MAX),
@SqlOuterOrderBy VARCHAR(MAX)
AS
DECLARE @rsSQL NVARCHAR(MAX)
DECLARE @rcSQL NVARCHAR(MAX)
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- build pagination SQL, using StartRow and EndRow to determine
-- which results to output
SET @rsSQL = N' WITH tempTable AS ( ' +
N' SELECT ' +
@SqlColumns +
N' , ROW_NUMBER() OVER(ORDER BY ' +
@SqlRowNumOrderBy +
N' ) AS RowNumber ' +
N' FROM ' +
@SqlTableClause
IF @SqlWhere + '' <> ''
BEGIN
SET @rsSQL = @rsSQL +
N' WHERE ' +
@SqlWhere
END
SET @rsSQL = @rsSQL +
N' ) SELECT ' +
@SqlFriendlyColumns +
N' FROM tempTable ' +
N' WHERE RowNumber >= ' +
CAST(@StartRow AS NVARCHAR(32 )) +
N' AND RowNumber <= ' +
CAST(@EndRow AS NVARCHAR(32 )) +
N' ORDER BY ' +
@SqlOuterOrderBy
-- uncomment PRINT to debug
--PRINT @rsSQL
EXEC sp_executesql @rsSQL
-- build second recordset simple for the count
SET @rcSQL =
N'SELECT COUNT(*) AS CountAll FROM ' +
@SqlTableClause
IF @SqlWhere + '' <> ''
BEGIN
SET @rcSQL = @rcSQL +
N' WHERE ' +
@SqlWhere
END
EXEC sp_executesql @rcSQL
SET NOCOUNT OFF;
END
Post By: aqlong
Post Date: 11/5/07 4:59 PM est.
Expires:
Never
Comments:
<cffunction name="searchTestimonials"
output="false"
access="public"
returntype="struct"
hint="Returns total count and recordset based on search criteria" >
<cfargument name="SearchCrit"
required="true"
type="struct"
hint="Search criteria, usually passed in from the URL scope" />
<cfset var StartRow = "" />
<cfset var EndRow = "" />
<cfset var retStruct = StructNew() />
<cfparam name="Arguments.SearchCrit.Name" type="string" default="" />
<cfparam name="Arguments.SearchCrit.Testimony" type="string" default="" />
<cfparam name="Arguments.SearchCrit.Active" type="numeric" default="1" />
<cfparam name="Arguments.SearchCrit.pg" type="numeric" default="1" />
<cfparam name="Arguments.SearchCrit.RecordsPerPage" type="numeric" default="30" />
<cfparam name="Arguments.SearchCrit.OrderBy" type="string" default="stamp" />
<cfparam name="Arguments.SearchCrit.OrderDirection" type="string" default="DESC" />
<!--- derive start and end rows --->
<cfset StartRow = ((Arguments.SearchCrit.pg-1)*Arguments.SearchCrit.RecordsPerPage)+1 />
<cfset EndRow = (StartRow + Arguments.SearchCrit.RecordsPerPage)-1 />
<cfset retStruct = DAO.readSearch( Arguments.SearchCrit, StartRow, EndRow ) />
<cfreturn retStruct />
</cffunction>
Post By: aqlong
Post Date: 11/5/07 5:03 PM est.
Expires:
Never
Comments:
<!--- readSearch() --->
<cffunction name="readSearch" returntype="struct" output="false" access="package" hint="Returns data that match the specified criteria" >
<cfargument name="SearchCrit" type="struct" required="true" hint="A structure representing the search criteria" />
<cfargument name="StartRow" type="numeric" required="true" hint="First row of results" />
<cfargument name="EndRow" type="numeric" required="true" hint="Last row of results" />
<cfset var returnStruct = StructNew() />
<cfset var SqlCols = '' />
<cfset var SqlTableClause = '' />
<cfset var SqlWhere = '' />
<cfset var SqlOrderBy = '' />
<!--- columns --->
<cfsavecontent variable="SqlCols" >
ID, Name, Active, Caption, Testimony, StampReceived, Stamp </cfsavecontent>
<!--- tables --->
<cfsavecontent variable="SqlTableClause" >
Testimonials
</cfsavecontent>
<!--- conditions --->
<cfoutput>
<cfsavecontent variable="SqlWhere" >
ID > 0
<cfif Len(Arguments.SearchCrit.Name)>
AND name LIKE '%#Arguments.SearchCrit.Name#%'
</cfif>
<cfif Len(Arguments.SearchCrit.Testimony)>
AND Testimony LIKE '%#Arguments.SearchCrit.Testimony#%'
</cfif>
AND active = #Arguments.SearchCrit.Active#
</cfsavecontent>
</cfoutput>
<!--- order --->
<!--- TODO: update to support multiple ORDER BY columns --->
<cfoutput>
<cfsavecontent variable="SqlOrderBy" >
<cfif Len(Arguments.SearchCrit.OrderBy)>
#Arguments.SearchCrit.OrderBy#
<cfif Len(Arguments.SearchCrit.OrderDirection)>
#Arguments.SearchCrit.OrderDirection#
</cfif>
</cfif>
</cfsavecontent>
</cfoutput>
<cfstoredproc procedure="sproc_paging" datasource="#Application.DSN.LDC#" >
<cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" dbvarname="Columns" value="#Trim(SqlCols)#" >
<cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" dbvarname="TableClause" value="#Trim(SqlTableClause)#" >
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" dbvarname="StartRow" value="#Arguments.StartRow#" >
<cfprocparam type="In" cfsqltype="CF_SQL_INTEGER" dbvarname="EndRow" value="#Arguments.EndRow#" >
<cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" dbvarname="SqlWhere" value="#Trim(SqlWhere)#" >
<cfprocparam type="In" cfsqltype="CF_SQL_VARCHAR" dbvarname="SqlOrderBy" value="#Trim(SqlOrderBy)#" >
<!--- return data + count --->
<cfprocresult name="rs" resultset="1" >
<cfprocresult name="recordcount" resultset="2" >
</cfstoredproc>
<cfset returnStruct.rs = rs />
<cfset returnStruct.rc = recordcount.countAll />
<cfreturn returnStruct />
</cffunction>
Post By: landry2104
Post Date: 1/30/08 1:22 PM est.
Expires: 1/31/08 1:30 PM est.
Comments:
/**
*
*/
package dblpq.distance;
import java.util.LinkedList;
import dblpq.person.Person;
/**
* Cette classe nous permetra de donner la distance entre deux auteurs. En d´autre terme,
* elle nous donnera le nombre d´ebene qui separent deux authors...
*
*/
public class DistanceBetweenAuthors {
private Person p1,p2;
private int distance = 0;
public DistanceBetweenAuthors(){}
// public DistanceBetweenAuthors( Person p1 , Person p2){
// this.p1 = p1;
// this.p2 = p2;
//
// }
public boolean areCoAuthors(Person p1, Person p2){
Person[] coAuthors = p1.getCoauthors();
for(Person p : coAuthors){
if(p.getName()==p2.getName()){
return true;
}
}
return false;
}
public int getDistance(Person p1, Person p2){
LinkedList<Person> usedPerson = new LinkedList<Person> ();
if( areCoAuthors(p1,p2)){
distance++;
}
else{
Person[] coAuthors = p1.getCoauthors();
usedPerson.add(p1);
for (int i=0;i<coAuthors.length;i++){
Person coAuthor = coAuthors[i];
usedPerson.add(coAuthor);
for( int j = 0 ; j< coAuthor.getCoauthors().length ;j++ ){
Person p = coAuthor.getCoauthors()[j];
if ( ! usedPerson.contains(p)){
getDistance(coAuthor,p2);
distance++;
}
else{}
}
}
// }
}
return distance;
}
}
Post By: martin.sam
Post Date: 4/22/08 3:34 PM est.
Expires: 4/23/08 3:34 PM est.
Comments:
test
config/autoload.yml:
class: sfAutoloadConfigHandler
config/php.yml:
class: sfPhpConfigHandler
config/databases.yml:
class: sfDatabaseConfigHandler
config/settings.yml:
class: sfDefineEnvironmentConfigHandler
param:
prefix: sf_
config/app.yml:
class: sfDefineEnvironmentConfigHandler
param:
prefix: app_
config/factories.yml:
class: sfFactoryConfigHandler
config/bootstrap_compile.yml:
class: sfCompileConfigHandler
config/core_compile.yml:
class: sfCompileConfigHandler
config/filters.yml:
class: sfFilterConfigHandler
config/logging.yml:
class: sfLoggingConfigHandler
param:
prefix: sf_logging_
config/routing.yml:
class: sfRoutingConfigHandler
config/i18n.yml:
class: sfDefineEnvironmentConfigHandler
param:
prefix: sf_i18n_
modules/*/config/generator.yml:
class: sfGeneratorConfigHandler
modules/*/config/view.yml:
class: sfViewConfigHandler
modules/*/config/mailer.yml:
class: sfDefineEnvironmentConfigHandler
param:
prefix: sf_mailer_
module: yes
modules/*/config/security.yml:
class: sfSecurityConfigHandler
modules/*/config/cache.yml:
class: sfCacheConfigHandler
modules/*/validate/*.yml:
class: sfValidatorConfigHandler
modules/*/config/module.yml:
class: sfDefineEnvironmentConfigHandler
param:
prefix: mod_
module: yes
Post By: doug
Post Date: 9/25/08 8:09 AM est.
Expires: 10/23/08 8:16 AM est.
Comments:
Do you think this is overkill?
<!--- Clear known empty form inputs --->
<cfif structKeyExists(attributes,"submit" )>
<cfset attributes.submit="" />
</cfif>
<cfloop collection="#attributes#" item="x" >
<cfset myText = trim(attributes[x]) />
<cfif len(myText)>
<!--- known SQL Injection attackts --->
<cfset reAttack = "^[A-F0-9]+'?(:?\s|%20)+(:?AND|OR)(:?\s|%20)" />
<cfset reAttack = ListAppend(reAttack,"^[0-9]'[0-9]" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\b([A-Z0-9]+)(:?\s|%20)*'?(:?\s|%20)*=(:?\s|%20)*'?(:?\s|%20)*\1\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bis(:?\s|%20)+(:?not(:?\s|%20)+)?null\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"(:?#x?[A-F0-9]{2,3 };?){2,}" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"(:?%[A-F0-9]{2,2 }){2,}" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"/\*\*/" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bsysObjects\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bSELECT\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bUPDATE\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bINSERT\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bDELETE\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bUNION\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bDESC\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bEXEC\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"'dbo'" ,"|" ) />
<cfif reFindNoCase("(#reAttack#)" ,myText)>
<cfthrow type="userAttack" message="Suspected attack." detail="SQL Injection." />
</cfif>
<!--- known Cross Site Scripting attacts --->
<cfset reAttack = "</?script\b" />
<cfset reAttack = ListAppend(reAttack,"<body\b" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bjavascript(:?\s|%20)*:" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"(:?\\n| \b)document\.\w" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,":(:?\s|%20)*url\(" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bsrc(:?\s|%20)*=(:?\s|%20)*('|" ")" ,"|" ) />
<cfset reAttack = ListAppend(reAttack,"\bvbscript\b" ,"|" ) />
<cfif reFindNoCase("(#reAttack#)" ,myText)>
<cfthrow type="userAttack" message="Suspected attack." detail="Cross Site Scripting." />
</cfif>
</cfif>
</cfloop>