Skip to content

Instantly share code, notes, and snippets.

Avatar
🎮

Chris Yip chrisyip

🎮
View GitHub Profile
@chrisyip
chrisyip / encrypt-decrypt.js
Last active Jul 6, 2017 — forked from adrianbravo/encrypt-decrypt.js
Basic Node.js crypto cipher/decipher example.
View encrypt-decrypt.js
'use strict'
const crypto = require('crypto')
const key = 'salt_from_the_user_document'
const plaintext = '56d008a27c36552a0f97b291'
const cipher = crypto.createCipher('aes-256-cbc', key)
const decipher = crypto.createDecipher('aes-256-cbc', key)
let encryptedPassword = cipher.update(plaintext, 'utf8', 'base64')
encryptedPassword += cipher.final('base64')
@chrisyip
chrisyip / .eslintrc
Created Feb 19, 2016
Configuration file for ESLint v2
View .eslintrc
{
"parserOptions": {
"ecmaVersion": 6
},
"env": {
"es6": true,
"node": true
},
@chrisyip
chrisyip / stack-loader.js
Last active Mar 4, 2016
Batch module loader for node.js.
View stack-loader.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 / wechat-fluid-badge.js
Last active Jan 6, 2016
Add badge for WeChat w/ Fluid
View wechat-fluid-badge.js
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
View progress-bar.js
class ProgressBar {
constructor (viewSize) {
this.viewSize = viewSize
this.circleStrokeColor = '#249fff'
this.circleStrokeWidth = 5
this.circleFillColor = 'transparent'
let svg = this.svg = this.createSVG()
svg.setAttribute('width', viewSize)
@chrisyip
chrisyip / safeApply.js
Last active Aug 29, 2015
Safer $apply for angular, suppress $digest already in progress error
View safeApply.js
angular.module('myApp', [])
.run(function ($rootScope, $exceptionHandler) {
$rootScope.$safeApply = function (exp) {
var phase = (this.$root || this).$$phase
if (phase !== '$apply' && phase !== '$digest') {
this.$apply(exp)
} else {
try {
this.$eval(exp)
} catch (ex) {
View console.trace.js
// http://stackoverflow.com/questions/6715571/how-to-get-result-of-console-trace-as-string-in-javascript-with-chrome-or-fire
function getStackTrace () {
var obj = {}
// Remove arguments.callee from trace list
Error.captureStackTrace(obj, getStackTrace)
return obj.stack
}
console.log(getStackTrace())
@chrisyip
chrisyip / tower
Created Apr 20, 2015
Script for opening Git Tower
View tower
#!/usr/bin/env bash
if [ -x "/Applications/Tower.app" ] || [ -x "$HOME/Applications/Tower.app" ]; then
tower="Tower"
else
echo "Tower not found!"
exit 2
fi
if [ -z "$1" ]; then
@chrisyip
chrisyip / iojs.sh
Last active Feb 16, 2016
Get latest installed node from nvm path
View iojs.sh
#!/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 / who_uses_my_ports.sh
Created Dec 16, 2014
List ports being used
View who_uses_my_ports.sh
sudo lsof -i -P | grep -i "listen"