Skip to content

Instantly share code, notes, and snippets.

View categoryTree.js
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'},
]
View reverseKGroupFromEnd.js
/**
* Definition for singly-linked list.
* function ListNode(val) {
* this.val = val;
* this.next = null;
* }
*/
/**
* @param {ListNode} head
* @param {number} k
View vue-map-editor.html
<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])
View vue-local-storage.js
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]))
},
View tang.html
<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>
@wintercn
wintercn / sim.html
Last active Mar 31, 2019
贝塞尔曲线模拟二次曲线
View sim.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<style>
.ball {
width:10px;
height:10px;
View editor.html
<a href="javascript:void 0;">abc</a>
<div id="editor" contentEditable="true" style="white-space:pre;">
abc
</div>
<div id="editor2" contentEditable="true" style="white-space:pre;">
abc
View m-Sum.js
var mSum = (m, n, a) =>
a.length ? m > 2 ? mSum(m, n, a.slice(0, a.length - 1)).concat(
mSum(m - 1 , n - a[a.length - 1], a.slice(0, a.length - 1)).map(e => e.concat([a[a.length - 1]]))) :
twoSum(n, a) :
[];
var twoSum = (n, a) => {
a.sort((x, y) => x - y);
var r = [];
if(a.length < 2) return r;
View translate.we
<template>
<div class="ct" style="transform:translate({{x}}, {{y}})" onpanstart=starthandler onpanmove=movehandler>
<text style="font-size: 42;">Move me!</text>
<image class="img" style="width: 400px; height: 400px;" src="{{img}}"></image>
</div>
</template>
<style>
.ct {
width: 750;
View quickSort.js
// 2018.5.11更新: 减少了swap
function qSort(compare) {
var swap = (p1, p2) => {
var tmp = this[p1];
this[p1] = this[p2];
this[p2] = tmp;
}
var sortRange = (start, end) => {
var midValue = this[start];
var p1 = start + 1, p2 = end - 1;
You can’t perform that action at this time.