Skip to content

Instantly share code, notes, and snippets.

@aliaspooryorik
aliaspooryorik / axis-ticks.js
Last active Feb 27, 2020
Axis ticks based on range
View axis-ticks.js
// based on https://stackoverflow.com/questions/8855026/generate-axis-scale
function calculateTicks(min, max, tickCount) {
var span = max - min,
step = Math.pow(10, Math.floor(Math.log(span / tickCount) / Math.LN10)),
err = tickCount / span * step;
// Filter ticks to get closer to the desired count.
if (err <= .15) step *= 10;
else if (err <= .35) step *= 5;
else if (err <= .75) step *= 2;
View Task.cfc
component {
variables.sourceFiles = [];
variables.componentPaths = [];
variables.verbose = true;
variables.updated = 0;
public function run() {
var sourceFiles = findSourceFiles();
sourceFiles.each(fixDottedPath);
View orderedstructsyntax.cfm
<cfscript>
x = [
"a":1,
"z":2,
"b":3
];
y = {
"a":1,
@aliaspooryorik
aliaspooryorik / listLast.sql
Created Mar 26, 2019
MySQL get last element from delimited list
View listLast.sql
SELECT SUBSTRING_INDEX('1/2/3/4/500', '/', -1) AS last_element;
View BDDTest.cfc
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();
View gist:fbd657962d0f4576af33c0fce7e9f072
<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 / Iterator.cfc
Last active Sep 12, 2018
Iterator based on the IBO pattern
View Iterator.cfc
component {
function init(required query data){
setQuery(arguments.data);
return this;
}
/* ---------------------------- PUBLIC ---------------------------- */
/* --- Iterator methods ---------------------------- */
@aliaspooryorik
aliaspooryorik / assetService.cfc
Last active Sep 10, 2018 — forked from cfvonner/assetService.cfc
Testing a service with dependencies
View assetService.cfc
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 / window_function_paging.sql
Created Aug 29, 2018
efficient MYSQL pagination with window functions
View window_function_paging.sql
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
;
View reg_exp_speed_test.cfm
<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",