Skip to content

Instantly share code, notes, and snippets.

@tluyben
tluyben / assert.js
Created November 27, 2020 07:06
partial deep assert
const processOutput = (_output, _outputExample) => {
Object.keys(_outputExample).forEach((k)=>{
const val = _outputExample[k]
if (val != null && Array.isArray(val)) {
assert.deepStrictEqual(_output[k], val)
} else if (typeof val == 'object' && val != null) {
processOutput(_output[k], val)
} else {
assert.strictEqual(_output[k], val)
@tluyben
tluyben / gist:b33548e1a3b8ed120312369fa67fb522
Created October 30, 2020 15:02
Run openwhisk playground on a public IP address with Nginx
On the same server as OpenWhisk with the playground running, add the Nginx config;
server {
listen 443;
listen [::]:443;
server_name whisk.server.com;
location ~ /api/v1/* {
proxy_pass http://172.17.0.1:3233;
@tluyben
tluyben / ofxint.pl
Created September 13, 2020 10:38
OFX hack for using the historical forex rates to fix csv files with a conversion rate
#!/usr/bin/perl
=begin comment
Go here: https://www.ofx.com/en-us/forex-news/historical-exchange-rates/
open developer tools in Chrome
paste in console;
@tluyben
tluyben / mt940.pl
Last active September 13, 2020 09:51
MT940 to csv convertor - specifically written to quickly analyse a large mt940 file, but very easy to change / append to
#!/usr/bin/perl
%fieldmapping = ( '20'=>'transaction_ref', '25'=>'account_ref', '28C' => 'statement_no', '86'=>'account_owner',
'61'=>'amount', '60F' => 'opening_balance', '62F'=>'closing_balance' );
@fieldorder = ($fieldmapping{'20'}, $fieldmapping{'25'}, 'date', $fieldmapping{'28C'}, $fieldmapping{'86'},
'currency', $fieldmapping{'61'}, $fieldmapping{'60F'}, $fieldmapping{'62F'});
$last = "";
$skipline = 0;
@tluyben
tluyben / verhoef.cs
Last active August 21, 2020 13:43
Verhoeff's Dihedral Group D5 Check raw port from JS
using System;
public class Program
{
int[][] F = new int[8][];
int[][] Op = new int[10][];
int[] Inv = new int[] { 0, 4, 3, 2, 1, 5, 6, 7, 8, 9 };
public Program()
{
private T GetContext<T>() where T : DbContext
{
var options = new DbContextOptionsBuilder<T>().UseNpgsql(connection).Options;
return (T) typeof(T).GetConstructor(new Type[] { typeof(DbContextOptions<T>) }).Invoke(new object[] { options });
}
/// <summary>
/// Copy every matching property from source -> target
/// </summary>
/// <param name="target"></param>
/// <param name="source"></param>
public static void Slurp(this object target, object source)
{
target.GetType()
.GetProperties()
.Where(p => p.SetMethod != null)
@tluyben
tluyben / retry.cs
Created March 18, 2020 18:53
retry after error
const int RETRIES = 3;
void Retry(Action f)
{
for (int i = 0; i < RETRIES; i++)
{
try
{
f();
}
@tluyben
tluyben / explainquery.pl
Created January 15, 2020 12:09
explain all mysql queries in log
#!/usr/bin/perl
# enable query log for mysql
open(F, "tail -f ~/query.log|");
while(<F>){
chomp;
if (/\d+\s+Execute\s+(select.*)$/igsm) {
print "\n\nQuery: $1 : \n";
$qry = $1;
$qry =~ s/\`/\\\`/isgm;
@tluyben
tluyben / ListView.cs
Created December 12, 2019 15:10
ListView with Checkbox - not working
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using System.Collections.Generic;
using System.Linq;
using Avalonia.Data;
using Avalonia.Controls.Templates;
using Avalonia.Controls.Primitives;
using System;
namespace Playground