Skip to content

Instantly share code, notes, and snippets.

View kianting's full-sized avatar

Kian, Ting kianting

View GitHub Profile
import java.net.*;
import java.io.*;
import groovy.json.JsonSlurper
import groovy.json.JsonOutput
def queryParameterAsObject(sQueryParameter){
def retVal = [:];
def arrParam = sQueryParameter.split("\\&");
if (arrParam.size() > 1){
arrParam.each{ def keyVal = it?.split('=');
import java.time.*
import java.time.format.*
def formatTime(unixEpochTime, sFormat, sTimeZone){
def objLocalDateTime = LocalDateTime.ofInstant(Instant.ofEpochSecond(unixEpochTime), ZoneId.of(sTimeZone));
return objLocalDateTime.format(DateTimeFormatter.ofPattern("yyyy:MM:dd"));
}
​println formatTime(Math.round((new Date()).getTime()​/1000​)​, 'yyyy:MM:dd', "Pacific/Auckland")​
@kianting
kianting / semvar.groovy
Created September 17, 2020 22:06
Groovy Semvar Pattern Matching
​def semvarPattern = /^(?:(\d+)\.)?(?:(\d+)\.)+?(\*|\d+)$/
def version = '1.1.1.1.1.1.1'
if(!(version ==~ semvarPattern)){
println 'Semvar match fail !!!'
}​​else{
println 'Semvar match success !!!'
}​
@kianting
kianting / mypolicy.xml
Created June 26, 2018 03:27
Rate limiting Mule 3.9 policies to be deployed on-prem
<?xml version="1.0" encoding="UTF-8"?>
<policy id="67891011"
policyName="RateLimitingPolicy"
xmlns="http://www.mulesoft.org/schema/mule/policy"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mule="http://www.mulesoft.org/schema/mule/core"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting"
xmlns:api-platform-gw="http://www.mulesoft.org/schema/mule/api-platform-gw"
xsi:schemaLocation="http://www.mulesoft.org/schema/mule/policy http://www.mulesoft.org/schema/mule/policy/current/mule-policy.xsd
#!/bin/bash
# TO Stop Mule Service in linux
mule stop
# to start mule service
mule start
#to check status of mule service
ps aux | grep mule
@kianting
kianting / fibinaci.js
Created October 8, 2017 22:35
A recursive function that generates a series of Fibonacci numbers based on 2 arguments, the first argument is the starting number of the Fibonacci sequence, the second number is total of elements to generate in the sequence.
// Write your code here.
var fibonaci = function(num, total)
{
if (total === 1){
return [num]
}else{
var list = fibonaci(num, total -1)
list.push(((list[list.length-2] != null) ? list[list.length-2] : 0) + list[list.length-1])
return list
}
@kianting
kianting / Caching.xml
Last active August 8, 2017 03:56
MuleSoft Caching
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
@kianting
kianting / Caching.xml
Created August 8, 2017 03:56
MuleSoft Caching
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:ee="http://www.mulesoft.org/schema/mule/ee/core" xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd
http://www.mulesoft.org/schema/mule/ee/core http://www.mulesoft.org/schema/mule/ee/core/current/mule-ee.xsd">
@kianting
kianting / sendMail.ps1
Created August 8, 2017 00:10
Powershell Script to Send E-Mail
#
#.SYNOPSIS
#Sends SMTP email via the Hub Transport server
#
#.EXAMPLE
#.Send-Email.ps1 -To "administrator@exchangeserverpro.net" -Subject "Test email" -Body "This is a test"
#
param(
[string]$to,
@kianting
kianting / sendmailtest.xml
Last active August 8, 2017 00:05
MuleSoft Send SMTP E-mail
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:smtp="http://www.mulesoft.org/schema/mule/smtp" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/smtp http://www.mulesoft.org/schema/mule/smtp/current/mule-smtp.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>