Skip to content

Instantly share code, notes, and snippets.

@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;
@pingyen
pingyen / fbGroupDump.php
Last active August 29, 2015 14:20
Download Facebook Group Feed, Memebers, & About
<?php
ini_set('date.timezone', 'Asia/Taipei');
$access_token = isset($argv[1]) ? $argv[1] : 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456';
$group_id = 123456789012345;
/* feed */
@pingyen
pingyen / fbUserDump.php
Last active August 29, 2015 14:20
Download Facebook User Feed
<?php
$access_token = isset($argv[1]) ? $argv[1] : 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz123456';
$user_id = 'me';
/* feed */
$until = time();
$since = intval(substr(array_values(array_filter(scandir(__DIR__ . '/feed/', true), function($val) { return substr($val, -5) === '.json'; }))[0], 0, -5));
@pingyen
pingyen / emscripten.txt
Created June 9, 2015 05:26
Emscripten Installation Guide
$ sudo apt-get install python-software-properties
$ sudo apt-add-repository ppa:chris-lea/node.js
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
$ sudo apt-get update
$ sudo apt-get install nodejs default-jre
$ sudo apt-get install gcc-4.8 g++-4.8
$ sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 20
$ sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 20
$ wget http://www.cmake.org/files/v3.2/cmake-3.2.3-Linux-x86_64.tar.gz
$ tar zxvf cmake-3.2.3-Linux-x86_64.tar.gz