Sitelet https://gist.github.com/wintercn
Skip to content

Instantly share code, notes, and snippets.

@wintercn
wintercn / README.md
Last active October 5, 2026 09:29
Void 0.24.0 Vue Pages: browser Back loses scroll position after ordinary anchor document navigation

Vue Pages: browser Back loses the scroll position after document navigation

This standalone app has two server-rendered Vue pages. Page A contains 80 numbered rows, each with an ordinary link to Page B. The numbered rows make the scroll position visible.

Run

Use Node.js 24.21.0 or newer.

Download the gist as a ZIP and extract it into a new folder. Gist stores the files in a flat directory. Put the two Vue files in src/pages/, then install and start:

class BinaryHashTree {
constructor() {
this.root = null;
this.depth = 0; // 记录树的当前深度
}
// 将数字转换为二进制字符串
toBinaryString(num) {
return (num >>> 0).toString(2);
}
const fib = n => n === 0 ? [0, 1] :
n % 2 ? (([a, b]) => [b, a + b])(fib(n - 1)) :
(([a, b]) => [a * b + a * (b - a), a * a + b * b])(fib(n / 2));
Array(10).fill(0).map((v, n) => fib(n)[0])
@wintercn
wintercn / primes.js
Last active August 25, 2023 09:30
JavaScript Primes
function* primes(){
let primes = [];
let i = 1;
outer:while(true) {
++ i;
for(let p of primes)
if(p % i === 0)
continue outer;
primes.push(i);
yield i;
<body>
<style>
.number {
color:purple;
}
.keyword {
color:blue;
}
.string {
color:red;
@wintercn
wintercn / categoryTree.js
Last active May 3, 2020 17:00
JS Factory demo
const categories = [
{id:'animals', parent:null},
{id:'mammals', parent:'animals'},
{id:'cats', parent:'mammals'},
{id:'dogs', parent:'mammals'},
{id:'chihuahua', parent:'dogs'},
{id:'labrador', parent:'dogs'},
{id:'persian', parent:'cats'},
{id:'siamese', parent:'cats'},
]
@wintercn
wintercn / reverseKGroupFromEnd.js
Created December 15, 2019 16:35
reverseKGroupFromEnd
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @param {number} k
<body style="margin:0;">
<div id="app" style="position:relative;width:100%;height:100%;">
</div>
<script src="https://cdn.jsdelivr.net/npm/vue"></script>
<script>
Vue.component('local-storage', {
props: ['value', 'key'],
template: `<div></div>`,
mounted(){
if(!localStorage[this.$props.key])
Vue.component('local-storage', {
props: ['value', 'key'],
template: `<div></div>`,
mounted(){
if(!localStorage[this.$props.key])
return;
var str = JSON.stringify(this.$props.value);
if(str != localStorage[this.$props.key])
this.$emit('input', JSON.parse(localStorage[this.$props.key]))
},
@wintercn
wintercn / tang.html
Created April 21, 2019 13:46
tang.js
<meta charset="utf-8">
<body style="text-align:center">
<canvas width="1000" height="1000" style="background:black;margin:auto;">
</canvas>
<script src="tang.js">
</script>
</body>