Skip to content

Instantly share code, notes, and snippets.

View thecfguy's full-sized avatar

Pritesh thecfguy

View GitHub Profile
@thecfguy
thecfguy / index.cfm
Created December 17, 2013 09:33
One-to-One relationship with primary key and unique key combination. This example has relationship triangle. :)
<cfscript>
ormreload();
//Save
objt6 = tbl6Service.new({"col":"tbl6"});
objt7 = tbl7Service.new({"col":"tbl7"});
objt8 = tbl8Service.new({"col":"tbl8"});
objt6.addTbl8(objt8);
@thecfguy
thecfguy / onetomany.cfc
Last active December 31, 2015 07:49
one-to-many and many-to-one relationship
component output="false" singleton{
// Default Action
property name="masterService" inject="entityService:tmaster" scope="variables";
property name="detailService" inject="entityService:tdetail" scope="variables";
function index(event,rc,prc){
var queryService = new query();
queryService.execute(sql="delete from tmaster where id not in (select masterid from tdetail)");
queryService.execute(sql="DELETE FROM tdetail WHERE masterid not IN (select id from tmaster) or masterid is null");
var msg = {};
var myid = getTickCount();
@thecfguy
thecfguy / save.cfc
Created December 14, 2013 08:07
Many-to-Many ColdFusion/ColdBox ORM
<cfcomponent output="false">
<cfproperty name="tbl1Service" inject="entityService:tbl1" scope="variables">
<cfproperty name="tbl3Service" inject="entityService:tbl3" scope="variables">
<cffunction name="index" access="public" returntype="void" output="false">
<cfargument name="event" type="any">
<cfscript>
var objT1 = tbl1Service.new({"col1":"new"});
var objT3 = tbl3Service.new({"column2":'New'});
<cfparam name="url.x" default="1;delete from x">
<cfset esapi = CreateObject("java", "org.owasp.esapi.ESAPI").encoder()>
<cfset codec = createObject("java","org.owasp.esapi.codecs.MySQLCodec").init(0)>
<cfset url.x = esapi.encodeForSQL(codec, url.x)>
<cfquery name="q" datasource="amex">
select * from [users]
where id like #url.x#
</cfquery>
<cfdump var="#q#" />
@thecfguy
thecfguy / zapreport.xsl
Created November 23, 2013 06:34
Render ZAP export in human readable format. Just add <?xml-stylesheet type="text/xsl" href="zapreport.xsl"?> next to top most <?xml ...> tag and open xml file any new generation browser.
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
<html>
<head>
<style>
body{
font-family: verdana,arial,sans-serif;
<cfscript>
writeOutput("Before lock at #now()#");
lock name="threadlock" timeout="3" type="exclusive"
{
writeOutput("<br/>started at #now()#");
thread action="sleep" duration="10000";
writeOutput("<br/>ended at #now()#");
}
writeOutput("<br/>After lock at #now()#");
</cfscript>
@thecfguy
thecfguy / generatepdf.cfm
Created October 16, 2013 07:23
Generate PDF using CFDOCUMENT with custom fonts
<cfdocument format="PDF" fontembed="true" filename="#expandpath('./test.pdf')#" overwrite="true"><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Test</title>
<style type="text/css">
@font-face
{font-family:"Calibri"; }
@font-face
{font-family:"Impact"; }
@font-face
@thecfguy
thecfguy / pd4fonts.properties
Created October 16, 2013 07:22
RAILO font properties file to add additional font.
#this is an autogenerated file. please remove manually any references to copyrighted fonts
#Fri Apr 17 20:00:52 CEST 2009
Arial=arial.ttf
Arial\ Bold=arialbd.ttf
Arial\ Bold\ Italic=arialbi.ttf
Arial\ Italic=ariali.ttf
Courier\ New=cour.ttf
Courier\ New\ Bold=courbd.ttf
Courier\ New\ Bold\ Italic=courbi.ttf
Courier\ New\ Italic=couri.ttf
@thecfguy
thecfguy / peoplesearch.cfm
Created October 2, 2013 10:12
Get people search for linkedin
<cfhttp url="https://api.linkedin.com/v1/people-search:(people:(id,first-name,last-name))">
<cfhttpparam type="header" name="content-type" value="application/x-www-form-urlencoded">
<cfhttpparam type="url" name="oauth2_access_token" value="[access-token]">
<cfhttpparam type="url" name="first-name" value="pritesh">
<cfhttpparam type="url" name="last-name" value="patel">
<cfhttpparam type="url" name="format" value="json">
<cfhttpparam type="url" name="count" value="2">
</cfhttp>
<cfset response = deserializeJSON(cfhttp.filecontent)>
<cfparam name="url.param1" default="URL Parameter 1">
<cfparam name="url.param2" default="URL Parameter 2">
<cfscript>
function callme(){
var url = "http://www.thecfguy.com";
writedump([url,local.url]);
}
callme();
writedump(url);
abort;