Skip to content

Instantly share code, notes, and snippets.

@yllan
yllan / merge.cpp
Created May 16, 2022 14:22
merge two lists
/**
* Definition for singly-linked list.
* struct ListNode {
* int val;
* ListNode *next;
* ListNode() : val(0), next(nullptr) {}
* ListNode(int x) : val(x), next(nullptr) {}
* ListNode(int x, ListNode *next) : val(x), next(next) {}
* };
*/
@yllan
yllan / im.txt
Created December 24, 2021 02:44
Inside Macintosh URL
https://developer.apple.com/library/archive/documentation/mac/pdf/Text.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/MoreMacintoshToolbox.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/MacintoshToolboxEssentials.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/ResEditReference.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/ImagingWithQuickDraw.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/MacOS_RT_Architectures.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/Processes/Vertical_Retrace_Mgr.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/Sound/Sound_Input_Manager.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/Networking/DDP.pdf
https://developer.apple.com/library/archive/documentation/mac/pdf/Operating_System_Utilities/PRAM_Utilities.pdf
@yllan
yllan / machine.js
Last active November 5, 2021 06:28
Generated by XState Viz: https://xstate.js.org/viz
const IDX = {
VHS: { P2: 6, P3: 7, P4: 8, P5: 9, P6: 10 }
}
const nudgePoints = (elementIndexes) => assign((ctx, evt) => {
const [x, y] = [evt.clientX, evt.clientY]
const [sx, sy] = ctx.lastClientPoint
const [dx, dy] = [x - sx, y - sy]
const paths = elementIndexes.map(idx => [0, ctx.groupIndex, idx])
ctx.editorMethods.nudgeElementsAtPath(dx, dy, paths)
return { ...ctx, lastClientPoint: [x, y] }
@yllan
yllan / machine.js
Created October 12, 2021 09:54
Generated by XState Viz: https://xstate.js.org/viz
const pinchMachine = Machine({
id: 'pinch',
initial: 'idle',
context: {
onPinch: () => {},
onPan: ([dx, dy]) => {},
finishPinch: () => {},
onSingleTouch: {
touchStart: (currentPoint) => {},
touchMove: (currentPoint) => {},
@yllan
yllan / std-variant.md
Last active February 17, 2021 04:00
std::variant

std::variant 是 C++ 的 sum type

在 C++17 後要 sum type 可以這樣用:

#include<variant>

// data Solution = Surface Vector3 Double |
//                 Line Vector3 Vector3 |
// Copyright (c) the JPEG XL Project
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@yllan
yllan / machine.js
Last active September 11, 2020 02:36
Generated by XState Viz: https://xstate.js.org/viz
const m = Machine({
id: 'websocket',
context: {
devices: []
},
initial: 'offline',
states: {
offline: {
on: {
CONNECT: 'trying'
@yllan
yllan / main.swift
Created May 14, 2020 14:43
ShitWeb
//
// main.swift
// ShitWeb
//
// Created by Yung-Luen Lan on 2020/5/14.
// Copyright © 2020 Yung-Luen Lan. All rights reserved.
//
import Foundation
import Network
@yllan
yllan / polygon.png
Last active December 24, 2019 02:47
遞迴思考 Thinking in recursion
polygon.png
@yllan
yllan / explain.md
Last active December 23, 2019 10:22
My Hack for declarative resumable parsing

前提: Syntax很簡單,不用look ahead,而且都會知道要讀多少byte(沒有那種「讀到0x00為止」)

我的作法看起來長這樣:

const msgParser = expect([10, 10, 20], (datetime, messageType, messageID) => {
    switch (messageType) {
        case "HI":
            expect([10, 10], (senderID, senderName) => {
 // connect