ColdFusion Removing duplicate values from a list

To get the number unique values from a list you can create a Java set, which does not allow duplicate values

createObject("java", "java.util.HashSet").init(listToArray(valueList(eventsQuery.event_id))).size();

The init values requires a list, so if you already have a list, you can just pass that in to return a Java set object. You will need to convert the set back to a list to make it easy to work with in ColdFusion although you could iterate over it if you’d like. Here’s the easiest version.

listWithDupes = [1,2,3,1,3];
noDupes = createObject("java", "java.util.HashSet").init(listWithDupes);
noDupesArray = createObject("java", "java.util.ArrayList").init(noDupes);
writeDump(noDupesArray); //returns 1,2,3

read more

Detecting a Credit Card number in a field using JavaScript

Given a field such as <input id="notes" type="text" names="notes"> You can detect a Credit Card number using the following in jQuery. This will detect 15 or 16 digit credit card numbers because of the d{3,4}. To only detect 15 or 16 change that to be only d{3} for 15 or d{4} for 16.

$('#notes').on('input', function() {
    const ccDetected = $('#notes').val().match(/\b(?:\d{4}[ -]?){3}(?=\d{3,4}\b)/gm);
    if (ccDetected) {
        alert('don''t use credit cards!');
    }
});

read more

Update LibreELEC to version 9 for Kodi 18

Kodi version 18 has been released as has LibreELEC version 9.

If you’ve checked for updates on your Raspberry Pi and nothing is showing here’s the solution.

  1. Go to the LibreELEC Add-On
  2. Change Automatic Updates from Auto to Manual
  3. Enable Show Custom Channels and then disable it
  4. From the Update Channelmenu chooseLibreELEC-9.0
  5. Go to Available Versions
  6. Install 9.0.0 (or the latest)
  7. Turn Automatic Updates back on
  8. Repeat when LibreELEC version 10 comes out

read more

SurveyMonkey CX API call

SurveyMonkey has a great new API available that allows you to easily send someone an email programmatically. I ran into some hiccups while setting it up and there’s almost zero documentation out there.

Endpoint: This is provided at the end of setting up a survey. Should look like

https://cx.surveymonkey.com/api/v1/surveys/${fromSurvey}/replies

Headers

name="Content-Type" value="application/json"
name="Authorization" value="Token token=#apiToken#"

Body

{
    "person": {
        "email": "emailAddress",
        "first_name": "first name",
        "last_name": "last name",
        "fields": {
            "Custom Field": ["custom field value"]
        }
    },
    "delay": 0
}

The custom fields must match exactly what you put in your admin and you must pass it in as a list. If you don’t pass a list it won’t register. The delay is the number of days to delay sending the survey.

My full postman request is below with sensitive information redacted.

  "info": {
    "_postman_id": "d16018c3-53d9-4ebd-a47f-61a84505a04d",
    "name": "SurveyMonkey",
    "schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
  },
  "item": [
    {
      "name": "Survey Monkey",
      "request": {
        "method": "POST",
        "header": [
          {
            "key": "Content-Type",
            "value": "application/json",
            "type": "text"
          },
          {
            "key": "Authorization",
            "value": "Token token=${apiToken}",
            "type": "text"
          }
        ],
        "body": {
          "mode": "raw",
          "raw": "{\r\n  \"person\": {\r\n    \"email\": \"email@gmail.com\",\r\n    \"first_name\": \"First\",\r\n    \"last_name\": \"Last\",\r\n    \"fields\": {\r\n      \"Products\": [\"Acme M500\", \"Acme B7500\"]},\r\n  \"facets\": {\r\n    \"Job ID\": \"1234\"\r\n  },\r\n  \"delay\": 24\r\n}"
        },
        "url": {
          "raw": "https://cx.surveymonkey.com/api/v1/surveys/${fromSurvey}/replies",
          "protocol": "https",
          "host": ["cx", "surveymonkey", "com"],
          "path": ["api", "v1", "surveys", "${fromSurvey}", "replies"]
        }
      },
      "response": []
    }
  ]
}

read more

Updating all sub modules in a git project

This command will find all the submodules in your current git projects and pull down changes from master for each submodule.

git submodule -q foreach git pull -q origin master

Once you pull down changes make sure you push the changes back to your project to see the changes.

What is this actually doing?

git submodule basically gets all the submodules in your project

-q means quiet which means it doesn’t output the name of the submodule as it loops through them. This parameter is not required.

foreach um, it loops through each submodule

git pull -q origin master this pulls down the changes from master on the submodule and doesn’t output the changes. Again, the -q is not required, but will reduce the conole output.

read more