Skip to content

Instantly share code, notes, and snippets.

Avatar
🇳🇱

Herman hermanbanken

🇳🇱
View GitHub Profile
@hermanbanken
hermanbanken / BottomUpScrollable.tsx
Last active Jun 14, 2022
Screen that is glued to the bottom of the screen if there is enough space, or a regular scroll view if it does not fit
View BottomUpScrollable.tsx
import React, {useCallback, useRef, useState} from 'react';
import {
Pressable,
RefreshControl,
SafeAreaView,
ScrollView,
StyleSheet,
Text,
View,
} from 'react-native';
@hermanbanken
hermanbanken / .gitignore
Last active Jun 7, 2022
Music concert generation of overlay slides
View .gitignore
slides.html
slides.pdf
View index.ts
import * as functions from "firebase-functions" // The Cloud Functions for Firebase SDK to create Cloud Functions and set up triggers.
import { Firestore } from "@google-cloud/firestore"; // Cloud Firestore: Node.js Client
import * as admin from "firebase-admin"; // The Firebase Admin SDK to access Firestore.
admin.initializeApp();
const db = admin.firestore();
const adminUSA = new Firestore({projectId:"firestoreusa"}); // Firebase USA access account
const collections = ["bridges", "users", "tokens"];
View Dockerfile
FROM node:alpine
COPY server.js /srv/www/
COPY server.js.map /srv/www/
ENV API_URL=http://example.com NODE_OPTIONS=--enable-source-maps
ENTRYPOINT [ "node", "/srv/www/server.js" ]
View bootstramp.yaml
# yaml-language-server: $schema=https://github.com/jcchavezs/envoy-config-schema/releases/download/v1.21.0/v3_Bootstrap.json
node:
id: "something"
cluster: "some-cluster"
metadata:
any: {}
key: can
be: used-here
locality:
zone: "europe-west4-a"
View README.md

Sadly we can't have nice things in TypeScript (see https://www.ackee.agency/blog/typescript). Specifically middleware that:

  1. Notifies when the chain is broken
pipe(
   () => 21,
   (n: number) => n * 2,
 (n: string) => n.repeat(5), // Error: number is not assignable to string
@hermanbanken
hermanbanken / auth.go
Created Jan 18, 2022
Triple JWT audience/issuer server
View auth.go
package main
import (
"context"
"fmt"
"log"
"net/http"
"os"
"github.com/golang-jwt/jwt/v4"
@hermanbanken
hermanbanken / NativeHttpServer.java
Created Dec 17, 2021
java server serving 404 without dependencies
View NativeHttpServer.java
package main;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Map;
@hermanbanken
hermanbanken / README.md
Last active Dec 12, 2021
Cloud Function for GKE upgrade notifications
View README.md

We want to receive notifications when a Kubernetes cluster upgrades. For this we can configure PubSub subscriptions:

const exec = require("child_process").execSync;

const mapping = {
  "my-dev-project": [{ name: "clusterA", region: "europe-west4" }, { name: "clusterB", region: "us-east1" }],
  "my-prod-project": [{ name: "clusterC", region: "europe-west4" }, { name: "clusterD", region: "us-east1" }],
};
@hermanbanken
hermanbanken / gitlab_list_variables.js
Created Sep 9, 2021
GitLab list pipeline variables
View gitlab_list_variables.js
#!/bin/env node
const PRIVATE_TOKEN = "redacted";
const headers = { "PRIVATE-TOKEN": PRIVATE_TOKEN };
const root = "https://gitlab.com/api/v4";
const project = 24418136; // "hue-contract-tests";
const { default: fetch } = require("node-fetch");
fetch(`${root}/projects/${project}/pipelines`, { headers }).then((res) => res.json())
.then(async (pipelines) => {