Skip to content

Instantly share code, notes, and snippets.

@aliaspooryorik
aliaspooryorik / gist:9e23bd0ce7392bf1caa32d3a78110f9e
Created September 27, 2017 14:49
Parse datetime strings in ACF using Java 8
<cfscript>
s = "2017-08-17T14:34:46.260-0400";
//x = parsedateTime("2017-08-17T14:34:46.260-0400", "pop" ) ;
DateTimeFormatter = createObject("java", "java.time.format.DateTimeFormatter");
parseFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss.SSSZ");
LocalDateTime = createObject("java", "java.time.LocalDateTime");
dateTime = LocalDateTime.from(parseFormat.parse(s));
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://cdn.jsdelivr.net/momentjs/2.14.1/moment-with-locales.min.js"></script>
<script src="https://cdn.jsdelivr.net/momentjs/2.14.1/locales.min.js"></script>
@aliaspooryorik
aliaspooryorik / go-example1
Last active August 18, 2017 17:19
Go : Example 1
package main
import (
"fmt"
)
func main() {
text := `The quick brown fox jumps over the lazy dog`
vowels, spaces, constants := 0, 0, 0
@aliaspooryorik
aliaspooryorik / query column as array.cfm
Created August 17, 2017 11:47
query column as array
var newarray = [];
newarray.addAll(q[colname]);
return newarray;
@aliaspooryorik
aliaspooryorik / flatternArray.cfm
Last active July 12, 2017 12:58
Flatten an array
<cfscript>
a = [1,[2,[3,[4,5],6,7],8,9],10];
function recurse(data) {
var result = [];
data.each(function(item) {
if (isArray(item)) {
result.append(recurse(item), true);
} else {
result.append(item);
@aliaspooryorik
aliaspooryorik / flatten.cfm
Created July 11, 2017 11:40
Flatten complex data
<cfscript>
struct = {
"a": 1,
"b": 2,
"c": 3,
"d": {
"e": 4
}
};
<cfscript>
function foo() {
var i = 0;
local.j = 0;
local.cat = 1;
var bat = 2;

Transformation Priority Premise

  • ({} → nil) no code at all → code that employs nil
  • (nil → constant)
  • (constant → constant+) a simple constant to a more complex constant
  • (constant → scalar) replacing a constant with a variable or an argument
  • (statement → statements) adding more unconditional statements.
  • (unconditional → if) splitting the execution path
  • (scalar → array)
  • (array → container)
The html...
<!DOCTYPE html>
<html lang="en">
<head>
</head>
<body>
<h3>Submit Some Hidden Form Data</h3>
@aliaspooryorik
aliaspooryorik / bleeding_variables.cfc
Last active March 3, 2017 14:26
Find bleeding variables
component extends="testbox.system.BaseSpec" {
function run(testResults, testBox) {
it ("should not bleed variables", function() {
prepareMock(variables.sut).$property("getVariablesScopeList", "this", getVariablesScopeList);
var before = sut.getVariablesScopeList();
sut.doSomething();
var after = sut.getVariablesScopeList();
expect(before).toBe(after, "variables have leaked!");
});