Skip to content

Instantly share code, notes, and snippets.

View robertz's full-sized avatar

Robert Zehnder robertz

View GitHub Profile
@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 / 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."
}));
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 / 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] = [];
})
@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");
<cffunction name="xmlToStruct" access="public" returntype="struct" output="false">
<cfargument name="xmlNode" type="string" required="true" />
<cfscript>
var res = {};
var xmlDoc = xmlSearch(xmlParse(xmlNode), "/node()")[1];
for(var i = 1; i <= xmlDoc.xmlChildren.len(); i++){
var n = replace(xmlDoc.XmlChildren[i].XmlName, xmlDoc.XmlChildren[i].XmlNsPrefix & ":", "");
if(res.keyExists(n)){
if(!isArray(res[n])){
tmp = res[n];
[
{
"userId": 1,
"id": 1,
"title": "I rewrote the title",
"body": "quia et suscipit\nsuscipit recusandae consequuntur expedita et cum\nreprehenderit molestiae ut ut quas totam\nnostrum rerum est autem sunt rem eveniet architecto"
},
{
"userId": 1,
"id": 2,
@robertz
robertz / example1.cfm
Last active July 10, 2019 00:17
example httpRequest file
<cfscript>
baseUrl = "https://jsonplaceholder.typicode.com";
api = new API();
api
.setUrl( baseUrl & '/posts')
.execute();
writeDump(api.getResult());
component output = "false" {
public function init() {
variables['instance'] = {};
instance['hasExecuted'] = false;
instance['isJson'] = "";
instance['created'] = now();
instance['url'] = "";
instance['resolvedUrl'] = "";
instance['verb'] = "GET";
param([string] $userName = "coh",
[string] $userPassword = "coh")
$ErrorActionPreference = "STOP"
function Get-Adler32 {
param(
[string] $data
)