Skip to content

Instantly share code, notes, and snippets.

View williamlsh's full-sized avatar
🎯
Focusing

William williamlsh

🎯
Focusing
  • Western Hemisphere
View GitHub Profile
func birthTime(){
sampleFile := "testdata/sample.md"
fi, err := os.Stat(sampleFile)
if err != nil {
return
}
// fmt.Printf("file info: %v", fi.ModTime())
stat := fi.Sys().(*syscall.Stat_t)
birthTime := time.Unix(stat.Birthtimespec.Unix()).Unix()
function createMarkup() {
return {__html: 'First · Second'};
}
function MyComponent() {
return <div dangerouslySetInnerHTML={createMarkup()} />;
}
function htmlDecode(str) {
const doc = new DOMParser().parseFromString(str, 'text/html');
return doc.documentElement.innerHTML;
}
// htmlDecode example
// const str =
// '\u003ch1\u003e\n\u003ca id="user-content-sonnet-1" class="anchor" href="#sonnet-1" aria-hidden="true"\u003e\u003cspan aria-hidden="true" class="octicon octicon-link"\u003e\u003c/span\u003e\u003c/a\u003eSonnet 1\u003c/h1\u003e\n\u003cp\u003eFrom fairest creatures we desire increase,\nThat thereby beauty’s rose might never die,\nBut as the riper should by time decease,\nHis tender heir might bear his memory:\nBut thou, contracted to thine own bright eyes,\nFeed’st thy light’st flame with self-substantial fuel,\nMaking a famine where abundance lies,\nThyself thy foe, to thy sweet self too cruel.\nThou that art now the world’s fresh ornament\nAnd only herald to the gaudy spring,\nWithin thine own bud buriest thy content\nAnd, tender churl, makest waste in niggarding.\nPity the world, or else this glutton be,\nTo eat the world’s due, by t
var (
postContentType = "text/plain"
articlesDir = "articles"
htmlExt = ".html"
)
// renderMarkdown posts raw markdown texts to Github REST api service to render.
// It then writes a rendered HTML file with the same name as its coresponding article tile under articles directory.
func renderMarkdown(articlesDir, title string, body io.Reader) (err error) {
resp, err := http.Post(url, postContentType, body)
// Reference: https://www.reddit.com/r/golang/comments/apf6l5/multiple_files_upload_using_gos_standard_library/
//
// Original author: https://www.reddit.com/user/teizz
//
// handles multiple files being uploaded
// reads them in blocks of 4K
// writes them to a temporary file in $TMPDIR
// calculates and logs the SHA256 sum
// proceeds to remove the temporary file through a defer statement
package main
package main
import "fmt"
func main() {
f := fibonacci()
fmt.Println(f())
}
func fibonacci() func()int {
function fabonacci() {
let fabonacciArray = [1, 1];
let fn;
return function cur() {
const len = fabonacciArray.length;
fn = fabonacciArray.slice(len - 2, len).reduce((pre, cur) => pre + cur);
fabonacciArray.push(fn);
console.log(fabonacciArray);
return fn;
};
/**
* 2018 William
* Array duplication counter
* Count duplicate elements in a array
*/
'use strict';
const caseArr = [1, 2, 2, 3, 3, 3];
const caseArr2 = ['Hello', 'Hello', 'hello', 'j', 'j', 'k'];