Skip to content

Instantly share code, notes, and snippets.

View aztack's full-sized avatar
🎯
Focusing

Wang Weihua aztack

🎯
Focusing
View GitHub Profile
@aztack
aztack / recordCanvasStream.ts
Created November 18, 2022 06:38
recordCanvasStream
**
* Record canvas stream into a webm file
* @param canvas HTMLCanvasElement
* @param options {duration: number, fps: number}
* @returns Promise<Blob> | ((discard:boolean) => Promise<Blob|null>)
* @example
* // Stop after 5 seconds
* const blob = await recordCanvasStream(canvas, { duration: 5, fps: 30 });
* downloadBlob(blob, 'recording.webm');
*
@aztack
aztack / init.gradle
Created April 2, 2020 09:52
init.gradle
// ~/.gradle/init.gradle
allprojects {
def google_uri = new URI('https://maven.aliyun.com/repository/google')
def central_uri = new URI('https://maven.aliyun.com/repository/central')
def jcenter_uri = new URI('https://maven.aliyun.com/repository/jcenter')
repositories {
all {
ArtifactRepository repo ->
if (repo instanceof MavenArtifactRepository) {
@aztack
aztack / cryptography-file-formats.md
Created October 12, 2022 14:37 — forked from tuansoibk/cryptography-file-formats.md
Cryptography material conversion and verification commands
  1. Introduction
  2. Standards
  3. Common combinations
  4. Conversion
  5. Verification/Inspection
  6. Tips for recognising

Introduction

It happens that there are many standards for storing cryptography materials (key, certificate, ...) and it isn't always obvious to know which standard is used by just looking at file name extension or file content. There are bunch of questions on stackoverflow asking about how to convert from PEM to PKCS#8 or PKCS#12, while many tried to answer the questions, those answers may not help because the correct answer depends on the content inside the PEM file. That is, a PEM file can contain many different things, such as an X509 certificate, a PKCS#1 or PKCS#8 private key. The worst-case scenario is that someone just store a non-PEM content in "something.pem" file.

@aztack
aztack / gitgraft.sh
Created August 30, 2022 02:28 — forked from Victrid/gitgraft.sh
Find which commit your no-git friend is working on and generate patches for attaching their works onto git tree.
#!/bin/bash
hash git 2>/dev/null || { echo >&2 "Required command 'git' is not installed. ( hmm... why are you using this? ) Aborting."; exit 1; }
hash realpath 2>/dev/null || { echo >&2 "Required command 'realpath' is not installed. Aborting."; exit 1; }
hash pwd 2>/dev/null || { echo >&2 "Required command 'pwd' is not installed. Aborting."; exit 1; }
hash cd 2>/dev/null || { echo >&2 "Required command 'cd' is not installed. Aborting."; exit 1; }
hash echo 2>/dev/null || { echo >&2 "Required command 'echo' is not installed. Aborting."; exit 1; }
hash mv 2>/dev/null || { echo >&2 "Required command 'mv' is not installed. Aborting."; exit 1; }
hash diff 2>/dev/null || { echo >&2 "Required command 'diff' is not installed. Aborting."; exit 1; }
hash diffstat 2>/dev/null || { echo >&2 "Required command 'diffstat' is not installed. Aborting."; exit 1; }
@aztack
aztack / export-comp-from-after-effect.jsx
Last active August 4, 2022 13:49
export-comp-from-after-effect
/*
Copyright (c) 2020 adroitwhiz
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
@aztack
aztack / index.ts
Last active August 1, 2022 02:05
Express.js Download Streamed Zip
import express from 'express';
import archiver from 'archiver';
express().use('/download-assets', async (req, res) => {
res.set('Content-Type', 'application/octet-stream');
res.set('Transfer-Encoding', 'chunked');
res.attachment(`assets.zip`);
console.log(`Archiving project assets...`);
const zipfile = archiver('zip');
@aztack
aztack / index.ts
Created July 16, 2022 11:55 — forked from Bnaya/index.ts
Typescript Types indirect re-export with isolatedModules: true
// Cannot re-export a type when the '--isolatedModules' flag is provided.ts(1205)
export { IMyInterface } from "./types"
// this works!
import { IMyInterface as IMyInterfaceForExport } from "./types"
export type IMyInterface = IMyInterfaceForExport;
// And Also:
export type IMyInterface2 = import("./types").IMyInterface;
@aztack
aztack / Working GDB on macOS 11.md
Created May 27, 2022 14:01 — forked from mike-myers-tob/Working GDB on macOS 11.md
Steps to get GDB actually working in April 2021 on macOS

Debug with GDB on macOS 11

The big reason to do this is that LLDB has no ability to "follow-fork-mode child", in other words, a multi-process target that doesn't have a single-process mode (or, a bug that only manifests when in multi-process mode) is going to be difficult or impossible to debug, especially if you have to run the target over and over in order to make the bug manifest. If you have a repeatable bug, no big deal, break on the fork from the parent process and attach to the child in a second lldb instance. Otherwise, read on.

Install GDB

Don't make the mistake of thinking you can just brew install gdb. Currently this is version 10.2 and it's mostly broken, with at least two annoying bugs as of April 29th 2021, but the big one is https://sourceware.org/bugzilla/show_bug.cgi?id=24069

$ xcode-select install  # install the XCode command-line tools
@aztack
aztack / stack-vm.js
Created March 28, 2022 07:55 — forked from DmitrySoshnikov/stack-vm.js
Educational Stack-based Virtual Machine
/**
* Educational Stack-based VM.
*
* See also:
* - More complex example with recursion: https://gist.github.com/DmitrySoshnikov/afda459222e96e6002ac
* - Register-based VM example: https://gist.github.com/DmitrySoshnikov/6407781
*
* by Dmitry Soshnikov <dmitry.soshnikov@gmail.com>
* http://dmitrysoshnikov.com
* MIT Stye License (C) 2015
@aztack
aztack / programming-with-nothing.js
Created March 15, 2022 02:46
programming-with-nothing
const ZERO = p=>x=>x;
const ONE = p=>x=>p(x);
const TWO = p=>x=>p(p(x));
const THREE = p=>x=>p(p(p(x)));
const FIVE = p=>x=>p(p(p(p(p(x)))));
const INCREMENT = n=>(p=>x=>p(n(p)(x)));
const ADD = n=>m=>(n(INCREMENT)(m));
const MULTIPLY = n=>m=>(n(ADD(m))(ZERO));
const POWER = n=>m=>(m(MULTIPLY(n))(ONE));