Skip to content

Instantly share code, notes, and snippets.

View paranoidjk's full-sized avatar

paranoidjk paranoidjk

View GitHub Profile
@paranoidjk
paranoidjk / regex.js
Last active October 25, 2016 07:14
regex snippet
var singleTagRE = /^<(\w+)\s*\/?>(?:<\/\1>|)$/;
var tagExpanderRE = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig;
var r20 = /%20/g;
var rhash = /#.*$/;
var rantiCache = /([?&])_=[^&]*/;
var rheaders = /^(.*?):[ \t]*([^\r\n]*)$/mg;
var rlocalProtocol = /^(?:about|app|app-storage|.+-extension|file|res|widget):$/;
var rnoContent = /^(?:GET|HEAD)$/;
var rprotocol = /^\/\//;
@paranoidjk
paranoidjk / hasOwnProperty.js
Created September 1, 2016 02:08 — forked from jimeh/hasOwnProperty.js
Cross-browser hasOwnProperty solution
/*
Cross-browser hasOwnProperty solution, based on answers from:
http://stackoverflow.com/questions/135448/how-do-i-check-to-see-if-an-object-has-an-attribute-in-javascript
*/
if ( !Object.prototype.hasOwnProperty ) {
Object.prototype.hasOwnProperty = function(prop) {
var proto = this.__proto__ || this.constructor.prototype;
return (prop in this) && (!(prop in proto) || proto[prop] !== this[prop]);
};
}
@paranoidjk
paranoidjk / rename.js
Created August 28, 2016 08:34
rename mutli images use nodejs
var fs = require('fs');
var path = require('path');
var dir = '/Users/jiangmu/Downloads/花花/';
fs.readdir(dir, function (err, files) {
if (err) {
console.log(err);
return;
}
@paranoidjk
paranoidjk / cancelPromise.md
Created April 18, 2016 07:41
If you use ES6 promises, you may need to wrap your promise in order to make it cancelable.

facebook/react#5465 (comment)

This simple method can be used to add cancel to any promise

const makeCancelable = (promise) => {
  let hasCanceled_ = false;

  const wrappedPromise = new Promise((resolve, reject) => {
    promise.then((val) =>
 hasCanceled_ ? reject({isCanceled: true}) : resolve(val)
@paranoidjk
paranoidjk / requestAnimationFrame.js
Last active March 15, 2016 01:58
a requestAnimationFrame polyfill
/* requestAnimationFrame.js
* by zhangxinxu 2013-09-30
*/
(function() {
var lastTime = 0;
var vendors = ['webkit', 'moz'];
for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || // name has changed in Webkit
window[vendors[x] + 'CancelRequestAnimationFrame'];
@paranoidjk
paranoidjk / iterm2Finder.alfredworkflow
Created March 7, 2016 13:42
open currnt iterm2 path in Finder
on alfred_script(q)
tell application "Finder"
set pathList to (quoted form of POSIX path of (folder of the front window as alias))
end tell
tell application "System Events"
if not (exists (processes where name is "Terminal")) then
do shell script "open -a Terminal " & pathList
else
tell application "Terminal"
@paranoidjk
paranoidjk / iterm2.alfredwoflow
Created March 7, 2016 13:23
alfred workflow which run command on iterm2
-- This is v0.6 of the custom script for AlfredApp for iTerm 2.9+
-- Please see https://github.com/stuartcryan/custom-iterm-applescripts-for-alfred/
-- for the latest changes.
-- Please note, if you store the iTerm binary in any other location than the Applications Folder
-- please ensure you update the two locations below (in the format of : rather than / for folder dividers)
-- this gets around issues with AppleScript not handling things well if you have two iTerm binaries on your system... which can happen :D
on alfred_script(q)
if application "iTerm2" is running or application "iTerm" is running then
@paranoidjk
paranoidjk / JS-Regular.html
Created February 25, 2016 02:51 — forked from lbj96347/JS-Regular.html
JS正则提取字符串/中文/英文/数字
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>javaScript正则表达式提取字符串中字母、数字、中文</title>
</head>
<body>
<input type="text" id="oText" value="李秉骏的常用代号是96347,英文名字是CashLee噢" size=100><br/>
<input type="button" value="number" onclick="get_character_you_want(this);">
@paranoidjk
paranoidjk / gist:2f6e3624b8b2d5e213cb
Created February 24, 2016 10:47
osx 将当前文件夹以及子文件夹所有.png 修改为.jpg
find . -name "*.png"|sed 's/.png//'|xargs -n1 -I {} mv {}.png {}.jpg
@paranoidjk
paranoidjk / ga.php
Created February 14, 2016 05:43
自动更新VPN密码到Keychain
<?php
error_reporting(0);
$key = strtoupper($argv[1]);
$lut = array(
'A' => 0, 'B' => 1, 'C' => 2, 'D' => 3,
'E' => 4, 'F' => 5, 'G' => 6, 'H' => 7,
'I' => 8, 'J' => 9, 'K' => 10, 'L' => 11,