Skip to content

Instantly share code, notes, and snippets.

View gucheen's full-sized avatar

Cheng Gu gucheen

View GitHub Profile
@gucheen
gucheen / landing.html
Created January 26, 2024 02:03
b.guchengf.me landing
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Be Bold Creative Strategic</title>
<style>
* {
font-family: sans-serif;
@gucheen
gucheen / pinboard-json-to-netscape-html.js
Created August 15, 2023 13:34
convert pinboard json data to standard netscape html bookmarks
import fs from 'fs'
const rawFile = 'bookmarks.json'
const outputHTML = 'bookmarks.html'
const pinboardData = JSON.parse(fs.readFileSync(rawFile).toString())
fs.writeFileSync(outputHTML, `<!DOCTYPE NETSCAPE-Bookmark-file-1>
<!--This is an automatically generated file.
It will be read and overwritten.
@gucheen
gucheen / parseLodash.js
Created August 25, 2015 05:51
Safe JSON.parse with lodash.js
function parseLodash(str){
return _.attempt(JSON.parse.bind(null, str));
}
@gucheen
gucheen / fnm-arm64.sh
Last active December 2, 2021 16:58
fnm: install arm64 version of node from homebrew bottles
#!/bin/bash
# assume that you have installed homebrew, wget and fx(https://github.com/antonmedv/fx)
# do all things in /tmp
mkdir -p /tmp/fnm-node;
pushd /tmp/fnm-node;
# clean tmp
rm -fr ./*;
mkdir fnm;
const request = require('request');
const util = require('util');
const fs = require('fs');
const path = require('path');
const os = require('os');
const get = util.promisify(request.get);
const post = util.promisify(request.post);
const sleep = (ms) => {
@gucheen
gucheen / index.html
Created March 17, 2021 03:07
BrowserView-dragging-problem
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title></title>
<style>
*,
*::after,
*::before {
@gucheen
gucheen / color-scheme-wsl.reg
Created May 19, 2018 14:04
color scheme for wsl
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Console]
; 00BBGGRR, not RGB!
"ColorTable00"=dword:00000000 ; 0 - black
"ColorTable04"=dword:000000CD ; 1 - dark red
"ColorTable02"=dword:0000CD00 ; 2 - dark green
"ColorTable06"=dword:0000CDCD ; 3 - dark yellow
"ColorTable01"=dword:00EE0000 ; 4 - dark blue
"ColorTable05"=dword:00CD00CD ; 5 - dark magenta
@gucheen
gucheen / format-amount.ts
Created January 26, 2021 09:50
morden-elegant-way-to-format-currency-in-js
const amountFormatter = new Intl.NumberFormat('en-US', { style: 'currency', currency: 'CNY' })
/**
* 1234567.12 to 1,234,567.12
* @param amount
*/
export const formatAmount = (amount: number): string => {
if (typeof amount === 'undefined') {
return ''
}
@gucheen
gucheen / fix-hugo-md-file-time.js
Created January 21, 2021 06:15
fix hugo md files' time by its created time
// hugo list all > posts.csv
/*
When you export your markdown files from other application or system,
Files' created time will be incorrect.
This script fix these time by its date from hugo front matter.
works by `touch` command
*/
const fs = require('fs')
const path = require('path')
@gucheen
gucheen / typecho2hugo.js
Created January 13, 2021 02:06
export sqlite typecho posts to hugo. depends on del and better-sqlite3
const path = require("path");
const fs = require('fs');
const del = require('del');
const Database = require('better-sqlite3');
const db = new Database('typecho.db', { verbose: console.log, readonly: true });
const tmpFolder = path.resolve(__dirname, 'typecho2hugo');
if (fs.existsSync(tmpFolder)) {
del.sync(path.resolve(tmpFolder, '*'));