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 / 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));
@aztack
aztack / useCombinedRefs.js
Created January 12, 2022 08:43
React Missing Hooks
function useCombinedRefs(...refs) {
const targetRef = React.useRef()
React.useEffect(() => {
refs.forEach(ref => {
if (!ref) return
if (typeof ref === 'function') {
ref(targetRef.current)
} else {
@aztack
aztack / Effects.js
Created January 4, 2022 06:42 — forked from unktomi/Effects.js
/**
* Algebraic Effects and Handlers as in <a href='http://www.eff-lang.org/'>Eff</a>
*/
'use strict'
//
// Note:
// new Continuation() - returns the current function's continuation.
//
@aztack
aztack / jsx-helper.tsx
Created December 14, 2021 10:15
jsx control flow helper
import React from 'react';
type Typed = {type: Function};
const ofType = (type: Function) => (it: Typed) => it?.type === type;
const isDefined = (it: any) => it != null;
export function Truthy(props: React.PropsWithChildren<{}>) {
return <>{props.children}</>;
}
export function Falsy(props: React.PropsWithChildren<{}>) {
title slug
Views
views

Views and Dialogs

Theia does not enforce you to use any specific UI library. For most of Theia's current UI elements either plain DOM modifications or React is being used. In this article we'll show you how to implement UI elements with both of these techniques.

Creating a plain HTML Dialog

@aztack
aztack / wrap_child_process_exec.js
Created November 18, 2021 10:09
wrap child_process.exec
/**
/**
* Essentially wraps `child_process.exec` into a promise.
*
* @param script Command line to run as a shell command.
*/
function run(script) {
return new Promise((resolve, reject) => {
const env = Object.assign({}, process.env);
const scriptProcess = cp.exec(script, {
@aztack
aztack / delegate.ts
Created November 1, 2021 06:57
delegate.ts
class EventEmitter {
on(event: string, callback: () => void) {
console.log(`EventEmitter#on`, this.constructor.name);
}
emit(event: string) {
console.log(`EventEmitter#emit`, this.constructor.name);
}
}
class Win {
x:number = 41;
/**
* DERIVING THE Y COMBINATOR IN 7 EASY STEPS
*
* Ionut G. Stan | ionut.g.stan@gmail.com | http://igstan.ro | http://twitter.com/igstan
*
*
* The Y combinator is a method of implementing recursion in a programming
* language that does not support it natively (actually, it's used more for
* exercising programming brains). The requirement is the language to support
* anonymous functions.
@aztack
aztack / validate_ipv6.rb
Created June 7, 2012 08:29 — forked from cpetschnig/validate_ipv6.rb
Regular Expression Validation for IPv6 Addresses in Ruby
# Regular Expression Validation for IPv6 addresses in Ruby
#
# Inspired by (if not to say copied from): http://forums.dartware.com/viewtopic.php?t=452
# Thanks, Dartware!
IPV6_REGEX = /^\s*((([0-9A-Fa-f]{1,4}:){7}([0-9A-Fa-f]{1,4}|:))|(([0-9A-Fa-f]{1,4}:){6}(:[0-9A-Fa-f]{1,4}|((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){5}(((:[0-9A-Fa-f]{1,4}){1,2})|:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3})|:))|(([0-9A-Fa-f]{1,4}:){4}(((:[0-9A-Fa-f]{1,4}){1,3})|((:[0-9A-Fa-f]{1,4})?:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){3}(((:[0-9A-Fa-f]{1,4}){1,4})|((:[0-9A-Fa-f]{1,4}){0,2}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){2}(((:[0-9A-Fa-f]{1,4}){1,5})|((:[0-9A-Fa-f]{1,4}){0,3}:((25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}))|:))|(([0-9A-Fa-f]{1,4}:){1}(((:[0-9A-Fa-f]{1,4}){1,6})|((:[0-9A-Fa-f
@aztack
aztack / checker_functions.ts
Created July 26, 2021 10:50
functions of TypeScript/src/compiler/checker.ts
// generate
function *generateJsxAttributes(node: JsxAttributes): ElaborationIterator {
function *generateJsxChildren(node: JsxElement, getInvalidTextDiagnostic: () => DiagnosticMessage): ElaborationIterator {
function *generateLimitedTupleElements(node: ArrayLiteralExpression, target: Type): ElaborationIterator {
function *generateObjectLiteralElements(node: ObjectLiteralExpression): ElaborationIterator {
// accepts
function acceptsVoid(t: Type): boolean {
function acceptsVoidUndefinedUnknownOrAny(t: Type): boolean {