Skip to content

Instantly share code, notes, and snippets.

/**
* Create a configuration getter that reads from command line arguments, environment variables,
* and a .env file in the priority.
* @param args Result of deno std's [parseArgs](https://deno.land/std/cli/parse_args.ts)
* @param getEnv Function to get environment variables
* @param dotEnv Record from a .env file
* @returns A function that returns the value for a configuration parameter
*/
export function configSource<T>(
{ args, getEnv, dotEnv }: {
/**
* Multiplexes multiple async iterators into a single async iterable iterator.
* @param args An array of async iterators to be multiplexed.
* @returns An async iterable iterator that yields values immediately from iterators.
*/
export async function* multiplex<T, N>(
args: readonly AsyncIterator<T, void, N>[],
): AsyncIterableIterator<T> {
const promises = new Map<AsyncIterator<T, unknown, N>, ReturnType<typeof step<T, N>>>();
args.forEach((iterator) => promises.set(iterator, step(iterator)));
export function atomFamilyStrict<
Key,
Args extends unknown[],
AtomType extends {
onMount?: (set: (...args: Args) => void) => void | (() => void);
},
>(initializeAtom: (param: Key) => AtomType) {
const atoms = new Map<string, AtomType>();
const family = (key: Key) => {
@jeiea
jeiea / build.gradle.kts
Created August 31, 2023 04:24
React native kotlin DSL build script example
import com.facebook.react.utils.KotlinStdlibCompatUtils.toBooleanStrictOrNullCompat
import java.util.Properties
plugins {
id("com.android.application")
id("com.facebook.react")
}
apply(from = "../../node_modules/@react-native-community/cli-platform-android/native_modules.gradle")
val applyNativeModulesAppBuildGradle: groovy.lang.Closure<Any> by extra
@jeiea
jeiea / aws_mfa_shell.ts
Last active September 1, 2023 05:24
Why should I write this
import { parse } from "https://deno.land/x/ini@v2.1.0/mod.ts";
import { parseFlags } from "https://deno.land/x/cliffy@v1.0.0-rc.3/flags/mod.ts";
type Config = { profile?: string; serial?: string };
let fileConfig: undefined | Config;
if (import.meta.main) {
await main();
}
extension ObjectExt<T> on T {
R let<R>(R Function(T) x) => x(this);
}
class ProgramCardDataFamily {
const ProgramCardDataFamily();
ProgramCardDataProvider call( int data) {
return ProgramCardDataProvider( data);
}
import { expandGlob } from "https://deno.land/std@0.165.0/fs/expand_glob.ts";
main().catch(console.error);
async function main() {
const osEscaper = Deno.build.os === "windows" ? "`" : "\\";
const readPromises: Promise<string>[] = [];
for await (const path of Deno.args) {
const escaped = path.replace(/(\[|\])/g, (_, arg) => `${osEscaper}${arg}`);
for await (const entry of expandGlob(escaped, { extended: false })) {
@jeiea
jeiea / open_in_notion.user.js
Last active November 28, 2022 02:58
Open web notion link in desktop app
// ==UserScript==
// @name Open notion in app
// @namespace https://gist.github.com/jeiea/514c8c0862710cc04aa9cbb5ac465c84
// @downloadURL https://gist.github.com/jeiea/514c8c0862710cc04aa9cbb5ac465c84/raw/open_in_notion.user.js
// @version 0.3
// @description Useful with slack integration.
// @author jeiea
// @match https://www.notion.so/*
// @icon https://www.google.com/s2/favicons?sz=64&domain=notion.so
// @grant window.close
@jeiea
jeiea / a.log
Created February 8, 2022 10:36
!! PLEASE REVIEW THIS LOG FOR SENSITIVE INFORMATION BEFORE SHARING !!
Dart Code extension: 3.34.0
Flutter extension: 3.34.0 (activated)
App: Visual Studio Code
Version: 1.64.0
Platform: win
Workspace type: Flutter
const makePageNavigator = ref => {
let currentPage;
let ratio;
let ignoreIntersection = false;
const resetAnchor = entries => {
const container = ref.current;
if (!container?.clientHeight || entries.length === 0) {
return;