Skip to content

Instantly share code, notes, and snippets.

@chrisyip
chrisyip / lodash_baseSlice.js
Last active August 29, 2015 14:07
faster array-like slicer, aimed to replace [].slice.call(arguments). jsperf http://jsperf.com/from-slice-vs-slice-call
// https://github.com/lodash/lodash/blob/51e459b386f8301c803442f7fc722e46fc192d35/lodash.js#L2573
// 2 times faster!
function baseSlice(array, start, end) {
var index = -1,
length = array.length;
start = start == null ? 0 : (+start || 0);
if (start < 0) {
start = -start > length ? 0 : (length + start);
}
function isGenerator (input) {
return typeof input === 'function' && input.constructor.name === 'GeneratorFunction'
}
@chrisyip
chrisyip / c_works_no.md
Last active February 12, 2018 20:29
Fix Yosemite issues

If you encounter errors like this configure: error: C compiler cannot create executables, try this command on Terminal:

sudo ln -s /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain /Applications/Xcode.app/Contents/Developer/Toolchains/OSX10.10.xctoolchain

You should change XcodeDefault.xctoolchain and OSX10.10.xctoolchain tu suit your case.

@chrisyip
chrisyip / promisified-generator.js
Last active August 29, 2015 14:02
Promise with ES6 generator
// https://www.promisejs.org/generators/
function async(makeGenerator) {
return function () {
var generator = makeGenerator.apply(this, arguments);
function handle(result){
if (result.done) return Promise.resolve(result.value);
return Promise.resolve(result.value).then(function (res){
return handle(generator.next(res));
# http://EditorConfig.org
root = true
[*]
charset = utf-8
end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 2
@chrisyip
chrisyip / modify.sh
Created January 20, 2014 09:04
Modify committer and author information in Git
git filter-branch -f --env-filter "GIT_AUTHOR_NAME=''; GIT_AUTHOR_EMAIL=''; GIT_COMMITTER_NAME=''; GIT_COMMITTER_EMAIL='';" HEAD
@chrisyip
chrisyip / regex.js
Created January 7, 2014 06:30
Regex Collection
// 邮箱
/^(?:[a-z0-9]+[_\-+.]?)*[a-z0-9]+@(?:([a-z0-9]+-?)*[a-z0-9]+.)+([a-z]{2,})+$/i
// 手机:13012345678 - 19012345678
/^1[3-9]\d{9}$/
// 座机:02012345678、020-12345678、020 12345678、12345678,1234567
/^(?:((?:0\d{2,3}[- ]?)?[1-9]\d{6,7})|(?:[48]00[- ]?[1-9]\d{6}))$/
@chrisyip
chrisyip / fluid_gmail.js
Last active January 1, 2016 19:59 — forked from kirbysayshi/fluid_gmail.js
Gmail Unread Badge for Fluid
setTimeout(updateDockBadge, 1000)
setTimeout(updateDockBadge, 3000)
setInterval(updateDockBadge, 5000)
function updateDockBadge() {
var inboxLink = document.querySelector('a[href*="shva=1#inbox"]')
, badge = window.fluid.dockBadge
if (inboxLink && inboxLink.href && inboxLink.href.indexOf('mail.google.com') > -1) {
var match = inboxLink.title.match(/\((\d+)\)$/)
@chrisyip
chrisyip / for_global.txt
Last active February 19, 2020 10:26
SSLedge bypass list
127.0.0.1, anrdoezrs.net, *.anrdoezrs.net, w3ctech.com, *.w3ctech.com, hdtdxp.com, *.hdtdxp.com, uuzuonline.com, *.uuzuonline.com, luzhou.net, *.luzhou.net, cjphr.com, *.cjphr.com, fridaying.com, *.fridaying.com, bjokli.com, *.bjokli.com, 93txt.com, *.93txt.com, robotplayer.com, *.robotplayer.com, upai99.com, *.upai99.com, gemsky.net, *.gemsky.net, 00base.com, *.00base.com, mebi9t.com, *.mebi9t.com, is686.com, *.is686.com, cdncache.org, *.cdncache.org, sucaitianxia.com, *.sucaitianxia.com, 89178.com, *.89178.com, 5dmail.net, *.5dmail.net, oy66.com, *.oy66.com, shanghaining.com, *.shanghaining.com, book118.com, *.book118.com, zsbeike.com, *.zsbeike.com, hunantv.com, *.hunantv.com, ylunion.com, *.ylunion.com, mysilu.com, *.mysilu.com, 0737mp.com, *.0737mp.com, 37cu.com, *.37cu.com, longre.com, *.longre.com, yanzheng.com, *.yanzheng.com, lifeyoyo.com, *.lifeyoyo.com, wulinyingxiong.net, *.wulinyingxiong.net, yong9.net, *.yong9.net, communicatte.com, *.communicatte.com, ok92.net, *.ok92.net, junshishu.com, *.juns
@chrisyip
chrisyip / hosts.rb
Last active December 24, 2015 06:49
a command line tool to help add / delete / list / search hosts file.
#!/usr/bin/env ruby
# encoding: utf-8
require 'optparse'
require 'fileutils'
@options = {}
@hosts_path = '/private/etc/hosts'
OptionParser.new { |opts|