Skip to content

Instantly share code, notes, and snippets.

View roark47's full-sized avatar
👨‍💻
Stare at the screen

Roark Li roark47

👨‍💻
Stare at the screen
  • Alibaba Group
  • China
  • 12:21 (UTC +08:00)
View GitHub Profile
@roark47
roark47 / add-property-to-function-in-ts.js
Created April 14, 2022 03:59
How to describe adding property to function with typescript
type IsFunc = {
value: boolean;
(getNew: boolean): boolean;
};
// More details:
// @see: https://melvingeorge.me/blog/add-properties-to-functions-typescript
export const isDevEnv = <IsFunc>((getNew: boolean) => {
if (isDevEnv.value && !getNew) {
return isDevEnv.value;
const pipe = (...fns) => (value) => reduce(fns, (acc, fn) => fn(acc), value)
const reduce = (array, fn, initialValue) => {
let accumlator
if (initialValue != undefined) {
accumlator = initialValue
} else {
accumlator = array[0]
}
if (initialValue === undefined) {
for (let i = 1; i < array.length; i++) {
accumlator = fn(accumlator, array[i])
@roark47
roark47 / algorithm-tool.js
Created March 8, 2020 07:35
用于算法练习的辅助工具脚本
/**
* 生成随机数数组(用于算法练习)
* @param {number} digits 生成多少位数字
* @param {number} length 数组长度
* @return {array} 包含需求的随机数组成数组
*/
function generateRandomNumberArray(digits = 3, length = 1000) {
if (typeof digits !== 'number' || typeof length !== 'number') {
throw new Error('Digits and length must be number type')
}
@roark47
roark47 / .prettierrc
Created September 26, 2019 05:56
prettier plugin local config.
{
"arrowParens": "always",
"bracketSpacing": true,
"cursorOffset": -1,
"endOfLine": "auto",
"htmlWhitespaceSensitivity": "css",
"jsxSingleQuote": true,
"printWidth": 80,
"semi": false,
"singleQuote": true,
@roark47
roark47 / h5-react.html
Created September 17, 2019 14:53
A simple demo for using react in html file.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>React Playground</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.2.1/react-dom.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/babel-core/5.8.23/browser.min.js"></script>
import Listener from './listeners.js'
const getModal = () => import('./src/modal.js')
Listener.on('didSomethingToWarrentModalBeingLoaded', () => {
// Async fetching modal code from a separate chunk
getModal().then((module) => {
const modalTarget = document.getElementById('Modal')
module.initModal(modalTarget)
})
// jQuery Callbacks & Deferred & when function
// ==== Callbacks ====
var flagsCache = {}
function createFlags(flags) {
var object = flagsCache[flags] = {},
i,
length
@roark47
roark47 / download file by JavaScript.js
Created January 11, 2018 03:13
a script about downloading file by JavaScript
function downloadData(data, filename, type) {
var file = new Blob(["\ufeff" + data], { type: type });
if (window.navigator.msSaveOrOpenBlob)
// IE10+
window.navigator.msSaveOrOpenBlob(file, filename);
else {
// Others
var a = document.createElement("a"),
url = URL.createObjectURL(file);
a.href = url;
@roark47
roark47 / movingCube.html
Last active April 24, 2017 16:09
Make a moving cube by CSS3 animation attribute
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>立方体</title>
<style>
/*为什么两层div包裹各面后,旋转时不会出现畸变?*/
.magic{
position: absolute;/*子元素的绝对定位首先寻找已定位的父元素作参照。*/
top: 50%;/*只有absolute才有top和left等值。 */