Skip to content

Instantly share code, notes, and snippets.

@tluyben
tluyben / Forth1.cs
Last active Feb 1, 2021
A minimal Forth implementation in C#
View Forth1.cs
/*
* Minimal .NET Forth implementation. Just an experiment. Do not use for anything serious.
* by Tycho Luyben (https://github.com/tluyben)
*
* The only 'primitive' (built-in) is an foreign function interface word which allows you to define
* whatever is needed, for example:
*
* hello System.String System.Console.WriteLine ffi
*
* will print hello.
@tluyben
tluyben / places.py
Created Jan 6, 2021
Google places api search in Python
View places.py
import googlemaps
gmaps = googlemaps.Client(key='YOUR_KEY')
test = gmaps.find_place('nice company', 'textquery')
if 'candidates' in test and len(test['candidates'])>0:
first = test['candidates'][0]['place_id']
details = gmaps.place(first)
@tluyben
tluyben / count.pl
Created Dec 31, 2020
counting new files per minute over 3k in a directory
View count.pl
#!/usr/bin/perl
$p = -1;
$intr = 2;
@minute = ();
while(1) {
$c = `find ./scraped -size +3k -ls|wc -l`;
chomp($c);
if ($p>=0) {
$t = $c - $p;
@tluyben
tluyben / gist:f8b19965eaab6d236f9b
Created May 1, 2014
Atari 2600 ET sourcecode 1982
View gist:f8b19965eaab6d236f9b
LIST OFF
; *** E . T. T H E E X T R A - T E R R E S T R I A L ***
; Copyright 1982 Atari, Inc.
; Designer: Howard Scott Warshaw
; Artist: Jerome Domurat
; Analyzed, labeled and commented
; by Dennis Debro
; Last Update: July 18, 2006
;
@tluyben
tluyben / assert.js
Created Nov 27, 2020
partial deep assert
View assert.js
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 Oct 30, 2020
Run openwhisk playground on a public IP address with Nginx
View gist:b33548e1a3b8ed120312369fa67fb522
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 Sep 13, 2020
OFX hack for using the historical forex rates to fix csv files with a conversion rate
View ofxint.pl
#!/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 Sep 13, 2020
MT940 to csv convertor - specifically written to quickly analyse a large mt940 file, but very easy to change / append to
View mt940.pl
#!/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 Aug 21, 2020
Verhoeff's Dihedral Group D5 Check raw port from JS
View verhoef.cs
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()
{
View efgetcontext.cs
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 });
}