Skip to content

Instantly share code, notes, and snippets.

@aliaspooryorik
aliaspooryorik / cheatsheet.ts
Last active June 21, 2023 08:35
Typescript Cheatsheet
/* eslint-disable no-console */
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-inferrable-types */
/* eslint-disable no-unused-vars */
/*
WATCH: https://www.youtube.com/playlist?list=PLNqp92_EXZBJYFrpEzdO2EapvU0GOJ09n
*/
/*
@aliaspooryorik
aliaspooryorik / axis-ticks.js
Last active February 27, 2020 12:14
Axis ticks based on range
// 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;
@aliaspooryorik
aliaspooryorik / Task.cfc
Created February 16, 2020 21:35
Fix case Task
component {
variables.sourceFiles = [];
variables.componentPaths = [];
variables.verbose = true;
variables.updated = 0;
public function run() {
var sourceFiles = findSourceFiles();
sourceFiles.each(fixDottedPath);
@aliaspooryorik
aliaspooryorik / orderedstructsyntax.cfm
Created March 29, 2019 10:04
orderedstructsyntax
<cfscript>
x = [
"a":1,
"z":2,
"b":3
];
y = {
"a":1,
@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 / 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();
<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 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 ---------------------------- */
@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 / 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
;