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 / 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 / index.html
Created November 10, 2021 11:35
Intercept file protocol in electron
<html>
<bod>
<iframe src="https://domain.com/page.html />
</body>
</html>
@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 / 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 {
@aztack
aztack / checker_mod.ts
Created July 26, 2021 03:09 — forked from hackape/checker_mod.ts
Answer to Stack Overflow Question: "How can I see how TypeScript computes types?"
// https://github.com/microsoft/TypeScript/blob/ba5e86f1406f39e89d56d4b32fd6ff8de09a0bf3/src/compiler/checker.ts
// 1. add this line to ln:3
export const _conditionalTypes: any = {}
// 2. then replace ln:12303 to ln:12360
function trackConditionalType() {
// one time stuff
@aztack
aztack / igloo-ui-react-component.tsx
Created July 16, 2021 07:04
igloo-ui-react-component.tsx
import React from 'react';
import ReactDOM from 'react-dom';
import { AzButton, AzTabs, AzSection, AzPanel } from 'aztec-ui-react'
function App() {
const marginRight = {marginRight: '1em'};
return <>
<AzSection caption="Buttons & Tabs">
<AzButton className="small right" type="plain" size="extra-small" slot="header" onClick={() => alert(1)}>Collapse</AzButton>
<AzTabs items="[{caption:'Disabled Buttons'}, {caption: 'Normal', icon: 'check'}, {caption: 'Empty Tab', icon: 'bars'}, {icon: 'download', closable: true}]" active-index="1">
COOKIE="Cookie: thinkjs=______;" # 使用浏览器登录之后拿 cookie
VIP="________" # host ip
RESOLVE="--resolve ppt.baomitu.com:443:$VIP"
list_json=$(curl $RESOLVE -s -H "$COOKIE" "https://ppt.baomitu.com/api/slide/list?page=1&epage=500&tag_id=-1")
raw_js=`echo "console.log((" $list_json ").data.data.map(item => item.slide_title.trim().replace(/\s{2,}/g, ' ') + '#' + item.slide_id).join('\n'))"`
data=`node -e "$raw_js"`
dir_name="./ppt-baomitu"
rm -rf $dir_name
mkdir $dir_name