Skip to content

Instantly share code, notes, and snippets.

View mikeacjones's full-sized avatar
🚀

Michael Jones mikeacjones

🚀
View GitHub Profile
#region ServiceBase
protected override void OnStart(string[] args)
{
base.OnStart(args);
_MicrosInterface = new MicrosInterface(MicrosMessageHandler, Properties.Settings.Default.ListenPort, Properties.Settings.Default.InterfaceMessageExpected);
_MicrosInterface.Start();
}
protected override void OnStop()
{
base.OnStop();
@mikeacjones
mikeacjones / Bitwise.dwl
Created May 19, 2020 12:22
Bitwise math helper
%dw 2.0
import dw::core::Numbers
import dw::core::Strings
fun AND(lo: Number, ro: Number) = do {
var binary = getBinary(lo, ro)
---
Numbers::fromBinary(binary.left map ($ as Number * binary.right[$$] as Number) reduce ($$++$))
}
@mikeacjones
mikeacjones / Powerset.dwl
Last active April 19, 2023 17:22
Function to return the power set - requires Bitwise.dwl (also in gist)
%dw 2.0
import Bitwise
fun powerSet(set: Array) = do {
var iterable = (0 to pow(2,sizeOf(set))-1) as Array
---
iterable map (item) -> set filter (Bitwise::AND(item,pow(2,$$)) != 0)
}
@mikeacjones
mikeacjones / Namespaces.dwl
Created May 19, 2020 12:48
Function for easily appending namespaces to all key:value pairs of an object. Full traversal, so objects in arrays too.
%dw 2.0
fun appendNamespace(data, nsSelector: (k: Key) -> Namespace | Null) =
data match {
case is Array -> data map appendNamespace($, nsSelector)
case is Object -> data mapObject do {
var ns0 = nsSelector($$)
---
if (ns0 != null) ns0#"$($$)": appendNamespace($, nsSelector)
else ($$): appendNamespace($, nsSelector)
@mikeacjones
mikeacjones / settings.xml
Last active January 6, 2021 16:37
Example settings.xml file for maven CI with Mulesoft
<servers>
<server>
<id>anypoint-exchange-v2</id>
<username>USERNAME</username>
<password>PASSWORD</password>
</server>
<server>
<id>MuleRepository</id>
<username>USERNAME</username>
<password>PASSWORD</password>
@mikeacjones
mikeacjones / hlLoop.dwl
Last active January 6, 2021 16:39
Example hlLoop for EDI - elements use indexing and back-reference relative indexes when building structure. See hlLoop_usage.dwl for example
%dw 2.0
fun hlLoop(payload: Object) =
((payload.DeliveryItems distinctBy $.PurchaseOrder).PurchaseOrder reduce ((order, accum=hlLoopRoot(payload)) ->
payload.DeliveryItems distinctBy $.ProductId reduce ((item, accum=hlLoopPurchaseOrder(order, accum)) ->
(payload.DeliveryItems filter ($.ProductId == item.ProductId and $.ProductBatchNumber != null)) reduce ((package, accum=hlLoopItem(item, accum)) ->
hlLoopPackage(package, accum)
)
)
)).items
@mikeacjones
mikeacjones / hlLoop_usage.dwl
Last active January 6, 2021 16:39
Example usage of hlLoop.dwl - building EDI data format
%dw 2.0
import * from dw::edi::hlLoop
output application/json
---
{
"Delimiters": "|>U\n",
TransactionSets: {
v004010: {
@mikeacjones
mikeacjones / common.dwl
Last active January 6, 2021 16:40
Just some odds and ends functions that I may or may not use. Some of these are just personal experiments.
%dw 2.0
fun getEdges(left: Array, right: Array, isEdgeFn: (l: Object, r: Object) -> Boolean) =
left reduce ((leftItem, mAccum = { li: 0, edges: [] }) ->
(right reduce ((rightItem, iAccum = { li: mAccum.li, ri: 0, edges: mAccum.edges }) ->
{
li: iAccum.li,
ri: iAccum.ri + 1,
edges: iAccum.edges ++ [([iAccum.li, iAccum.ri]) if (isEdgeFn(leftItem, rightItem))]
}
@mikeacjones
mikeacjones / max-matching.dwl
Last active December 10, 2020 02:11
hopcroft-karp implemented using dataweave
%dw 2.0
import * from dw::util::Values
var INF = pow(2, 28) //infinity constant
var ARR = (size, value) -> ((0 to size-1) as Array) map value //make it a bit easier to initialize an array
//function for while looping
var while = (conditionFn: (s: Any) -> Boolean, whileFn: (s: Any) -> Any, state = {}) ->
if (conditionFn(state)) while(conditionFn, whileFn, whileFn(state))
else state
@mikeacjones
mikeacjones / shuffle.dwl
Last active January 6, 2021 16:40
Function to shuffle an array
%dw 2.0
fun splice(arr: Array, index: Number) =
if (index == 0) arr[1 to -1]
else (arr[0 to index-1] default []) ++ (arr[index+1 to -1] default [])
fun shuffle(arr: Array) =
(((0 to sizeOf(arr)-1) as Array) reduce (i, s = {res:[], items: arr}) -> do {
var ri = floor(random() * sizeOf(s.items))
---