Skip to content

Instantly share code, notes, and snippets.

@pingyen
pingyen / deflateCSS.js
Last active December 11, 2015 11:38
CSS Deflating Logic
function deflate(css) {
// remove remark
css = css.replace(/\/\*[\s\S]*?\*\//g, '');
// uniform @import
css = css
.replace(/@import\s+url\(\s*"([^"]+)"\s*\)\s*;/g, '@import "$1";')
.replace(/@import\s+url\(\s*\'([^\']+)\'\s*\)\s*;/g, '@import "$1";')
.replace(/@import\s+url\(\s*([\S^\)]+)\s*\)\s*;/g, '@import "$1";')
.replace(/@import\s*"([^"]+)"\s*;/g, '@import "$1";')
@pingyen
pingyen / docWriteHijack.html
Last active December 11, 2015 05:38
document.write Hijacking
<div id="target" ></div>
<script>
var google_ad_client = 'ca-pub-1821434700708607',
google_ad_slot = '2826960791',
google_ad_width = 728,
google_ad_height = 90;
(function() {
var w = document.write;
@pingyen
pingyen / gaCse.html
Last active December 11, 2015 05:38
Google Analytics + Custom Search
<script src="http://www.google-analytics.com/ga.js" ></script>
<script>
try {
var pageTracker = _gat._getTracker('UA-6851063-1');
pageTracker._trackPageview();
} catch(e) {}
</script>
<form action="http://www.google.com.tw/cse" target="_blank" style="margin : 10px 0" >
<input type="hidden" name="cx" value="partner-pub-1821434700708607:3830778188" >
@pingyen
pingyen / jsConsoleCustom.js
Last active December 11, 2015 04:38
JavaScript Console Customization
(function() {
var arr = ['log', 'error', 'info', 'warn', 'trace'],
n = arr.length;
for(var i = 0; i < n; ++i) {
(function(k) {
var f = console[k];
console[k] = function() {
var arr = Array.prototype.slice.call(arguments);
@pingyen
pingyen / ui.js
Created September 20, 2012 10:06
WinJS.UI ui.js
This file has been truncated, but you can view the full file.
/// <loc filename="Metadata\ui_loc_oam.xml" format="messagebundle" />
/*!
© Microsoft. All rights reserved.
This library is supported for use in Windows Store apps only.
Build: 1.0.9200.20498.win8_ldr.120817-1716
Version: Microsoft.WinJS.1.0
*/
@pingyen
pingyen / base.js
Created September 20, 2012 10:04
WinJS base.js
/// <loc filename="Metadata\base_loc_oam.xml" format="messagebundle" />
/*!
© Microsoft. All rights reserved.
This library is supported for use in Windows Store apps only.
Build: 1.0.9200.20498.win8_ldr.120817-1716
Version: Microsoft.WinJS.1.0
*/
@pingyen
pingyen / twd97Conv.php
Last active April 30, 2023 15:47
Transform TWD97 to Latitude Longitude
<?php
function twd97_to_latlng($x, $y) {
$a = 6378137.0;
$b = 6356752.314245;
$lng0 = 121 * M_PI / 180;
$k0 = 0.9999;
$dx = 250000;
$dy = 0;
$e = pow((1 - pow($b, 2) / pow($a, 2)), 0.5);
@pingyen
pingyen / plurkBot2.php
Last active June 29, 2017 11:11
Plurk Bot with Reply
<?php
define('NICKNAME', 'abc');
define('PASSWORD', 'iamabc');
define('USER_ID', '123456');
$message = 'Hello World!';
$reply = 'I am ABC!';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
@pingyen
pingyen / jsFuncCall.html
Last active August 30, 2015 02:15
JavaScript Function Call Performance Test
<html>
<head>
</head>
<body>
<script>
var i,
max = 10000000;
for(i = 0; i < max; ++i);
@pingyen
pingyen / plurkBot.php
Last active October 20, 2018 22:14
Plurk Bot
<?php
define('NICKNAME', 'abc');
define('PASSWORD', 'iamabc');
define('USER_ID', '123456');
$message = 'Hello World!';
$ch = curl_init();
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');