Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
bogdanRada / crawler.js
Created October 30, 2018 13:18 — forked from alexey-bass/crawler.js
Phantom Crawler
function log(msg) {
console.log(getTime()+ ': '+ msg);
}
function getTime() {
var d = new Date();
return pad(d.getHours()) +':'+ pad(d.getMinutes()) +':'+ pad(d.getSeconds()) +'.'+ rpad(d.getMilliseconds(), 3);
}
function pad(val, len) {
@bogdanRada
bogdanRada / generateSVG.js
Created October 30, 2018 13:18 — forked from tomazzaman/generateSVG.js
Generate PNG from a React-powered SVG. Server-side.
/**
* Run this with `babel-node generateSVG.js`
*/
import fs from 'fs';
import path from 'path';
import { Readable } from 'stream';
import childProcess from 'child_process';
import phantomjs from 'phantomjs';
import im from 'imagemagick';
import tmp from 'tmp';
@bogdanRada
bogdanRada / netsniff.js
Created October 30, 2018 13:18 — forked from mfn/netsniff.js
netsniff.js from phantomjs, added DOMContentLoaded
if (!Date.prototype.toISOString) {
Date.prototype.toISOString = function () {
function pad(n) { return n < 10 ? '0' + n : n; }
function ms(n) { return n < 10 ? '00'+ n : n < 100 ? '0' + n : n }
return this.getFullYear() + '-' +
pad(this.getMonth() + 1) + '-' +
pad(this.getDate()) + 'T' +
pad(this.getHours()) + ':' +
pad(this.getMinutes()) + ':' +
pad(this.getSeconds()) + '.' +
@bogdanRada
bogdanRada / README.md
Created October 30, 2018 13:18 — forked from tobiashm/README.md
Use PhantomJS to render PDF in Rails

Use PhantomJS to render PDF in Rails

Avoid disk IO

If you're deploying your app to somewhere where you can't be sure to have reliable disk read/write access, the normal strategy of writing to a temp-file doesn't work. Instead we can open a pipe to the Phantom.js process, and then pass in the HTML via stdin, and then have the rasterize.js script write out the resulting PDF to stdout, which we can then capture. Any log messages from the Phantom.js process can be passed via stderr if we want.

Session heist

@bogdanRada
bogdanRada / exporter.rb
Created October 30, 2018 13:17 — forked from Jpuelpan/exporter.rb
A very simple Ruby wrapper for PhantomJS.
# exporter.rb
# A very simple Ruby wrapper for PhantomJS
# for create PDF's or anything you can create with PhantomJS
require 'json'
class Exporter
class PhantomJSNotFound < StandardError; end
class << self
def default_options
var http = require('http');
var url = require('url');
var spawn = require('child_process').spawn, child;
var fs = require('fs');
var util = require('util');
var gm = require('gm');
var ssh2 = require('ssh2');
var debug = 1; // increase to increase verbosity
require('systemd');
@bogdanRada
bogdanRada / appcachefix.js
Created October 30, 2018 13:17 — forked from swarog/appcachefix.js
Fix for appcache issue with playing audio in offline mode in the Chrom on Android.
/**
* AppCache audio tag caching fix main code
*/
(function () {
//document.addEventListener("DOMContentLoaded", function () {
hashCode = function (str) {
var hash = 0;
if (str.length == 0) return hash;
for (var i = 0; i < str.length; i++) {
char = str.charCodeAt(i);
require 'uri'
require 'cgi'
require 'openssl'
require 'base64'
module YBoss
class Oauth
attr_accessor :consumer_key, :consumer_secret, :token, :token_secret, :req_method,
:sig_method, :oauth_version, :callback_url, :params, :req_url, :base_str
@bogdanRada
bogdanRada / decode_session_cookie.rb
Created October 25, 2018 12:16 — forked from tnez/decode_session_cookie.rb
The following can be pasted and evaluated in a rails (~> 3.2) console in order to give a simple utility function to inspect the session cookie that can be taken and pasted directly from browser dev-tools.