Skip to content

Instantly share code, notes, and snippets.

View 92hackers's full-sized avatar
🎯
Focusing

CHEN Yuan 92hackers

🎯
Focusing
View GitHub Profile
@92hackers
92hackers / numbers.js
Last active September 14, 2017 02:54
javascript number types
const binary = 0b1111
//=> 15
const oct = 0o1111
//=> 585
const decimal = 1111
// => 1111
const hex = 0x1111
@92hackers
92hackers / code_refactor.js
Created September 13, 2017 12:34
compare two snippets
const value = Number(amount)
this.validateFaield = !isNaN(value) ? value > balance : true
||
||
this.validateFailed = !(value <= balance)
// compare NaN value always return false.
@92hackers
92hackers / common_fields.md
Last active September 3, 2017 02:19
Common fields to a database model
schema type description
id number id of current instance
created_at date when instance created?
updated_at date when instance updated?
status [1,2,3] life status of instance
@92hackers
92hackers / README-Template.md
Created August 31, 2017 11:58 — forked from avikalkohlinagarro/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

@92hackers
92hackers / switch-to-terminal.js
Created August 31, 2017 11:56
vsCode switch to terminal from editor panel
[
{ "key": "ctrl+`", "command": "workbench.action.focusActiveEditorGroup", "when": "terminalFocus" },
{ "key": "ctrl+`", "command": "workbench.action.terminal.focus", "when": "!terminalFocus" }
]
// Paste above code into F1: Open KeyboardShortcuts preferences. yourself keybinds.json
// regex 分组的一个好例子
const pattern = /^(0*([1-9]\d{1,3})\ +)?([1-9]\d{7,})$/
const str = '086 18118771840'
pattern.exec(str)
/* => [ '086 18118771840', '086 ', '86', '18118771840' ]
* 这里,用正则来匹配想要的字段,加上括号,即可自动分组,
* 应用: 根据条件提取字段,分组甚至能够在正则表达式里面直接使用。
*/
@92hackers
92hackers / comparisons.js
Created August 30, 2017 08:41
Three kinds of comparisons in Javascript
// 1, Object.is
Object.is('hello', 'hello')
// => true
Object.is(+0, -0)
// => false
Object.is(NaN, NaN)
// => true
@92hackers
92hackers / backslash.js
Created August 22, 2017 03:49
javascript deals with back slach, useful when involved Windows OS
'C:\Users\Administrator/Desktop/7-42.pdf' is wrong.
should be 'C:\\Users\\Administrator/Desktop/7-42.pdf'
because \ is preserved to escape character.
const str = 'C:\\Users\\Administrator/Desktop/7-42.pdf'
str.replace(/\//g, '\\')
// => 'C:\\Users\\Administrator\\Desktop\\7-42.pdf'
@92hackers
92hackers / reduce.md
Last active August 22, 2017 09:06
Javascript reduce function and dynamic keys in es6 format

Objects can be created with computed keys, so es6.ruanyifeng.com is not enough.

const obj = {
  [variable]: value,
}

Reduce, the simplest way to accummulate datas. reduce set first item as initial value default.

const total = ['age', 'name', 'favourite'].map(key =&gt; dataLists.reduce((sum, data) =&gt; ({
@92hackers
92hackers / init.sh
Last active August 10, 2019 07:25
配置新的开发环境----(oh-my-zsh, vim, docker, git, clang, cmake) 里面凝结了搞机的许多技能,值得读完。
#! /usr/bin/env bash
# sudo passwd root: set password for root user
sudo passwd root # for root user
sudo passwd $USER # for current logged in user.
# Add a new user
sudo adduser <qm>
# add epel yum repository