Skip to content

Instantly share code, notes, and snippets.

View FauxFaux's full-sized avatar

Chris West FauxFaux

View GitHub Profile
export function mongo(name: string): KRoot[] {
return [
deploymentOf(name, {
name,
image: 'mongo:4-bionic',
ports: [{ containerPort: 27017 }],
readinessProbe: {
exec: { command: ['mongo', '--eval', '{ ping: 1 }'] },
},
}),
interface A { a: number }
interface B { b: number }
function ifIs<T>(l: Array<A | B>, isT: (o: any) => o is T, handle: (t: T) => void) {
for (const o of l) {
if (isT(o)) {
handle(o);
}
}
}
#![feature(process_exitcode_placeholder)]
#![feature(never_type)]
use std::process::ExitCode;
fn app() -> Result<!, ()> {
Err(())
}
fn main() -> ExitCode {
@FauxFaux
FauxFaux / 1-nested-tables.toml
Created October 10, 2019 06:33
toml table unnesting
[[products]]
name = "potato"
available = true
[products.shelf]
row = 7
column = 12
[[products]]
name = "tomato"
available = true
@FauxFaux
FauxFaux / readFileSync_vs_readFile.js
Last active March 19, 2022 04:12 — forked from Kirill89/readFileSync_vs_readFile.js
readFileSync vs readFile benchmark
const fs = require('fs');
const fsp = fs.promises;
const util = require('util');
const readFile = util.promisify(fs.readFile);
fs.writeFileSync('a', 'a');
const attempts = 10000;
@FauxFaux
FauxFaux / pom.xml
Created March 20, 2019 09:09
Maven can't version range ???
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>io.github.egg</groupId>
<artifactId>egg</artifactId>
<version>1.0-SNAPSHOT</version>
<name>egg</name>
<dependencies>
@FauxFaux
FauxFaux / 1.green-Yellow.java
Created January 24, 2019 09:31
Java source to .class mapping
// Here's a .java file, named 'Yellow.java'
// Inside a package (and directory) named 'green'
package green;
// Here's a class named 'Blue'
class Blue {
// Here's a method named 'foo' inside 'Blue'
void foo() {
import java.io.FileInputStream;
import java.io.IOException;
public class A {
static long checkHeader(String path) throws IOException {
// can't use try() as there's no way to catch only the initialisation exception?
final FileInputStream fis;
try {
fis = new FileInputStream(path);
} catch (IOException e) {
@FauxFaux
FauxFaux / bad-locking.ts
Created December 18, 2018 10:58
Type system can't save you from missing awaits
/*
% npm install typescript
.. warnings blah blah..
+ [email protected]
updated 1 package and audited 2 packages in 0.538s
found 0 vulnerabilities
% node_modules/.bin/tsc --lib es2018,dom --target es2018 --strict --noImplicitReturns --noImplicitAny --out hello.js hello.ts
@FauxFaux
FauxFaux / dump-firebird.py
Created November 17, 2018 11:35
Dump a firebird database to json (and never look back)
import fdb
import json
import sys
import decimal
import datetime
def js(val):
if type(val) == int:
return val
if type(val) == str: