Skip to content

Instantly share code, notes, and snippets.

View ariya's full-sized avatar
💭
I may be slow to respond.

Ariya Hidayat ariya

💭
I may be slow to respond.
View GitHub Profile
@ariya
ariya / post.js
Created May 28, 2011 09:09
Example using HTTP POST operation
var page = new WebPage(),
server = 'http://posttestserver.com/post.php?dump',
data = 'universe=expanding&answer=42';
page.open(server, 'post', data, function (status) {
if (status !== 'success') {
console.log('Unable to post!');
} else {
console.log(page.content);
}
@ariya
ariya / pizza.js
Created May 29, 2011 05:33
Find pizza in New York using Google Local
var page = new WebPage();
page.onConsoleMessage = function (msg) {
console.log(msg);
};
page.open('http://www.google.com/m/local?site=local&q=pizza+in+new+york', function (status) {
if (status !== 'success') {
console.log('Unable to access network');
} else {
@ariya
ariya / netsniff.js
Created June 7, 2011 07:08
onResourceRequested example
var page = new WebPage(), address, resources = [];
if (phantom.args.length === 0) {
console.log('Usage: netsniff.js <some URL>');
phantom.exit();
} else {
address = phantom.args[0];
page.onLoadStarted = function () {
page.startTime = Date.now();
@ariya
ariya / result.txt
Created June 7, 2011 07:08
m.bing.com
All resources:
[
{
"method": "GET",
"url": "http://m.bing.com/",
"time": 1
},
{
"method": "GET",
"url": "http://m.bing.com/css/1/V1/common.css",
Increase the goat teleporter timeout threshold to 100 because the old
value of 10 caused problems for extremely overweight goats. Tests show
that the largest goat in existence should be teleported in 50ms, so...
BUG=31337,2754
TEST=Try loading an overweight goat and confirm the teleporter works.
@ariya
ariya / unrandomize.js
Created August 22, 2011 03:40
Modify global object at the page initialization.
// Modify global object at the page initialization.
// In this example, effectively Math.random() always returns 0.42.
var page = new WebPage();
page.onInitialized = function () {
page.evaluate(function () {
Math.random = function() {
return 42 / 100;
};
@ariya
ariya / webtoddler.html
Created September 14, 2011 21:50
HTML boilerplate: toddler's version
<html>
<head></head>
<shoulder></shoulder>
<knees></kneeds>
<toes></toes>
</html>
@ariya
ariya / webtoddler.html
Created September 14, 2011 21:52
HTML boilerplate: toddler's version
<html>
<head></head>
<shoulder></shoulder>
<knees></knees>
<toes></toes>
</html>
@ariya
ariya / prevent-onload.js
Created September 17, 2011 16:43
PhantomJS 1.3 example: prevent window.onload
var page = new WebPage(),
address;
// Let's see what the web page's console might output.
page.onConsoleMessage = function (msg) {
console.log('from web page: ' + msg);
};
// Hijack assignment to window.onload to do nothing.
page.onInitialized = function () {
/* raw and ugly */
@-webkit-keyframes anim {
0% { -webkit-transform: translate3d(0px, 0px, 0px); }
100% { -webkit-transform: translate3d(150px, 0px, 0px) } }
/* formatted using http://senchalabs.github.com/cssbeautify */
@-webkit-keyframes anim {
0% {
-webkit-transform: translate3d(0px, 0px, 0px);
}