Skip to content

Instantly share code, notes, and snippets.

View robertz's full-sized avatar

Robert Zehnder robertz

View GitHub Profile
@robertz
robertz / Diversions.cfc
Last active January 3, 2021 20:32
Using org.json.XML to convert XML to JSON inside a ColdBox event handler. The org.json java library will need to be downloaded to the ColdBox /lib folder or added to the server.
component extends="coldbox.system.EventHandler" {
property name = "SpiderService" inject;
function xmlToJson (event, rc, prc) {
var u = event.getValue("u", "");
prc['data'] = {};
if(u.len()){
var obj = createObject("java", "org.json.XML");
@robertz
robertz / UtilityService.cfc
Last active January 6, 2021 02:15
given an array, return an array of arrays with {{chunkSize}} elements
component {
// given an array, return an array of arrays with {{chunkSize}} elements
function chunk (required array input, required numeric chunkSize) {
var output[1] = [];
var idx = 1;
input.each((item, index) => {
output[idx].append(item);
if(index % chunkSize == 0 && index < input.len()) output[++idx] = [];
})
var gulp = require('gulp');
var sass = require('gulp-ruby-sass');
var concat = require('gulp-concat');
var stripDebug = require('gulp-strip-debug');
var uglify = require('gulp-uglify');
var rimraf = require('gulp-rimraf');
var del = require('del');
var paths = {
jsdir: './_src/js/**/*.js',
@robertz
robertz / ChronService.cfc
Last active February 24, 2021 01:19
ChronService.cfc
component{
function log (required struct criteria) {
cfhttp(url = "https://api.kisdigital.com/chron/log", method = "POST", charset = "utf-8"){
cfhttpparam(type = "header", name = "Content-Type", value = "application/json");
cfhttpparam(type = "body", value = serializeJSON({
"appid": "e92c801d-659a-4548-8a16-b79f6b37cf2d",
"type": criteria.keyExists("type") ? criteria.type : "information",
"log": criteria.keyExists("log") ? criteria.log : "default",
"message": criteria.keyExists("message") ? criteria.message : "No message."
}));
@robertz
robertz / SpiderService.cfc
Created October 2, 2023 12:40
Read page metadata using jSoup in ColdFusion
component {
property name="jSoup" inject="javaLoader:org.jsoup.Jsoup";
function spider( required string link ){
var meta = { "url" : arguments.link, "alt_images" : [] };
try {
var jsDoc = jSoup
.connect( link )
@robertz
robertz / nest.cfc
Last active January 30, 2025 21:02
build nested array of objects from a flat array
// https://trycf.com/gist/5276cc942cc493a1e6f42b74b9f93eb0/lucee5?theme=monokai
data = [
{"id": 1, "message": "one", "parent": 0},
{"id": 2, "message": "two", "parent": 1},
{"id": 3, "message": "three", "parent": 2},
{"id": 4, "message": "four", "parent": 3},
{"id": 5, "message": "five", "parent": 4},
{"id": 6, "message": "six", "parent": 5},
{"id": 7, "message": "seven", "parent": 0},
{"id": 8, "message": "eight", "parent": 7},