Skip to content

Instantly share code, notes, and snippets.

@roulupen
roulupen / gist:4155963
Created November 27, 2012 18:10
Settng cookie by cfscript in ColdFusion 10
<cfscript>
/* ************** Setting Cookie by cfscript in ColdFusion 10 *********** */
//Type - 1
variables.cookieTest = structNew();
variables.cookieTest['value'] = "This is test Cokkie by me by using cfscript";
variables.cookieTest['expires'] = "10";
variables.cookieTest['secure'] = "yes";
variables.cookieTest['domain'] = "cf10";
cookie.myNewCookie = variables.cookieTest;
@roulupen
roulupen / gist:4173355
Created November 30, 2012 02:15
ColdFusion 10 New Structure Declaration. [Added in Blod]
<cfscript>
//New Type Structure declaration introduced in ColdFusion 10
request.employee = {
name: "Upendra Roul",
ID: "06-800",
JobTitle: "ColdFusion Developer"
};
writeDump(request.employee);
@roulupen
roulupen / gist:4269901
Created December 12, 2012 17:40
Extract Text from HTML
<div id="fb-root">&nbsp;</div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id))
return; js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=154111381338316";
fjs.parentNode.insertBefore(js, fjs);
}(document, 'script', 'facebook-jssdk'));
@roulupen
roulupen / gist:4270054
Created December 12, 2012 17:56
Extract Text from HTML Code in ColdFusion
<cfsavecontent variable="request.htmlString">
<div id="fb-root">&nbsp;</div>
<script>
(function(d, s, id) {
var js, fjs = d.getElementsByTagName(s)[0];
if (d.getElementById(id))
return; js = d.createElement(s);
js.id = id;
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1&appId=1234567890";
fjs.parentNode.insertBefore(js, fjs);
<cfscript>
request.inputString = "RajaRamMohamRoy";
request.outputString = rEReplace(request.inputString, "([a-z])([A-Z])", "\1 \2", "ALL");
writeOutput("<b>Input String:</b>" & request.inputString & "<br/>");
writeOutput("<b>Output String:</b>" & request.outputString & "<br/>");
/*
Here regular expression we have used is "([a-z])([A-Z])"
then replacing that matching pattern with "\1 \2". Which means we are searching for a string
which lower case and upper case letter consecutively. Like aA or bC.
@roulupen
roulupen / gist:4297073
Created December 15, 2012 16:55
Google API URL Shortening by ColdFusion
<cffunction name="shortenURLByGoogleAPI" access="public" returntype="Struct" hint="Takes long url as input parameter returns a struct containing both short and long url">
<cfargument name="longURL" required="true" type="string" hint="Long URL value" />
<cfset var httpReturnStruct = structNew() />
<cfset var inputParameter = {"longUrl" = arguments.longURL } />
<cfhttp url="https://www.googleapis.com/urlshortener/v1/url" method="post" result="httpReturnStruct">
<cfhttpparam type="header" name="Content-Type" value="application/json" />
<cfhttpparam type="body" value="#serializeJSON(inputParameter)#" />
</cfhttp>
@roulupen
roulupen / gist:4303899
Created December 16, 2012 06:51
Custom Tag - Part II
import com.allaire.cfx.* ;
public class HelloColdFusion implements CustomTag
{
public void processRequest( Request request, Response response )
throws Exception
{
String strName = request.getAttribute( "NAME" ) ;
response.write( "Hello, " + strName ) ;
}
<cfscript>
//function defined in cfm page which will add two number and will return the value
function addTwoNumber(num1, num2) {
return num1 + num2;
}
varriable.x = variables.addTwoNumber; //Function defined in this page is assigned to the variable x
writeOutPut("Call to addTwoNumber : " & varriable.x(10,12)); //Function call to AddTwoNumber by using variable
variables.y = createObject("component", "test").addTwoNum; // Function defined in test.cfc is assigned to variable y
component {
public function addTwoNum(num1, num2) {
return num1 + num2;
}
}
<cfscript>
public boolean function ListCompare(required string list,required string sublist,string delim=",") {
var local = {}; //Local scope declaration
local.qryFilterResult = queryNew(""); //Declaring query object to hold filtered list
try {
/* Creating a query object from the list passes in the argumnet */
local.qryOriginalList = queryNew("");
queryAddColumn(local.qryOriginalList, "listElement", "CF_SQL_VARCHAR", listToArray(arguments.list, arguments.delim));