Skip to content

Instantly share code, notes, and snippets.

@TianyiLi
TianyiLi / lib.js
Last active March 9, 2018 02:50
sample lib
module.exports.repeatWord = (length) => _char => Array.from({ length }, e => _char).join('')
module.exports.range = (length, start = 0) => Array.from({ length }, (_, i) => i + start)
module.exports.zeroAdd = (length, str) => (repeatWord(length)('0') + str).slice(length * -1)
@TianyiLi
TianyiLi / vue-global.d.ts
Created October 18, 2017 02:25
vue global type declaration
import * as _vue from "./vue";
declare global {
const Vue: typeof _vue.Vue;
}
@TianyiLi
TianyiLi / track.js
Last active October 17, 2017 08:30
javascript lines track
export function logger(...arg){
let parrent = new Error()
.stack
.split("\n")[2]
.trim()
.replace(/^at /, '')
.replace(__dirname, '')
let log = arg.forEach(e=>{ e = typeof e === 'string' ? e : JSON.stringify(e, null, 4)}).join(' ')
return log
}
@TianyiLi
TianyiLi / .vimrc
Created August 4, 2017 08:59
vimrc
" Fisa-vim-config
" http://fisadev.github.io/fisa-vim-config/
" version: 8.3.1
" ============================================================================
" Vim-plug initialization
" Avoid modify this section, unless you are very sure of what you are doing
let vim_plug_just_installed = 0
let vim_plug_path = expand('~/.vim/autoload/plug.vim')
@TianyiLi
TianyiLi / Dockerfile
Created August 1, 2017 07:12
ubuntu 12.04 with nodejs 6.11.1 and dbus-dev lib
FROM ubuntu:12.04
RUN apt-get update
RUN apt-get upgrade -y
RUN apt-get install -y build-essential && \
apt-get install -y python-software-properties software-properties-common && \
apt-get install -y byobu curl git htop man unzip vim wget pkg-config libdbus-1-dev && \
add-apt-repository -y ppa:ubuntu-toolchain-r/test && \
apt-get update && \
apt-get install -y gcc-4.9 g++-4.9 && \
#!/bin/bash
sudo apt-get update
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo apt-key fingerprint 0EBFCD88
@TianyiLi
TianyiLi / request-get.js
Created June 3, 2017 12:25
Memumusic get sample
function get(url, data, headers = []) {
let formBody = !!data ? Object.keys(data).map(k => `${encodeURIComponent(k)}=${data[k]}`).join('&') : '';
let getUrl = formBody.length ? `${url}?${formBody}` : url;
let header = new Headers({
'Accept': 'application/json',
'Content-Type': 'application/x-www-form-urlencoded'
})
headers.map(ele => {
const { name, value } = ele
if (name && value)
@TianyiLi
TianyiLi / test.js
Created April 5, 2017 12:43
iframe cross domain
// from parent javascript would be
window.addEventListener('message', function(event){
// event handle
console.log(event)
})
// use button click to send event 'test' could be anything
function send(){
let iframe = window.frames[0];
iframe.postMessage('test', document.querySelector('iframe').src);
@TianyiLi
TianyiLi / tsconfig.json
Last active June 3, 2017 12:29
typescript normal config
{
"compileOnSave": false,
"buildOnSave": false,
"compilerOptions": {
"module": "commonjs",
"target": "es6",
"noImplicitAny": false,
"sourceMap": false,
"outDir": "./dist/",
"typeRoots": [
@TianyiLi
TianyiLi / stomp.ts
Last active April 10, 2017 11:21
stomp use in back-end
import * as Stomp from 'webstomp-client';
import * as WebSocket from 'ws'
export class STOMP {
public state: STOMPState;
public messages: Stomp.Message;
private _config: StompConfig;
private _client: Stomp.Client;
private _resolvePromise: { (...args: any[]): void };
private _connectCallBack: (mes: Stomp.Message) => any;