Skip to content

Instantly share code, notes, and snippets.

View marcelduran's full-sized avatar

Marcel Duran marcelduran

  • Google Inc.
  • SF Bay Area
View GitHub Profile
@marcelduran
marcelduran / gist:889721
Created March 27, 2011 22:42
YUI3 sandboxing
(function (d){
var iframe = d.body.appendChild(d.createElement('iframe')),
doc = iframe.contentWindow.document;
iframe.style.cssText = 'position:absolute; top:-999em';
doc.open();
doc.write('
<body onload="
YUI_config={win:window.parent,doc:window.parent.document};
@marcelduran
marcelduran / cpuusage.js
Last active December 18, 2015 05:38
Getting CPU(s) usage % with NodeJS,based on: https://github.com/oscmejia/os-utils/blob/master/lib/osutils.js
var os = require('os');
const RESOLUTION = 1000; // 1s CPU resolution
function cpusInfo() {
return os.cpus().map(function(cpu) {
var t = cpu.times;
return {
total: t.user + t.nice + t.sys + t.irq + t.idle,
@marcelduran
marcelduran / kbps.sql
Last active December 18, 2015 19:19
I always wondered what could be a good "page speed" metric. Since most pages have a few kbytes of payload and take a few seconds to load kbps (kilobytes per second) could be a good metric. The following httparchive bigquery shows the "page speed" in kbps quantiles as well as min, max, avg and count for both desktop and mobile pages.Check it out h…
SELECT client + ' (' + STRING(volume) + ')' AS client, mean, q_10th, q_25th, median, q_75th, q_90th, q_95th, q_99th
FROM
(SELECT
'desktop' AS client,
COUNT(0) AS volume,
AVG((bytesTotal / 1024) / (fullyLoaded / 1000)) as mean,
NTH(101, QUANTILES((bytesTotal / 1024) / (fullyLoaded / 1000), 1001)) AS q_10th,
NTH(251, QUANTILES((bytesTotal / 1024) / (fullyLoaded / 1000), 1001)) AS q_25th,
NTH(501, QUANTILES((bytesTotal / 1024) / (fullyLoaded / 1000), 1001)) AS median,
NTH(751, QUANTILES((bytesTotal / 1024) / (fullyLoaded / 1000), 1001)) AS q_75th,
@marcelduran
marcelduran / httparchi_twitter.sql
Created July 16, 2013 00:04
Select all data from HTTPArchive dumps for twitter.com only
SELECT * FROM
(SELECT * FROM [httparchive:runs.2010_11_15_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2010_11_29_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2010_12_16_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2010_12_28_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2011_01_20_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2011_01_31_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2011_02_11_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2011_02_26_pages] WHERE url = "http://www.twitter.com/"),
(SELECT * FROM [httparchive:runs.2011_03_15_pages] WHERE url = "http://www.twitter.com/"),
<!doctype html>
<html>
<head>
<script>console.log('pre css', performance.now());</script>
<link rel="stylesheet" href="http://1.cuzillion.com/bin/resource.cgi?type=css&sleep=2&n=1&t=12345" onload="console.log('css load', performance.now())">
<script>console.log('post css', performance.now());</script>
</head>
<body>
<h1>foo</h1>
<script>console.log('dom', performance.now());</script>
@marcelduran
marcelduran / flickr_archive_downloader_browser.js
Last active December 28, 2016 02:18
Flickr archive bulk downloader
var PAD = '00000';
var count = {
all: 0,
day: 0,
single: 0
};
var timer, isFirst, imgs, current;
@marcelduran
marcelduran / gist:1e91b64849e4c0572de2
Created May 14, 2014 18:09
PhantomJS script to pseudo-retina screenshots
var page = require('webpage').create(),
address, output, size;
page.onConsoleMessage = function(msg, lineNum, sourceId) {
console.log('CONSOLE: ' + msg);
};
if (phantom.args.length < 2 || phantom.args.length > 6) {
console.log('Usage: rasterize.js URL filename WxH retina ua');
phantom.exit();
@marcelduran
marcelduran / app.js
Created June 26, 2014 04:14
defer.me
require('http').createServer(function(req,res){
console.log(req.headers['user-agent']);
res.writeHead(200, {
'Content-Type': 'text/css',
//'Cache-Control': 'private, max-age=' + 60*60*24*365*10,
//'Expires': new Date(new Date().getTime()+(1000*60*60*24*365*10)).toUTCString(),
'Vary': 'Accept-Encoding'
});
/*res.end(); return;*/
var d = new Date();
@marcelduran
marcelduran / screenxote.js
Created June 26, 2014 04:24
Screenxote, screenshot of page regions
var args = require('system').args,
page = require('webpage').create();
// valid options
var opts = {
'v': 'viewport',
'a': 'area',
's': 'selector',
'o': 'output',
'c': 'custom'
<!doctype html>
<html>
<head>
<script>foo = 'iframe'</script>
</head>
<body>
<iframe src="index.html"></iframe>
</body>
</html>