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 / pip.conf
Created August 16, 2017 04:13
Python snippets
[global]
timeout = 60
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
@92hackers
92hackers / gist:46abb237af4246369cee5d6dcab6adae
Created August 16, 2017 07:02
Js module only import single module from an big pakcage
import join from 'lodash/join' // es6, most useful when used with webpack.
const isArray = require('lodash/isArray') // node.js style.
@92hackers
92hackers / deepClone.js
Created August 18, 2017 09:34
javascript deep clone
const isArray = arr => Object.prototype.toString.call(arr) === '[object Array]'
const isObject = obj => Object.prototype.toString.call(obj) === '[object Object]'
/**
* Deep copy properties from src, and return cloned object
* @param {Object} src source object to clone from
*/
const deepClone = src => {
const dest = {}
const copy = (src, dest) => {
@92hackers
92hackers / with.py
Created August 18, 2017 12:55
Wrap open in a context manager, you must implement __enter__ and __exit__ methods
class File(object):
def __init__(self, file_name, method):
self.file_obj = open(file_name, method)
def __enter__(self):
return self.file_obj
def __exit__(self, type, value, traceback):
self.file_obj.close()
@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
@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 / 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 / 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
// 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 / 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