Skip to content

Instantly share code, notes, and snippets.

View firedfox's full-sized avatar
🎯
Focusing

Daniel Wang firedfox

🎯
Focusing
  • Weimob
  • Shanghai, China
  • 13:28 (UTC +08:00)
View GitHub Profile
@firedfox
firedfox / config.html
Created May 11, 2012 08:53
another case for "phantomjs --web-security=no"
<script>
var xhttp=new XMLHttpRequest();
xhttp.open("GET","http://localhost:8888/start",false);
xhttp.send();
console.log(xhttp.responseText);
</script>
@firedfox
firedfox / gist:2861273
Created June 3, 2012 02:55
blarg i'm dead
Obj = function(){
this.properties = {'foo':'bar'};
}
Obj.prototype.returnTrue = function(){
return true;
}
var objInstance = new Obj();
@firedfox
firedfox / back.js
Created June 28, 2012 06:20
phantomjs history.back
var flag = false;
var page = require('webpage').create();
page.onLoadFinished = function() {
flag = !flag;
if (flag) {
console.log('jump to google');
page.evaluate(function() {
window.location.href = 'http://www.google.com/';
@firedfox
firedfox / parallel.js
Created June 28, 2012 12:03
parallel.js for phantomjs
const QUEUE_LENGTH = 1;
var numRunningJobs = 0;
var numWaitingJobs = 0;
var parrallelCallback = function() {
numRunningJobs --;
if (numRunningJobs === 0 && numWaitingJobs === 0) {
phantom.exit();
@firedfox
firedfox / zt_template.js
Created August 9, 2012 05:53
analytics code for tieba
var _hmt = _hmt || [];
$(function () {
$.getJSON("/f/user/json_userinfo?_=" + new Date().getTime(), function (response) {
var userInfo = response.data;
if (userInfo.is_login) {
console.log("login")
_hmt.push(['_setCustomVar', 1, 'login', 1]);
} else {
console.log("not_login");
_hmt.push(['_setCustomVar', 1, 'login', 0]);
@firedfox
firedfox / retrieve-text-files.js
Created August 10, 2012 09:49
phantomjs retrieving text files
const TEXT_PREFIX = /<html><head><\/head><body><pre style="word-wrap: break-word; white-space: pre-wrap;">/;
const TEXT_SUFFIX = /<\/pre><\/body><\/html>/;
var page = require('webpage').create();
page.onLoadFinished = function() {
var content = page.content;
if (TEXT_PREFIX.test(content) && TEXT_SUFFIX.test(content)) {
content = content.replace(TEXT_PREFIX, '').replace(TEXT_SUFFIX, '');
};
@firedfox
firedfox / log-into-reddit-2.phantom.js
Created August 21, 2012 11:12
phantomjs log into reddit
var page = require('webpage').create();
page.onLoadFinished = function() {
var username = page.evaluate(function() {
return $('span.user').children('a').html();
});
if (username !== 'cvUg338yQa') {
page.evaluate(function(username, password) {
$('input[name="user"]:first').attr('value', 'cvUg338yQa');
@firedfox
firedfox / holmes-im-looyu-0.js
Created August 28, 2012 06:51
holmes-im-looyu-0
(function() {
var REQUEST_PATH = '/virtual/im/';
var REQUEST_NAME = ['center', 'left-sum'];
var GET_ITEMS = function() {
return [
document.getElementById('doyoo_mon_accept'),
document.getElementById('ncontent')
];
};
@firedfox
firedfox / hi.baidu.com.php
Created September 12, 2012 03:16
get blogs from hi.baidu.com
<?php
require('simple_html_dom.php');
$html = file_get_html('http://hi.baidu.com/new/bdtongji');
foreach($html->find('article') as $element) {
$day = $element->find('.q-day', 0)->plaintext;
$monthYear = $element->find('.q-month-year', 0)->plaintext;
if (!is_null($day) && !is_null($monthYear)) {
@firedfox
firedfox / jskit.py
Created September 21, 2012 10:02
jskit
#!/usr/bin/python
import re, sys, urllib
if __name__ == '__main__':
e = len(sys.argv) >= 3
if len(sys.argv) > 1:
r = re.compile('([^\x00-\xff])')
f = open(sys.argv[1])
s = f.read()
try: