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 / 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 / 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 / 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 / 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