Skip to content

Instantly share code, notes, and snippets.

View ivanionut's full-sized avatar
🎯
Focusing

Ivan Ionut ivanionut

🎯
Focusing
View GitHub Profile
<cfscript>
// Query to retrieve some data from the database
variables.myData = queryExecute(
sql = "
SELECT *
FROM myTable
LIMIT 10
",
options = {datasource="#Application.myDSN#"}
);
<cfscript>
// If you don't set this then the searchParams structure will be uppercased when converted to JSON and cause ElasticSearch to error.
processingdirective preserveCase="true";
public struct function elasticSearchSearch( required string serverURL,
required struct searchParams,
required string index,
required string type) {
// Post the search parameters to the ElasticSearch index and type
http method="post" url="#arguments.serverURL#/#arguments.index#/#arguments.type#/_search" result="searchResponse" {
<cfscript>
function convertSecondsToTimeString(seconds) {
local.hours = arguments.seconds \ 3600;
local.minutes = (arguments.seconds \ 60) mod 60;
local.seconds = (arguments.seconds) mod 60;
return numberformat(local.hours, "0") & ":" & numberformat(local.minutes, "00") & ":" & numberformat(local.seconds, "00");
}
</cfscript>
<cfoutput>
<cfscript>
public any function getWeekOfMonth(date d='#Now()#', numeric minDaysInFirstWeek=1) {
var cal = CreateObject('java', 'java.util.GregorianCalendar').init(
JavaCast('int', Year(arguments.d))
, JavaCast('int', Month(arguments.d)-1)
, JavaCast('int', Day(arguments.d))
, JavaCast('int', Hour(arguments.d))
, JavaCast('int', Minute(arguments.d))
, JavaCast('int', Second(arguments.d))
);
<cfscript>
public any function isoDateTimeFormat(date timestamp='#Now()#') {
var dt = DateConvert('local2utc', arguments.timestamp);
return DateFormat(dt, 'yyyy-mm-dd') & 'T' & TimeFormat(dt, 'HH:mm:ss.000') & 'Z';
}
</cfscript>
<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;
<!--- Get request from ColdFusion page contenxt. --->
<cfset objRequest = GetPageContext().GetRequest() />
<!--- Get requested URL from request object. --->
<cfset strUrl = objRequest.GetRequestUrl().Append(
"?" & objRequest.GetQueryString()
).ToString()
/>
CREATE TABLE `comuni` (
`id` smallint(4) NOT NULL,
`comune` varchar(48) NOT NULL DEFAULT '',
`prefisso` char(4) NOT NULL DEFAULT '',
`cap` char(5) NOT NULL DEFAULT '',
`codice_istat` char(6) NOT NULL DEFAULT '',
`codice_catasto` char(4) NOT NULL DEFAULT '',
`id_provincia` tinyint(3) NOT NULL,
`sigla` char(2) NOT NULL DEFAULT '',
`provincia` varchar(48) NOT NULL DEFAULT '',
<cfscript>
// Create an instance of the mail object
mail=new mail();
// Set it's properties
mail.setSubject( "Sample Email" );
mail.setTo( "[email protected]" );
mail.setFrom( "[email protected]" );
mail.setCC( "[email protected]" );
mail.setBCC( "[email protected]" );
<!--- place in /controllers folder--->
<cfcomponent extends="Controller">
<cffunction name="getdemo" returntype="Query" access="private" >
<cfset var entries = model("entry").findAll(select="BODY,CATEGORYID,TITLE,dateCreated") />
<cfreturn entries />
</cffunction>
<cffunction name="init">
<cfset filters(through="turnOffDebugging",only="processing")>