Skip to content

Instantly share code, notes, and snippets.

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
Example using HTTP POST operation
View post.js
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
Find pizza in New York using Google Local
View pizza.js
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 Jun 7, 2011
onResourceRequested example
View netsniff.js
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();
View result.txt
All resources:
[
{
"method": "GET",
"url": "http://m.bing.com/",
"time": 1
},
{
"method": "GET",
"url": "http://m.bing.com/css/1/V1/common.css",
View commit.log
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 Aug 22, 2011
Modify global object at the page initialization.
View unrandomize.js
// 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 Sep 14, 2011
HTML boilerplate: toddler's version
View webtoddler.html
<html>
<head></head>
<shoulder></shoulder>
<knees></kneeds>
<toes></toes>
</html>
@ariya
ariya / webtoddler.html
Created Sep 14, 2011
HTML boilerplate: toddler's version
View webtoddler.html
<html>
<head></head>
<shoulder></shoulder>
<knees></knees>
<toes></toes>
</html>
@ariya
ariya / prevent-onload.js
Created Sep 17, 2011
PhantomJS 1.3 example: prevent window.onload
View prevent-onload.js
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 () {
View keyframes.css
/* 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);
}