Skip to content

Instantly share code, notes, and snippets.

@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;
@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 / pageList.html
Last active August 29, 2015 14:10
Page List Display Logic
<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 March 17, 2015 14:47
Getting Box File Details
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 March 17, 2015 14:50
Xuite Photo Downloader
<?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 March 17, 2015 14:52
Xuite Vlog Downloader
<?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);
@pingyen
pingyen / googleCrawler.php
Created March 17, 2015 15:01
Crawling Google
<?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);
@pingyen
pingyen / pttCrawler.php
Created March 17, 2015 15:04
Crawling PTT
<?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 March 18, 2015 01:53
HTML to Image Example
<style>
div {
background-color: #005e81;
color: #FFF;
font-weight: bold;
font-size: 240px;
font-family: sans-serif;
width: 540px;
height: 528px;
padding-top: 12px;