Skip to content

Instantly share code, notes, and snippets.

@pingyen
pingyen / callService.php
Created April 20, 2017 06:18
Hinet VDSL Wi-Fi AP D-Link WBR-2200 Auto Dial-Up / Hang-Up
<?php
/* For Hinet VDSL Wi-Fi AP D-Link WBR-2200 */
// Log in http://192.168.0.1 &
// Get UID in Cookie by Chrome DevTools
define('UID', 'ABCxyz1234');
function callService($data) {
$ch = curl_init();
@pingyen
pingyen / guessCountry.php
Last active April 14, 2017 09:53
Guess Country by Locale
<?php
function guess_country_by_locale ($locale) {
$tokens = explode('-', strtolower($locale));
if (isset($tokens[1]) === true) {
$country = $tokens[1];
if ($country !== '') {
switch ($country) {
case 'hans':
@pingyen
pingyen / langCodes.json
Created April 13, 2017 14:08
Language Code Name Mapping
{
"aa": "Afar",
"ab": "Abkhazian",
"ae": "Avestan",
"af": "Afrikaans",
"ak": "Akan",
"am": "Amharic",
"an": "Aragonese",
"ar": "Arabic",
"as": "Assamese",
@pingyen
pingyen / compositionEventLogger.bookmarklet.js
Created March 8, 2017 05:55
Bookmarklet of Composition Event Logger
(function(){var b=document.createElement("div");b.style.cssText="position: fixed;bottom: 10px;right: 10px;padding: 10px;background: yellow;z-index: 2147483647";window.console2={log:function(a){console.log(a);b.innerHTML+=a+"<br />\n"}};"loading"!==document.readyState?document.body.appendChild(b):document.addEventListener("DOMContentLoaded",function(){document.body.appendChild(b)},!1);document.addEventListener("compositionstart",function(a){console2.log(["compositionstart",a.data,a.target].join(", "))},
!0);document.addEventListener("compositionupdate",function(a){console2.log(["compositionupdate",a.data,a.target].join(", "))},!0);document.addEventListener("compositionend",function(a){console2.log(["compositionend",a.data,a.target].join(", "))},!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);
};