Skip to content

Instantly share code, notes, and snippets.

View marcj's full-sized avatar
🖌️
Data

Marc J. Schmidt marcj

🖌️
Data
View GitHub Profile
@marcj
marcj / docker-run.ts
Last active December 5, 2021 15:18
Dockerode Docker run with STDIN in Node.Js
import * as Dockerode from "dockerode";
import * as stream from "stream";
import {ContainerCreateOptions, HostConfig} from "dockerode";
export async function dockerRunWithStdIn(
docker: Dockerode,
stdin: NodeJS.ReadableStream | Buffer,
options: {name: string} & ContainerCreateOptions
): Promise<Buffer> {
return await new Promise<Buffer>(async (resolve, reject) => {
```
screen ~/Library/Containers/com.docker.docker/Data/vms/0/tty
```
@marcj
marcj / gist:ab66f9e2cef2e6d5925e12b8885ab549
Last active November 17, 2019 20:22
Clean macOS for VMs
sudo mount -uw /
rm -rf /System/Library/Extensions/AMDRadeon*
rm -rf /System/Library/Extensions/GeForce*
rm -rf /System/Library/Desktop\ Pictures/*
find /System/Library/Templates/Data/System/Library/Speech -name PCMWave -exec rm -rf {} \;
rm -rf /System/Library/Screen\ Savers/*.saver
rm -rf /private/var/db/dyld
@marcj
marcj / render-angular-puppeteer.ts
Last active October 2, 2020 14:41
Render Angular as PDF in Puppeteer
//this is more or less pseudocode, not tested, just to demonstrate how it could look like conceptually.
import {AppServerModule} from './src/main.server';
import {ngExpressEngine} from '@nguniversal/express-engine';
const puppeteer = require('puppeteer');
const {join} = require('path');
const {readFileSync} = require('fs');
async function main() {
const renderer = ngExpressEngine({
@marcj
marcj / app.ts
Created June 24, 2021 16:20
deepkit: simple database example
#!/usr/bin/env ts-node-script
import 'reflect-metadata';
import { Application, KernelModule } from '@deepkit/framework';
import { http } from '@deepkit/http';
import { entity, t } from '@deepkit/type';
import { Database } from '@deepkit/orm';
import { SQLiteDatabaseAdapter } from '@deepkit/sqlite';
@entity.name('user')
class User {
@marcj
marcj / crud.ts
Created July 15, 2021 18:53
Deepkit REST crud automatic controller
#!/usr/bin/env ts-node-script
import 'reflect-metadata';
import { Application } from '@deepkit/framework';
import { http } from '@deepkit/http';
import { ClassSchema, entity, getClassSchema, t } from '@deepkit/type';
import { Database } from '@deepkit/orm';
import { MongoDatabaseAdapter } from '@deepkit/mongo';
import { ClassType, getObjectKeysSize } from '@deepkit/core';
import { AppModule } from '@deepkit/app';
#!/usr/bin/env ts-node-script
import 'reflect-metadata';
import { Application, onServerMainBootstrap } from '@deepkit/framework';
import { injectable, InjectorContext } from '@deepkit/injector';
import { t } from '@deepkit/type';
import { AppModule, AppModuleConfig } from '@deepkit/app';
import { ClassType } from '@deepkit/core';
import { eventDispatcher } from '@deepkit/event';
type Options = { exchange: string, routingKey: string, queue: string };
@marcj
marcj / typetype.ts
Created September 3, 2021 00:33
stack based scripting language for runtime TypeScript reflection and validation
enum OP {
string = 0,
number = 1,
boolean = 2,
object = 3,
function = 4,
array = 5,
date = 6,
class = 7,
interface = 8,
@marcj
marcj / memoize.ts
Created January 22, 2022 01:00
memoize jit
import { BenchSuite } from '../bench';
const memoize = require('memoizee');
function memoizeWithJIT(fn: Function, options: { stackSize: number } = { stackSize: 10 }): Function {
const stacks: string[] = [];
const variables: string[] = [];
const argNames: string[] = [];
for (let a = 0; a < fn.length; a++) {
type Command =
'foo0'
| 'foo1'
| 'foo2'
| 'foo3'
| 'foo4'
| 'foo5'
| 'foo6'
| 'foo7'
| 'foo8'