Skip to content

Instantly share code, notes, and snippets.

@artjomb
artjomb / fsOverwrite.js
Last active August 29, 2015 14:05
phantomjs fs.overwrite
var fs = require('fs');
fs.overwrite = function(source, destination, maxTrials){
var overwritten = false;
var trials = 0;
maxTrials = parseInt(maxTrials)
maxTrials = !!maxTrials ? maxTrials : null;
while(!overwritten) {
if (maxTrials && trials > maxTrials) {
return -1;
var casper = require('casper').create();
var url = "http://example.com/";
casper.start().thenOpen(url).then(function() {
this.download(url, "example.html");
this.page.customHeaders = {
"Accept-Language": "hu"
};
}).thenOpen(url).then(function() {
@artjomb
artjomb / benchmark.js
Last active August 29, 2015 14:06
Test PhantomJS 1.9.7 selectors API speed for a huge DOM
var page = require('webpage').create();
var content = "",
max = 100000,
i;
for(i = 0; i < max; i++) {
content += '<form id="f' + i + '"><input type="hidden" name="in' + i + '" valuate"iv' + i + '"></form>';
}
page.evaluate(function(content){
// Run as: casperjs --cookies-file=cookies.txt SE_get_close_votes.js
// to skip logging in the next time or simply: casperjs SE_get_close_votes.js
// Don't forget to input your credentials
// The login is not perfect, so it might fail. Just try again.
var casper = require('casper').create({
viewportSize: {
width: 1280,
height: 800
},
@artjomb
artjomb / result
Last active August 29, 2015 14:08
Small testing file for CasperJS (test environment) to see when the test suite is stopped executing
E:\shared\temp\casper>Test file: test90.js
# test w/o wait
FAIL test false
# type: assert
# file: test90.js:5
# code: test.assert(false, "test false");
# subject: false
PASS test true
# test w/ wait
FAIL test false
@artjomb
artjomb / PhantomJS1.x_useragentstring
Created November 10, 2014 13:11
This user agent string corresponds to the same features that PhantomJS provides.
Mozilla/5.0 (Windows NT 6.0) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/13.0.782.41 Safari/535.1
var page = require('webpage').create();
var url = 'http://api.jquery.com/jQuery.ajax/';
page.open(url, function (status) {
var result = page.evaluate(function(url){
var result = "blah";
$.ajax({
async: false,
url: "/",
type: 'get',
var casper = require('casper').create();
casper.start("http://stackoverflow.com/contact", function(){
this.capture("test37_1.png"); // ""
this.sendKeys("#search > input", "abcd", {keepFocus: true});
this.capture("test37_2.png"); // "abcd"
this.page.sendEvent("keypress", casper.page.event.key.Left);
this.page.sendEvent("keypress", casper.page.event.key.Left);
this.sendKeys("#search > input", "12");
this.capture("test37_3.png"); // "ab12cd"
package mytest;
import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.security.Key;
import org.apache.commons.codec.binary.Base64;
public class Test19EncDec {