Skip to content

Instantly share code, notes, and snippets.

View crunchie84's full-sized avatar
🦑
Focusing

Mark van Straten crunchie84

🦑
Focusing
View GitHub Profile
/**
This middleware verifies that the AWS api gateway authorizer lambda has been configured and executed
this middleware is meant to make sure that the seam between IaC and the implementation do not go out of sync
and for whatever reason this lambda is exposed without authorization logic having happened before
in the lambda authorizer
*/
export function assertAuthorizerExecuted() {
return ({
before: (handler, next) => {
const event = handler.event; //unbox middy
@crunchie84
crunchie84 / script.sh
Created January 21, 2021 14:11
Git Surgery blogpost - rewriting histories
# part one, put on your scrubs
mkdir git-surgery
cd git-surgery
git clone git@github.com:crunchie84/blogpost-git-surgery-source.git source
cd source
# extract our application from the source repository
git subtree split -P Configuration/application-1 -b rewritten-history-application-1
# Prepare our new repository
@crunchie84
crunchie84 / .gitconfig.aliases
Created April 21, 2020 12:48
git alias for the win 💪
#
# Include this in your own .gitconfig by using the
# [include] directive with the path to this file
#
# [include]
# path = ~/.gitconfig.aliases
#
# If you don't have any existing includes, you can add this via the following command
#
# git config --global include.path ~/.gitconfig.aliases
@crunchie84
crunchie84 / debug.ts
Created April 4, 2018 19:08
RxJs5 lifecycle debug operator
import 'rxjs/add/observable/empty';
import 'rxjs/add/operator/do';
import 'rxjs/add/operator/concat';
import 'rxjs/add/operator/finally';
import { Observable } from "rxjs";
/**
*
* Lifecycle debugging for your stream, sub/unsubscribe,complete and values
*
@crunchie84
crunchie84 / fibonacci.js
Created January 2, 2018 11:56
Find fibonacci numbers using perfect square formula
/**
* The question may arise whether a positive integer x is a Fibonacci number. This is true if and only if one or both of 5x^{2}+4 or 5x^{2}-4 is a perfect square.
* https://en.wikipedia.org/wiki/Fibonacci_number#Recognizing_Fibonacci_numbers
*/
// the first 20 fibonacci numbers are found 0->6765
Array.from(generate(6765+1))
.map((i, idx) => ({number: i, isFibonacci: isFibonacciNumber(i)}))
.filter(kv => kv.isFibonacci)
.map((kv, index) => console.log(`found ${1+index}th fibonacci number: ${kv.number}`));

LCD Digits

Your task is to create an LCD string representation of an integer value using a 3x3 grid of space, underscore, and pipe characters for each digit. Each digit is shown below (using a dot instead of a space)

._.   ...   ._.   ._.   ...   ._.   ._.   ._.   ._.   ._.
|.|   ..|   ._|   ._|   |_|   |_.   |_.   ..|   |_|   |_|
|_| ..| |_. ._| ..| ._| |_| ..| |_| ..|
@crunchie84
crunchie84 / rx-bitcoin-price-ticker.js
Last active September 29, 2020 05:21
RxJs bitcoin stock ticker example
Rx.Observable.timer(0, 10 * 1000)
.switchMap(_ => fetch('https://blockchain.info/ticker?cors=true')
.then(res => res.json())
.then(parsed => parsed.EUR.buy)
)
.distinctUntilChanged()
.scan((acc, curr) => ({
delta: Math.round((acc.value - curr || 0) * 100) / 100,
value: curr
}), {})
@crunchie84
crunchie84 / rx-collection-compare.js
Last active February 23, 2018 23:03
Rxjs5 test compare
const assert = require('chai').assert;
/**
* parts of code taken from https://github.com/Reactive-Extensions/RxJS/blob/master/tests/helpers/reactiveassert.js#L32
*
* and modified to work with the rxjs5 testing shim which has no differentiation between values and predicates
*/
exports.assertEqual = function assertEqual(actual, expected) {
const comparer = require('./is-equal'); // copied and adapted from https://raw.githubusercontent.com/Reactive-Extensions/RxJS/master/src/core/internal/isequal.js
let isOk = true;
@crunchie84
crunchie84 / keybase.md
Created February 19, 2016 10:25
keybase.md

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@crunchie84
crunchie84 / init.cs
Created December 3, 2015 14:20
Serilog config for RX pushing to redis
public class MvcApplication : HttpApplication
{
private static void initializeLogging()
{
var loggerConfiguration = new LoggerConfiguration()
.Enrich.WithProperty("type", "application")
.Enrich.WithProperty("application", "my-app-name")
.Enrich.WithProperty("application_version", "1.2.3.4")
.Enrich.WithProperty("environment", "development")
.Enrich.With<Serilog.Extras.Web.Enrichers.HttpRequestIdEnricher>()