Skip to content

Instantly share code, notes, and snippets.

@chrisyip
chrisyip / promised_sentry_capture_error.js
Created December 14, 2016 07:00
A promise version of Sentry.captureError.
'use strict'
const Raven = require('raven')
exports.capture = function (err, options = {}) {
return new Promise((resolve, reject) => {
const client = new Raven.Client(RAVEN_DSN)
const listener = res => {
@chrisyip
chrisyip / README.md
Created November 13, 2016 18:47
Vue v2 helpful plugins
Vue.components('my-component', {
  ready () {
    this.doSomething()
  }
})

equals

Vue.components('my-component', {
[
"a",
"abbr",
"address",
"area",
"article",
"aside",
"audio",
"b",
"base",
# video playback
vo=opengl-hq:icc-profile-auto
autofit-larger=95%x90%
autofit-smaller=30%x30%
# tries to automatically enable hardware decoding
hwdec=auto
# osd message, you can press o to display the osd message
osd-bar-align-y=0.9
osd-bar-h=1.2
/**
* Detect if element is in view
*
* @method isElementInView
* @param {HTMLElement} element the target element
* @param {HTMLElement} [parentElement] container element, default is widnow
* @param {Boolean} [ignoreBottom] useful when element is taller than container
* @return {Boolean} element is in view or not
*/
function isElementInView (element, parentElement, ignoreBottom) {
@chrisyip
chrisyip / clone_anythings.js
Created August 7, 2012 17:04
Clone Anything with JavaScript
// http://davidwalsh.name/javascript-clone
function clone(src) {
function mixin(dest, source, copyFunc) {
var name, s, i, empty = {};
for(name in source){
// the (!(name in empty) || empty[name] !== s) condition avoids copying properties in "source"
// inherited from Object.prototype. For example, if dest has a custom toString() method,
// don't overwrite it with the toString() method that source inherited from Object.prototype
s = source[name];
if(!(name in dest) || (dest[name] !== s && (!(name in empty) || empty[name] !== s))){
@chrisyip
chrisyip / stack-loader.js
Last active March 4, 2016 07:41
Batch module loader for node.js.
'use strict'
const addtionalExts = []
const fs = require('fs')
const path = require('path')
function find (root, p, re, recursive) {
if (root) {
p = path.resolve(root, p)
}
@chrisyip
chrisyip / .eslintrc
Created February 19, 2016 16:44
Configuration file for ESLint v2
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"es6": true,
"node": true
},
@chrisyip
chrisyip / iojs.sh
Last active February 16, 2016 06:03
Get latest installed node from nvm path
#!/usr/bin/env sh
if [ -d "$(brew --prefix)/Cellar" ]; then
node=`find /usr/local/Cellar -name node | grep iojs/.*/bin/node`
if [ ! -z "$node" ]; then
$node $@
else
echo "io.js not installed"
fi
else
@chrisyip
chrisyip / wechat-fluid-badge.js
Last active January 6, 2016 11:05
Add badge for WeChat w/ Fluid
setInterval(updateDockBadge, 500)
function updateDockBadge() {
var dots = document.querySelectorAll('.nav_view .chat_item .avatar .web_wechat_reddot_middle')
var badge = [].reduce.call(dots, function(pv, cv) {
var badge = Math.floor(cv.textContent)
if (isNaN(badge)) {
return 0