Skip to content

Instantly share code, notes, and snippets.

@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 / mdLinker.php
Created March 3, 2017 07:36
Add Link to .php .html file name in Markdown
<?php
$path = 'README.md';
$lines = explode("\n", file_get_contents($path));
foreach ($lines as &$line) {
$tokens = explode(' ', $line);
foreach ($tokens as &$token) {
$token = preg_replace('/(.+?)\.(html|php)/', '[$0]($0)', $token);
@pingyen
pingyen / platformDetection.php
Created January 11, 2017 06:35
iOS / Android Detection by User Agent
<?php
$platform = call_user_func(function() {
$token = $_SERVER['HTTP_USER_AGENT'];
if (isset($_GET['platform']) === true) {
$platform = $_GET['platform'];
return in_array($platform, array('iOS', 'Android', 'Other')) === true ?
$platform :
'Other';
@pingyen
pingyen / iosDupFind.php
Created December 31, 2016 17:06
iOS Duplicate Photos Finder
<?php
$map = array();
$base = '/path/to';
foreach (scandir($base) as $file) {
if ($name[0] === '.') {
continue;
}
@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 / 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));
}
?>