Skip to content

Instantly share code, notes, and snippets.

@pingyen
pingyen / xgettext.text
Created June 10, 2015 15:22
xgettext Example
$ xgettext -L PHP *.php includes/*.php -p languages/zh-Hant-TW/LC_MESSAGES -n --default-domain=default --from-code=UTF-8
@pingyen
pingyen / formatJSON.php
Created August 11, 2015 06:22
JSON Formatter
<?php
$path = '/path/to';
foreach(scandir($path) as $file) {
if (substr($file, -5) === '.json') {
$path2 = "$path/$file";
file_put_contents($path2, shell_exec("cat $path2 | python -m json.tool"));
}
}
?>
@pingyen
pingyen / jsIframe.html
Last active August 29, 2015 21:25
Put JS into Iframe
<iframe id="_if1" scrolling="no" style="width : 100%" ></iframe>
<script>
(function() {
var oIf = document.getElementById('_if1'),
win = oIf.contentWindow,
doc = win.document;
doc.write('<html><head></head><body><script src="http://postpet.jp/webmail/blog/clock_v1_moco.js" ></sc' + 'ript><body></html>');
if(doc.all) {
var scArr = doc.getElementsByTagName('script'),
@pingyen
pingyen / jsIframe2.html
Last active August 29, 2015 21:25
Put JS into Iframe 2
<iframe id="_if2" scrolling="no" style="width : 100%" ></iframe>
<script>
(function() {
var oIf = document.getElementById('_if2'),
win = oIf.contentWindow,
doc = oIf.contentWindow.document;
doc.write('<html><head></head><body><script src="http://www.lucido-l.jp/blogparts/parts.js" ></sc' + 'ript>');
if(doc.all) {
@pingyen
pingyen / jsIframe3.html
Last active August 29, 2015 21:25
Put JS into Iframe 3
<iframe id="_if3" scrolling="no" style="width : 100%" ></iframe>
<script>
(function() {
var oIf = document.getElementById('_if3'),
win = oIf.contentWindow,
doc = oIf.contentWindow.document;
doc.write('<html><head></head><body><script> google_ad_client = "pub-1821434700708607"; google_ad_slot = "8156194155"; google_ad_width = 200; google_ad_height = 200; </sc' + 'ript><script src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></sc' + 'ript>');
if(doc.all) {
@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 / 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 / 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 / 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 / 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;