Skip to content

Instantly share code, notes, and snippets.

Container C2
-------
| | |
-------
{
size: { width: 600 }
columns: [0,300],
rows: [
{
@Mr0grog
Mr0grog / getRenderQuad.js
Created July 27, 2010 08:19
Get a quadrilateral representing the rendered DOM node
/**
* elem.getBoundingClientRect() is awesome, BUT it doesn't actually explain
* where the edges are if an element is rotated, skewed or otherwise oddly
* transformed. This is a not pretty attempt to get the actual rendering quad
* (sadly, it has to modify the DOM to do its work).
* NOTE: designed for WebKit & Gecko.
* Everything but the getComputedStyle() call *should* work in IE, though.
*/
var getRenderQuad = function(elem) {
var quad = {},
@Mr0grog
Mr0grog / Object.defineProperties.js
Created December 4, 2012 06:21
Object.defineProperties modeled in JS
Object.defineProperties = function(O, Properties) {
// 1. If Type(O) is not Object throw a TypeError exception.
if (typeof(O) !== "object" || O == null) {
throw TypeError("Object.defineProperties called on non-object");
}
// 2. Let props be ToObject(Properties)
var props = Object(Properties); // not *exactly* the same, but similar enough
// 3. Let names be an internal list containing the names of each enumerable own property of props.
@Mr0grog
Mr0grog / Object.defineProperties.js
Created December 4, 2012 17:23 — forked from azendal/Object.defineProperties.js
Object.defineProperties modeled in JS
Object.defineProperties = function(O, Properties) {
// 1. If Type(O) is not Object throw a TypeError exception.
if (typeof(O) !== "object" || O == null) {
throw TypeError("Object.defineProperties called on non-object");
}
// 2. Let props be ToObject(Properties)
var props = Object(Properties); // not *exactly* the same, but similar enough
// 3. Let names be an internal list containing the names of each enumerable own property of props.
@Mr0grog
Mr0grog / jsc-nightly
Created December 19, 2012 07:10
Run the nightly build of JavaScriptCore and profile the generated bytecode. To use this, you have to have installed the WebKit Nightly build (http://nightly.webkit.org)
#!/bin/bash
# Run JSC (with the new bytecode profiler!)
#
# USAGE:
# jsc-nightly [PATH_TO_SCRIPT] [-p PROFILER_OUTPUT_PATH]
#
# e.g:
# jsc-nightly app.js -p app-profile.json
@Mr0grog
Mr0grog / gist:5180317
Created March 17, 2013 05:49
Pretty tail-call recursion for JavaScript.
// This was created as an answer for this JSMentors discussion: https://groups.google.com/d/topic/jsmentors/rG9KDmy7Z6A/discussion
/**
* Call this on a function to get a version that will do infinite tail-call recursion.
* The function that is passed in should take a function as its first argument.
* Instead of calling itself to recurse, the first argument should be called (when in tail position).
*
* @example
* var factorial = tailCallable(function(recurse, n, total) {
* total = total || 1;
/**
* Transition helper that allows elements to transition from
* scalar sizes (e.g. "2em") to "auto" (or vice versa). This is useful because
* browsers either simply do not animate such transitions or do them poorly.
*
* Requires your CSS to already have the transition defined. This just allows
* it to function without much jankiness.
*
* Usage:
*
@Mr0grog
Mr0grog / node-test-package.js
Last active August 29, 2015 13:56
Testing dependencies
#!/usr/bin/env node
var spawn = require('child_process').spawn;
var list = spawn('npm', ['list', '--json']);
var result = "";
list.stdout.on('data', function (data) {
result += data;
});

Keybase proof

I hereby claim:

  • I am mr0grog on github.
  • I am mr0grog (https://keybase.io/mr0grog) on keybase.
  • I have a public key ASCHEMnkYJbHpkkGywzma5kTvbxZvNaFusRi-XxcdoGBpwo

To claim this, I am signing this object:

@Mr0grog
Mr0grog / fix-hashes-versionista-styles.js
Created March 21, 2018 20:46
Quick-n-dirty script to roll through all the versions stored in `web-monitoring-db`, load their raw content, remove any unintentionally captured Versionista styling data, and validate their hashes. This makes some assumptions about how/where raw content is stored on S3.
'use strict';
const crypto = require('crypto');
const Iconv = require('iconv').Iconv;
const parallel = require('parallel-transform');
const pump = require('pump');
const request = require('request');
const stream = require('stream');
const S3 = require('aws-sdk/clients/s3');