Skip to content

Instantly share code, notes, and snippets.

View evagoras's full-sized avatar

Evagoras Charalambous evagoras

View GitHub Profile
@evagoras
evagoras / gist:5801584
Created June 18, 2013 00:00
Method to convert a Query to a CSV
<!---
Method to convert query to csv
(sourced from http://www.bennadel.com/blog/1231-Converting-A-ColdFusion-Query-To-CSV-Using-QueryToCSV-.htm)
Change: argument "Fields" not mandatory, taking by default all of the columns in the query.
--->
<cffunction
name="QueryToCSV"
access="public"
returntype="string"
output="false"
@evagoras
evagoras / Task.cfc
Last active September 30, 2015 09:14
ColdBox Bean to JSON
// transient bean
component accessors="true" {
// properties
property name="Code" type="string";
// validation
this.constraints = {
};
@evagoras
evagoras / Routes.cfm
Last active October 5, 2015 18:24
ColdBox - REST - Issue with list() method getting called every time
<cfscript>
// Allow unique URL or combination of URLs, we recommend both enabled
setUniqueURLS(false);
// Auto reload configuration, true in dev makes sense to reload the routes on every request
//setAutoReload(false);
// Sets automatic route extension detection and places the extension in the rc.format variable
setExtensionDetection(true);
// The valid extensions this interceptor will detect
// setValidExtensions('xml,json,jsont,rss,html,htm');
setValidExtensions('json');
@evagoras
evagoras / RemoveRows.cfm
Last active October 6, 2015 15:19
Removes unwanted records from a ColdFusion Query object to help with pagination.
<cfscript>
/**
* @hint Used for pagination, removes unwanted rows from a query.
* @qry The entire query object to be trimmed.
* @skip How many records to remove from the start.
* @take How many records to return after the @skip. -1 gets everything.
*/
query function RemoveRows
(
required query qry,
<cfscript>
/**
* @hint A simple interceptor that logs method calls and their results
*/
component implements="coldbox.system.aop.MethodInterceptor" {
property name="log" inject="logbox:logger:{this}";
@evagoras
evagoras / CustomOnRequestCaptureInterceptor.cfc
Last active December 9, 2015 18:28
Problem and possible solution for ColdBox ORM handling of NULLs
component {
void function onRequestCapture( any event, struct interceptData, any buffer ) {
if( listFindNoCase( "PUT,PATCH,DELETE", event.getHTTPMethod() ) ) {
// Content sent in from the client
var requestContent = toString( getHTTPRequestData().content );
// If the package is JSON, then deserialize and add to the RC collection
if ( isJson(requestContent) ) {
var jsonRequestContent = deserializeJson( requestContent );
var nullProperties = "";
@evagoras
evagoras / _createBatchFile.cfc
Last active September 28, 2023 16:21
Printing ZPL using CFML
<cffunction name="_createBatchFile" access="private" returntype="string" output="false">
<cfset var LOCAL = structNew() />
<cfset LOCAL.bFileExists = false />
<cfset LOCAL.cAbsoluteFilePath = expandPath( "/print-zpl.bat" ) />
<cfset LOCAL.cFileContents = "" />
<cfif fileExists( LOCAL.cAbsoluteFilePath )>
<cfset LOCAL.bFileExists = true />
</cfif>
@evagoras
evagoras / base.cfc
Last active March 4, 2016 09:12
ColdBox base object for Beans using Virtual Entity
component {
// Framework Services
property name="cbEntityService" inject="entityService";
property name="cbValidator" inject="ValidationManager@cbvalidation";
// Custom Services
property name="utils" inject="utils" persistent=false getter=false setter=false;
@evagoras
evagoras / update.sh
Last active September 28, 2023 16:21
Upgrading CommandBox on a Mac using Homebrew
# grant write permissions to the local user
sudo chgrp -R admin /usr/local
sudo chmod -R g+w /usr/local
# update brew
brew update
# upgrade CommandBox
brew upgrade commandbox
@evagoras
evagoras / baseHandler.cfc
Last active May 22, 2018 14:09
ColdBox 3.x base OPTIONS function
public any function options( event, rc, prc ){
var allowedVerbs = "";
var currentEvent = event.getCurrentEvent();
var sesInterceptor = getInterceptor( "SES" );
var moduleName = event.getCurrentModule();
var handler = currentEvent.listRest( ":" ).listDeleteAt( listFind( currentEvent, "options", "." ), "." );
var currentRoute = event.getCurrentRoute();
// list of routes in the SES Interceptor
var routes = sesInterceptor.getModuleRoutes( moduleName );
arrayEach(