Skip to content

Instantly share code, notes, and snippets.

@pingyen
pingyen / gaCse.html
Last active Dec 11, 2015
Google Analytics + Custom Search
View gaCse.html
<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 Dec 11, 2015
document.write Hijacking
View docWriteHijack.html
<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 / deflateCSS.js
Last active Dec 11, 2015
CSS Deflating Logic
View deflateCSS.js
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 / pageList.html
Last active Aug 29, 2015
Page List Display Logic
View pageList.html
<script>
for(var page = 1; page <= 20; ++page) {
for(var pageNum = 1; pageNum <= 20; ++pageNum) {
if (page <= pageNum) {
console.log(getPageDetail(page, pageNum));
}
}
}
@pingyen
pingyen / getBoxFileDetails.js
Created Mar 17, 2015
Getting Box File Details
View getBoxFileDetails.js
var folderID = '1234567890',
pageNum = 100;
var jsons = [],
files = [];
for (var i = 0; i < pageNum; ++i) {
jsons.push($.getJSON('https://app.box.com/index.php?rm=box_item_list&q[sort]=name&q[direction]=DESC&q[id]=d_' + folderID + '&q[page_num]=' + i + '&q[page_size]=20&q[theme_id]=1&q[collection_id]=0'));
}
@pingyen
pingyen / fetchXuitePhotos.php
Created Mar 17, 2015
Xuite Photo Downloader
View fetchXuitePhotos.php
<?php
$user = 'demo';
$html = '';
for ($i = 1; $i <= 100; ++$i) {
$html .= file_get_contents("http://photo.xuite.net/$user*$i");
}
$tokens = array_slice(explode('<p class="album_info_title">', $html), 1);
@pingyen
pingyen / fetchXuiteVlogs.php
Created Mar 17, 2015
Xuite Vlog Downloader
View fetchXuiteVlogs.php
<?php
$user = 'demo';
$videos = array();
for ($i = 1; $i <= 3; ++$i) {
foreach (array_slice(explode('<div class="media_thumb">', file_get_contents('http://vlog.xuite.net/' . $user . '*' . $i)), 1) as $token) {
$hq = strpos($token, '<div class="media_hq">') !== false;
$token = substr($token, strpos($token, '<a href="/play/') + 15);
View googleCrawler.php
<?php
$q = 'demo';
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://www.google.com.tw/search?q=' . rawurlencode($q) . '&tbm=nws&tbs=qdr:d');
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Safari/537.36');
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_IPRESOLVE, CURL_IPRESOLVE_V4);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$html = curl_exec($ch);
View pttCrawler.php
<?php
require('phpQuery/phpQuery.php');
$ch = curl_init();
curl_setopt($ch, CURLOPT_USERAGENT, 'facebookexternalhit/1.1 (+https://www.facebook.com/externalhit_uatext.php)');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$articles = array();
@pingyen
pingyen / apple-touch-icon.html
Created Mar 18, 2015
HTML to Image Example
View apple-touch-icon.html
<style>
div {
background-color: #005e81;
color: #FFF;
font-weight: bold;
font-size: 240px;
font-family: sans-serif;
width: 540px;
height: 528px;
padding-top: 12px;