Skip to content

Instantly share code, notes, and snippets.

View cwg999's full-sized avatar

Cody W. Geisler cwg999

View GitHub Profile
@cwg999
cwg999 / winst-logger.js
Created May 10, 2018 16:00
winst-logger.js
const path = require('path');
const util = require('util');
const { createLogger, format, transports } = require('winston');
const { combine, timestamp, label, printf } = format;
const myFormat = printf(info => {
info.label = info.label.padStart(5,' ');
info.level.padStart(7,' ');
let re = /[\r\n]+/;
if(typeof info.message === "object")
@cwg999
cwg999 / getNumberOfPdfPages.ps1
Last active May 1, 2019 17:45
Get Number of PDF Pages (Greater than 1) Parallel with Throttle Limit
$ArrayList = [System.Collections.ArrayList]@()
# Note: this scripts searches for folders named "Single" recursively from the starting folder.
Get-ChildItem -Path .\ -Recurse | Where-Object {
$_ -is [System.IO.FileInfo] `
-and ($_.Directory.Name -eq 'Single')
} | ForEach-Object {
$ArrayList.add($_.FullName)
}
# Threaded task to use pdfk to get files.
@cwg999
cwg999 / GeneratorPromiseFor.js
Created January 29, 2018 19:57
Generator Promise For Loop example
(function(){ // Generator Promise For Loop
let getFiringResult = delay => new Promise((o,x)=>setTimeout(()=>o(Math.random()),delay));
const fireCannons = (function* (data){
let index = 0;
while(index<5){
index++;
yield getFiringResult(1000);
}
return;
@cwg999
cwg999 / DeclarativeVsImperative.js
Last active January 15, 2018 20:31
Declarative vs Imperative
// Not sure this is accruate, but I was wondering about different styles.
(function(){
let sum = e=>e+1;
let sub = e=>e-1;
let mul = e=>e*e;
let div = e=>1/e;
let dataSet = [1,2,3];
let dataSet2 = [4,5,6];
@cwg999
cwg999 / printablecharacters.js
Created November 30, 2017 04:06
Prints printable characters.
console.log([...Array((127-32)).keys()].map(e=>String.fromCharCode(e+32)).join(''))
@cwg999
cwg999 / gs.js
Created November 14, 2017 15:02
Ghostscript Node execFile (util.promisify) Compress PDF
await execFile(GHOST_SCRIPT_PATH,[
`-q`,`-dNOPAUSE`, `-dBATCH`,`-dSAFER `,
`-sDEVICE=pdfwrite`,
`-dCompatibilityLevel=1.3`,
`-dPDFSETTINGS=/screen `,
`-dEmbedAllFonts=true`,
`-dSubsetFonts=true`,
`-dColorImageDownsampleType=/Bicubic`,
`-dColorImageResolution=300`,
`-dGrayImageDownsampleType=/Bicubic`,
@cwg999
cwg999 / encodeURIComponent.vb
Created September 8, 2017 14:17
encodeURIComponent in VBA for Excel
Function encodeURIComponent(strText As String) As String
Static objHtmlfile As Object
If objHtmlfile Is Nothing Then
Set objHtmlfile = CreateObject("htmlfile")
' objHtmlfile.parentWindow.execScript "function encode(s) {return encodeURIComponent(s)}", "jscript"
End If
encodeURIComponent = objHtmlfile.parentWindow.encodeURIComponent(strText)
End Function
Function decodeURIComponent(strText As String) As String
@cwg999
cwg999 / ps_vs_perl.md
Last active September 8, 2017 14:11
PowerShell vs. Perl

ls <path> | ?{$_.Name -match "^$"}

is shorthand for

Get-Child <path> | Where-Child {$_.Name -match "^$"}

in powershell.

Versus perl -le"foreach (){if(m/^$/){print $_ } }"

@cwg999
cwg999 / currying.js
Created August 4, 2017 18:35
Currying Example
(function (){
const double = (x) => x*2
const output = [1,2,3].map(double);
console.log(output) // [2,4,6]
// Currying
const mult = (i) => (x) => x*i
let aMod = (arr) => (mult) => arr.map(mult);
const arr = [1,2,3];
console.log(aMod(arr)(mult(2)));
@cwg999
cwg999 / compress_pdfs.ps1
Created August 3, 2017 13:55
Compresses PDFs using a ghostscript batch file, (required since ghostscript doesn't like powershell)
$ArrayList = [System.Collections.ArrayList]@()
Get-ChildItem -Path .\ -Recurse | Where-Object {
$_ -is [System.IO.FileInfo] `
-and ($_.Extension.ToLower().CompareTo('.pdf') -eq 0) `
-and ($_.name.CompareTo('out.pdf') -ne 0)
} | ForEach-Object {
$ArrayList.add($_.FullName)
}
workflow Test-Workflow{