Skip to content

Instantly share code, notes, and snippets.

Avatar
🐫
Learning OCaml

Isaac Huang caasi

🐫
Learning OCaml
View GitHub Profile
View naive-type-inference.ts
type PrimitiveType = 'string' | 'number' | 'boolean' | 'bigint'
const isPrimitiveType = (v: string): v is PrimitiveType => {
return (
v === 'string' ||
v === 'number' ||
v === 'boolean' ||
v === 'bigint'
)
}
View leetcode.895.c
typedef struct Q {
int val;
int sp;
int time[20000];
struct Q* left;
struct Q* right;
} Q;
Q* qCreate(int val, int time) {
Q* q = malloc(sizeof(Q));
View watchdog.sh
#!/bin/sh
for ARG in $@; do
# extract service name and pid file path
NAME=`echo $ARG | cut -d":" -f1`
PID_PATH=`echo $ARG | cut -d":" -f2`
if [ "$NAME" = "$PID_PATH" ]; then
PID_PATH="$PID_PATH.pid"
fi
# check service status
View set-state-action.ts
type SetStateAction<S> = S | (prevState: S) => S;
export const isStateTransition = <S>(
x: SetStateAction<S>
): x is StateTransition<S> => {
return typeof x === "function";
};
export const tapStateAction = <S>(
s: SetStateAction<S>,
View cloud.cfg.patch
--- /etc/cloud/cloud.cfg 2019-09-12 07:42:33.236106056 +0000
+++ /etc/cloud/cloud.cfg.dpkg-new 2021-05-11 17:22:24.000000000 +0000
@@ -12,7 +12,7 @@
disable_root: true
# This will cause the set+update hostname module to not operate (if true)
-preserve_hostname: true
+preserve_hostname: false
# Example datasource config
View parser-combinators.ts
type Option<T> = T | undefined;
type Parser<T> = (input: string) => [Option<T>, string];
const alt
: <T>(pa: Parser<T>, pb: Parser<T>) => Parser<T>
= (pa, pb) => (input) => {
const result = pa(input);
if (result[0] !== undefined) return result;
return pb(input);
};
@caasi
caasi / calcTextareaHeight.js
Created Jan 25, 2021
Patched Element UI input element
View calcTextareaHeight.js
const HIDDEN_STYLE = `
height:0 !important;
visibility:hidden !important;
overflow:hidden !important;
position:absolute !important;
z-index:-1000 !important;
top:0 !important;
right:0 !important
`;
View 2020-11-06.ts
// 沒限制
function g(a: number[], p: (x: number) => boolean) {
let i;
for (i = 0; i < a.length; ++i) {
if (p(a[i])) return i; // early return
}
return i;
}
// 有限制
View small_step.rs
use crate::arith::syntax::*;
use Term::*;
pub fn eval1(term: Term) -> Term {
match term {
// E-IfTrue
If(box True, box t1, _) => t1,
// E-IfFalse
If(box False, _, box t2) => t2,
// E-If-Wrong
View small-step.ts
import {
Term,
tru,
fal,
cond,
succ,
pred,
isZero,
wrong,
} from '../syntax';