Skip to content

Instantly share code, notes, and snippets.

View ivanionut's full-sized avatar
🎯
Focusing

Ivan Ionut ivanionut

🎯
Focusing
View GitHub Profile
@ivanionut
ivanionut / makeHoneyPotLink.cfm
Last active August 29, 2015 14:16 — forked from JamoCA/makeHoneyPotLink.cfm
ColdFusion UDF to generate randomized Honey Pot HTML Code. For use with ProjectHoneyPot.org. (NOTE: You can test this at CFLive.net)
@ivanionut
ivanionut / CSVtoQuery.cfm
Last active May 23, 2023 16:56 — forked from JamoCA/CSVtoQuery.cfm
Convert CSV File to Coldfusion Query Object using ColdFusion & opencsv (Java)
<!---
Convert CSV file to a ColdFusion query object using opencsv.
Requirements:
- ColdFusion 8+ ( http://en.wikipedia.org/wiki/Adobe_ColdFusion )
- opencsv - free parser library for Java ( http://opencsv.sourceforge.net/ )
http://opencsv.sourceforge.net/
opencsv supports all the basic csv-type things you're likely to want to do:
- Arbitrary numbers of values per line
- Ignoring commas in quoted elements
- Handling quoted entries with embedded carriage returns (ie entries that span multiple lines)
@ivanionut
ivanionut / ScopeInjectionProtection.cfm
Last active August 29, 2015 14:16 — forked from JamoCA/ScopeInjectionProtection.cfm
Sample ColdFusion 9+ script to prevent Fallback Scope Injection. URL & Form variables are universally accessible in the scope & used as fallback.
<!--- Sample ColdFusion 9+ script to prevent Fallback Scope Injection. URL & Form variables are universally accessible in the scope & used as fallback.
Based on insights provided by Peter Freitag's blog post http://www.petefreitag.com/item/834.cfm --->
<cfscript>
Scopes = "arguments,local,thread,variables,cgi,cookie,client,request,application,session,server,caller,thistag,this";
for (thisField in Form) {
if (ListLen(thisField,".") GT 1 AND ListFindNocase(Scopes, trim(ListFirst(ThisField,".")))){
StructDelete(Form, thisField);
if (ListFindnocase(Form.Fieldnames, ThisField)){
Form.Fieldnames = ListDeleteAt(Form.Fieldnames, ListFindnocase(Form.Fieldnames, ThisField));
}
<cffunction name="doZipSearch" access="public" returntype="query" >
<cfargument name="zip" />
<cfargument name="radius" />
<cfscript>
//var all the variables to make sure race conditions are prevented
var qzips = false;
var pQry = false;
var rQry = false;
var theList = "";
@ivanionut
ivanionut / sanitizeFileName.cfm
Last active August 29, 2015 14:19 — forked from JamoCA/sanitizeFileName.cfm
ColdFusion UDF to sanitize filename & remove illegal characters & symbols that are incompatible/invalid when used with different languages, OS and devices.
<cfscript>
/* 3/18/2015 sanitizeFileName()
Pass filename, list of options (optional), replacementCharacter (default="") */
function sanitizeFileName(s){
var e = trim(listLast(trim(s), "."));
var rules = "";
var replacementCharacter = "";
if(ArrayLen(Arguments) GTE 2) { rules = Arguments[2];}
if(ArrayLen(Arguments) GTE 3 AND LEN(trim(Arguments[3]))) { replacementCharacter = Arguments[3];}
s = trim(s);
<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>