Skip to content

Instantly share code, notes, and snippets.

View buddalee's full-sized avatar
🚲
Work in the Bicycle Industry

Roy Lee buddalee

🚲
Work in the Bicycle Industry
View GitHub Profile
@buddalee
buddalee / console.save.js
Created November 17, 2021 09:04 — forked from raecoo/console.save.js
Save JSON object to file in Chrome Devtool
// e.g. console.save({hello: 'world'})
(function(console){
console.save = function(data, filename){
if(!data) {
console.error('Console.save: No data')
return;
}
if(!filename) filename = 'console.json'
if(typeof data === "object"){
data = JSON.stringify(data, undefined, 4)
@buddalee
buddalee / example.js
Created June 4, 2021 08:17 — forked from magemore/example.js
upload image from clipboard on ctrl+v event on page
function uploadFile(file) {
var formData = new FormData();
formData.append("userfile", file);
var request = new XMLHttpRequest();
request.onload = function () {
if (request.status == 200) {
document.location.href='/';
} else {
alert('Error! Upload failed');
}
@buddalee
buddalee / nextjs-device-detect.js
Created May 27, 2020 06:36
Nextjs in server side to detect device with user agent
Nextjs in server side to detect device with user agent
@buddalee
buddalee / settings.json
Created February 14, 2020 09:31 — forked from doggy8088/settings.json
Will 保哥的 VSCode 使用者設定檔
{
"explorer.openEditors.visible": 0,
"workbench.colorTheme": "Default Light+",
"workbench.iconTheme": "vscode-simpler-icons",
"workbench.sideBar.location": "right",
// 需下載安裝 Fira Code 字型 (安裝 OTF 格式)
// https://github.com/tonsky/FiraCode/releases
// 需下載客製化過的 Microsoft YaHei Mono 字型
@buddalee
buddalee / flattenPages
Created June 11, 2019 06:44
flattenPages
const arr = [
{
title: '首頁',
id: 11,
parent_id: 0,
children: [
{
title: '子頁',
id: 12,
parent_id: 11,
@buddalee
buddalee / treeify
Created June 11, 2019 06:43
here is one in O(n log n) time treeify
const flattenArr = [
{ title: '首頁', id: 11, parent_id: 0, children: [] },
{ title: '子頁', id: 12, parent_id: 11, children: [] },
{ title: '產品頁', id: 21, parent_id: 0, children: [] }
]
function treeify(nodes) {
var indexed_nodes = {}, tree_roots = [];
for (var i = 0; i < nodes.length; i += 1) {
indexed_nodes[nodes[i].id] = nodes[i];
@buddalee
buddalee / version_3
Created September 18, 2018 02:54
for Echarts GL(sample data)
var xStr = `
0.000
0.000
0.043
0.162
0.393
0.769
1.323
2.116
3.336
@buddalee
buddalee / version_2
Created September 16, 2018 15:27
for Eric Echart gl line style
var series = [];
for (var y = -1; y < 1; y += 0.4) {
var data = [];
// Parametric curve
for (var x = -1; x < 1; x += 0.1) {
data.push([+x.toFixed(5), +y.toFixed(5), +(Math.sin(x * Math.PI + 0.22) * Math.sin(y * Math.PI + 0.22)).toFixed(5)]);
}
series.push({
type: 'line3D',
@buddalee
buddalee / version_1
Created September 16, 2018 15:02
for Eric Echart gl line style
option = {
visualMap: {
show: false,
dimension: 2,
min: 0,
max: 30
},
xAxis3D: {
type: 'value'
},