Skip to content

Instantly share code, notes, and snippets.

View Oaphi's full-sized avatar
💭
☕ and 👩‍💻

Oleg Valter Oaphi

💭
☕ and 👩‍💻
  • Rocket
  • Saint Petersburg
View GitHub Profile
@Oaphi
Oaphi / WebAppSelfHelp.md
Last active November 22, 2022 18:48
Web App troubleshooting questionnaire

Preliminary

  1. Does the Web App have a saved deployment? ("Publish" -> "Deploy as Web App")
  2. Are you accessing the /dev endpoint (https://script.google.com/.../yourIdHere/dev)?
  3. If you are accessing the /exec endpoint (https://script.google.com/.../yourIdHere/exec), did you redeploy?
  4. If you redeployed, did you increment the script version?
  5. If you have a client-side problem, what does the console say (pres F12 to open developer tools)?
  6. If you have a server-side problem, what do executions say (https://script.google.com/home/projects/yourIdHere/executions

Web App Access

@Oaphi
Oaphi / SOmods.tex
Last active November 12, 2021 21:09 — forked from normalhuman/SOmods.tex
[2021 update] SO moderator timeline, from a template by Najib Idrissi. See http://meta.stackoverflow.com/a/311059
\documentclass[tikz]{standalone} % last update March 2016
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\title{Moderator chart}
\begin{document}
\definecolor{rows}{rgb}{0.95,0.95,0.95}
\definecolor{myblue}{rgb}{0.1,0.3,0.9}
\definecolor{mypurple}{rgb}{0.5,0.3,0.7}
\begin{tikzpicture}[scale=0.5]
% 1 horizontal unit = 1 month, 0 = january 2010
@Oaphi
Oaphi / interleave.ts
Created November 2, 2021 01:08
Interleave an array with a repeating element
const interleave = <T, U>(arr: T[], inserted: U) => {
let insertions = 0;
return arr.flatMap((val, idx) => {
const isEven = (idx + insertions) % 2;
if(isEven) insertions += 1;
return isEven ? [inserted, val] : val;
});
}
@Oaphi
Oaphi / gulp.sh
Last active October 31, 2021 05:45
Gulp workflow
# if gulp CLI is not installed
npm i -g gulp-cli
# gulp package
npm i -D gulp @types/gulp
# TypeScript prerequisites
# ts-node is required for gulpfile.ts
npm i -D typescript ts-node
@Oaphi
Oaphi / html-tag-gulpfile.ts
Created October 20, 2021 09:15
Gulpfile for creating HTML tags from single-file scripts
import GulpClient = require("gulp");
import del from "del";
import { dest, series, src, watch } from "gulp";
import { appendText, prependText } from "gulp-append-prepend";
import rename from "gulp-rename";
import ts from "gulp-typescript";
const DIST = "dist";
const SOURCE = "src/*.ts";
@Oaphi
Oaphi / deep-omit.ts
Created October 17, 2021 23:11
Utility types and helper for deeply omitting a field from an object
type DeepKeyof<T, A = never> = { [P in keyof T]: T[P] extends object ? P extends A ? P : DeepKeyof<T[P], A | keyof T> | P : P }[keyof T];
type DeepOmit<T, U extends DeepKeyof<T>> = {
[P in keyof T as P extends U ? never : P]: T[P] extends object ?
keyof DeepOmit<T[P], Extract<U, DeepKeyof<T[P]>>> extends never ?
{} :
DeepOmit<T[P], Extract<U, DeepKeyof<T[P]>>> :
T[P]
};
@Oaphi
Oaphi / union-print.ts
Created October 2, 2021 04:12
Print string union
type PrintStringUnion<T extends string, S extends string = "|", A extends string = ""> = {
[P in T]: [T] extends [P] ? `${A}${P}` : PrintStringUnion<Exclude<T, P>, S, `${A}${P}${S}`>
}[T];
type TestUnion = "A" | "B" | "C" | "D" | "E";
type U = PrintStringUnion<TestUnion>;
const test1: U = "A|B|C|D|E"; // OK
@Oaphi
Oaphi / lens.ts
Created October 2, 2021 01:02
Deep lens into an object
type NestedObj = {
[x: string]: string | number | boolean | null | undefined | NestedObj;
};
const lens = (obj: NestedObj, path: string) => {
const parts = path.split(".");
const [lastPart] = parts.slice(-1);
let current: NestedObj = obj;
for (const part of parts) {
@Oaphi
Oaphi / bash-helpers.sh
Last active August 31, 2021 00:46
Various bash helpers
# extracts NPM environment variable names
npm_val() {
local value=$(ENV | grep -e "npm_package_$1" | cut -d "=" -f 2)
echo $value
}
# splits a string on dashes and rejoins with first letter uppercased
pretty() {
IFS=\-
local output
@Oaphi
Oaphi / TupleTypes.ts
Last active July 16, 2021 18:19
Useful tuple utility types
type Indices<A> = Exclude<keyof A, keyof any[]>;
type valueAtIndexToNever<T extends any[], I extends number> = {
[ P in keyof T ] : P extends Indices<T> ?
P extends `\${I}` ? never : T[P] :
T[P]
}
type test1 = valueAtIndexToNever<[1,2,3],1>; //[1, never, 3];