Skip to content

Instantly share code, notes, and snippets.

@aliaspooryorik
aliaspooryorik / validateemails.cfm
Last active April 16, 2018 15:07
validate email example
<cfscript>
input = [
'[email protected]',
'bar@locahost',
'bar"locahost'
];
foo = validateEmails(input);
writeDump(foo.hasErrors());
writeDump(foo.getErrors());
@aliaspooryorik
aliaspooryorik / range.cfml
Created July 18, 2018 16:14
CFML range - no loops
// not intended for real-life usage :)
function range (start, end) {
return repeatString("_,", end-start+1).listToArray().map(function(el, i) {
return start+i-1;
});
}
@aliaspooryorik
aliaspooryorik / reg_exp_speed_test.cfm
Last active July 20, 2018 13:55
reg exp speed test
<cfscript>
function test(pattern) {
return ReReplace(s, pattern, "-----", 'all');
}
s = "Fred Bloggs says 'My name is Fred
bloGGs my brother is Alfred Bloggs and I blog about people called fred or freddie'. x:Fred bloggss y: Fred bloggsss Yours FRED BLOGGS";
variations = [
"(?im)(?:(\b|^)Fred\s+Bloggss?(\b|$))",
"(?im)(\b|^)Fred\s+Bloggss?(\b|$)",
"(?im)\bFred\s+Bloggss?\b",
@aliaspooryorik
aliaspooryorik / window_function_paging.sql
Created August 29, 2018 10:57
efficient MYSQL pagination with window functions
SELECT *
FROM (
SELECT uuid,
row_number() over (ORDER BY uuid) AS rn,
count(*) over () AS totalrows
FROM tblfoo
) AS tmp
WHERE rn BETWEEN 212201 AND 212210
ORDER BY uuid
;
@aliaspooryorik
aliaspooryorik / assetService.cfc
Last active September 10, 2018 17:53 — forked from cfvonner/assetService.cfc
Testing a service with dependencies
component displayname="GIS Plant Asset Service" extends="app.model.services.baseService" accessors="true" {
property assetGateway;
public array function list() {
return populateBeans( "assetBean", assetGateway.select() );
}
public array function getByAssetID ( required string assetid ) {
var data = assetGateway.select( { assetid : assetid } );
@aliaspooryorik
aliaspooryorik / Iterator.cfc
Last active September 12, 2018 23:43
Iterator based on the IBO pattern
component {
function init(required query data){
setQuery(arguments.data);
return this;
}
/* ---------------------------- PUBLIC ---------------------------- */
/* --- Iterator methods ---------------------------- */
<cfscript>
// asked in cfml slack #cfml-beginners
function getNodePaths(xmldoc) {
var nodes = extractTextNodes(xmldoc);
var xPaths = [];
for (var node in nodes) {
xPaths.append(getXPath(node));
}
return xPaths;
@aliaspooryorik
aliaspooryorik / BDDTest.cfc
Created March 12, 2019 16:22
Simple BDD test
component extends="testbox.system.BaseSpec" {
function run(testResults, testBox) {
Feature("TestSuite", function() {
Given("I want to use TestBox", function() {
When("I run the TestSuite", function() {
Then("It should find and run tests", function() {
expect(true).toBeTrue();
@aliaspooryorik
aliaspooryorik / listLast.sql
Created March 26, 2019 15:04
MySQL get last element from delimited list
SELECT SUBSTRING_INDEX('1/2/3/4/500', '/', -1) AS last_element;
@aliaspooryorik
aliaspooryorik / orderedstructsyntax.cfm
Created March 29, 2019 10:04
orderedstructsyntax
<cfscript>
x = [
"a":1,
"z":2,
"b":3
];
y = {
"a":1,