Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Lan Qingyong lanqy

🎯
Focusing
Block or report user

Report or block lanqy

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@lanqy
lanqy / bytesToSize.js
Created Mar 19, 2013
JavaScript To Convert Bytes To MB, KB, Etc
View bytesToSize.js
// from http://scratch99.com/web-development/javascript/convert-bytes-to-mb-kb/
function bytesToSize(bytes) {
var sizes = ['Bytes', 'KB', 'MB', 'GB', 'TB'];
if (bytes == 0) return 'n/a';
var i = parseInt(Math.floor(Math.log(bytes) / Math.log(1024)));
if (i == 0) return bytes + ' ' + sizes[i];
return (bytes / Math.pow(1024, i)).toFixed(1) + ' ' + sizes[i];
};
@lanqy
lanqy / eventemitter.js
Created May 12, 2019 — forked from mudge/eventemitter.js
A very simple EventEmitter in pure JavaScript (suitable for both node.js and browsers).
View eventemitter.js
/* Polyfill indexOf. */
var indexOf;
if (typeof Array.prototype.indexOf === 'function') {
indexOf = function (haystack, needle) {
return haystack.indexOf(needle);
};
} else {
indexOf = function (haystack, needle) {
var i = 0, length = haystack.length, idx = -1, found = false;
@lanqy
lanqy / regexCheatsheet.js
Created Jan 30, 2019 — forked from cxa/regexCheatsheet.js
A regex cheatsheet 👩🏻‍💻 (by Catherine)
View regexCheatsheet.js
let regex;
/* 匹配特定的字符串 */
regex = /hello/; // 查找斜杠中的字符串(大小写敏感)……匹配 "hello", "hello123", "123hello123", "123hello",但不匹配 "hell0", "Hello"
regex = /hello/i; // 查找斜杠中的字符串(大小写不敏感)……匹配 "hello", "HelLo", "123HelLO"
regex = /hello/g; // 全局查找斜杠中的字符串……
/* 通配符 */
regex = /h.llo/; // "." 匹配除了换行外的任何一个字符……匹配 "hello", "hallo",但不匹配 "h\nllo"
regex = /h.*llo/; // "*" 匹配任何字符零次或多次,如 "hello", "heeeeeello", "hllo", "hwarwareallo"
@lanqy
lanqy / regexCheatsheet.js
Created Jan 30, 2019 — forked from sarthology/regexCheatsheet.js
A regex cheatsheet 👩🏻‍💻 (by Catherine)
View regexCheatsheet.js
let regex;
/* matching a specific string */
regex = /hello/; // looks for the string between the forward slashes (case-sensitive)... matches "hello", "hello123", "123hello123", "123hello"; doesn't match for "hell0", "Hello"
regex = /hello/i; // looks for the string between the forward slashes (case-insensitive)... matches "hello", "HelLo", "123HelLO"
regex = /hello/g; // looks for multiple occurrences of string between the forward slashes...
/* wildcards */
regex = /h.llo/; // the "." matches any one character other than a new line character... matches "hello", "hallo" but not "h\nllo"
regex = /h.*llo/; // the "*" matches any character(s) zero or more times... matches "hello", "heeeeeello", "hllo", "hwarwareallo"
@lanqy
lanqy / walk.go
Created Nov 30, 2018 — forked from tdegrunt/walk.go
Replace some text in a bunch of files with golang
View walk.go
package main
import (
"fmt"
"io/ioutil"
"os"
"path/filepath"
"strings"
)
@lanqy
lanqy / read_line.go
Created Nov 30, 2018 — forked from kendellfab/read_line.go
Golang --> Read file line by line.
View read_line.go
func readLine(path string) {
inFile, _ := os.Open(path)
defer inFile.Close()
scanner := bufio.NewScanner(inFile)
scanner.Split(bufio.ScanLines)
for scanner.Scan() {
fmt.Println(scanner.Text())
}
}
@lanqy
lanqy / gist:c7c59765b13485dcd4f920e423b2adba
Created Aug 10, 2018 — forked from ChrisCinelli/gist:2051841
Logging of Javascript error on the Frontend to the Backend
View gist:c7c59765b13485dcd4f920e423b2adba
/* ==========================================================
*
* Log on a remote server most of the errors in the browser
*
* @author Chris Cinelli
*
* Depends on:
* stacktrace.js - https://github.com/eriwen/javascript-stacktrace
* jsonStringify.js - http://www.thomasfrank.se/json_stringify_revisited.html
*
View RouterComponentExample.re
let str = ReasonReact.string;
let el = ReasonReact.element;
let arr = ReasonReact.array;
module Dashboard = {
let component = ReasonReact.statelessComponent("Dashboard");
let make = _children => {
...component,
View BasicRouterExample.re
let str = ReasonReact.string;
let el = ReasonReact.element;
let arr = ReasonReact.array;
module Dashboard = {
let component = ReasonReact.statelessComponent("Dashboard");
let make = _children => {
...component,
View AdvancedRouter.re
let str = ReasonReact.string;
let el = ReasonReact.element;
let arr = ReasonReact.array;
module Dashboard = {
let component = ReasonReact.statelessComponent("Dashboard");
let make = _children => {
...component,
You can’t perform that action at this time.