Skip to content

Instantly share code, notes, and snippets.

@pingyen
pingyen / flickrDiff.php
Created December 30, 2016 21:23
Flickr Photo Set Diff
<?php
$key = isset($argv[1]) ? $argv[1] : 'ABC';
$users = array(
'ABC' => array(
'photoset_id' => '12345678901234567',,
'api_key' => '0123456789abcdef01234567890abcde',
'secret' => 'abcdef1234567890',
'auth_token' => '12345678901234567-1234567890abcdef'
),
@pingyen
pingyen / firebug-lite.js
Last active December 1, 2016 14:11
Firebug Lite Stable bookmarklet
javascript:(function(F,i,r,e,b,u,g,L,I,T,E){if(F.getElementById(b))return;E=F[i+'NS']&&F.documentElement.namespaceURI;E=E?F[i+'NS'](E,'script'):F[i]('script');E[r]('id',b);E[r]('src',I+g+T);E[r](b,u);(F[e]('head')[0]||F[e]('body')[0]).appendChild(E);E=new Image;E[r]('src',I+L);})(document,'createElement','setAttribute','getElementsByTagName','FirebugLite','4','firebug-lite.js','releases/lite/latest/skin/xp/sprite.png','https://getfirebug.com/','#startOpened');
@pingyen
pingyen / xmlhttprequest.spy.js
Created November 8, 2016 14:15
Spy of XMLHttpRequest
(function() {
var prototype = XMLHttpRequest.prototype,
open = prototype.open,
send = prototype.send;
prototype.open = function() {
alert('open: ' + JSON.stringify(arguments));
open.apply(this, arguments);
};
@pingyen
pingyen / scrollEventLogger.bookmarklet.js
Last active March 8, 2017 05:53
Bookmarklet of Scroll Event Logger
javascript:(function(){var a=document.createElement("div");a.style.cssText="position: fixed;bottom: 10px;right: 10px;padding: 10px;background: yellow;z-index: 2147483647";window.console={log:function(b){a.innerHTML+=b+"<br />\n"}};"loading"!==document.readyState?document.body.appendChild(a):document.addEventListener("DOMContentLoaded",function(){document.body.appendChild(a)},!1);var c=document.body.scrollTop,d=Date.now();window.addEventListener("scroll",function(b){b=document.body.scrollTop;var a=Date.now();
console.log([b-c,a-d,b,a].join(", "));d=a;c=b},!0)})();
@pingyen
pingyen / tar.php
Created October 28, 2016 04:42
Tar each directory separately
<?php
foreach (scandir('.') as $dir) {
if ($dir[0] === '.' || is_dir($dir) === false) {
continue;
}
shell_exec("tar zcvf $dir.tgz $dir");
}
?>
@pingyen
pingyen / checked.js
Created October 16, 2016 21:43
Check all checkboxes
Array.from(document.querySelectorAll('input[type=checkbox]')).forEach(function(checkbox) { checkbox.checked = true; });
@pingyen
pingyen / rename.php
Created October 16, 2016 09:16
Simple Renaming Logic of iOS Photos
<?php
foreach (scandir('.') as $file) {
if ($file[0] === '.') {
continue;
}
rename($file, substr($file, 0, -4) . ' 1' . substr($file, -4));
}
?>
@pingyen
pingyen / touchEventLogger.bookmarklet.js
Last active September 10, 2018 21:29
Bookmarklet of Touch Events Logger
javascript:(function(){var a=document.createElement("div");a.style.cssText="position: fixed;bottom: 10px;right: 10px;padding: 10px;background: yellow;z-index: 2147483647";window.console={log:function(e){a.innerHTML+=e+"<br />\n"}};"loading"!==document.readyState?document.body.appendChild(a):document.addEventListener("DOMContentLoaded",function(){document.body.appendChild(a)},!1)})();
"touchstart touchmove touchend touchcancel pointerdown pointermove pointerup pointercancel click dblclick mousedown mouseup mousemove".split(" ").forEach(function(a){document.addEventListener(a,function(a){var d=a.type,b,c;switch(d){case "touchstart":b=a.touches;break;case "touchmove":case "touchend":case "touchcancel":b=a.changedTouches}void 0===b?(c=1,b=a):(c=b.length,b=b[0]);console.log([d,b.button,b.buttons,c,a.target.nodeName,b.pageX,b.pageY,Date.now()].join(", "))},!0)});
@pingyen
pingyen / websockify.txt
Created August 29, 2016 09:45
Websockify Installation Guide
$ git clone git@github.com:kanaka/websockify.git
$ sudo apt-get install python-numpy
$ cd /path/to/websockify
$ make
$ sudo ufw allow 2023
$ ./run 2023 localhost:1314
@pingyen
pingyen / appFiguresGetAccessToken.php
Created August 25, 2016 13:38
AppFigures OAuth 2.0 Get Access Token PHP Example
<?php
define('CLIENT_KEY', 'abcdef0123456789abcdef0123456789');
define('SECRECT_KEY', '9876543210fedcba9876543210fedcba');
define('ACCESS_TOKEN', 'aAbBcCdDeEfFgGhH');
define('ACCESS_SECRET', 'sSTtUuvVwWxXyYzZ');
define('VERIFIER', 'rRGghHiIkKlLmMnN');
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://api.appfigures.com/v2/oauth/access_token');