Skip to content

Instantly share code, notes, and snippets.

@digitalicarus
digitalicarus / ply.js
Last active August 29, 2015 14:00
ply "parser"
var ply = function (raw) {
this.raw = raw;
this.parse();
};
ply.prototype.regex = {
newline: /\n/,
space: /\s+/,
leadspace: /^\s+/,
trailspace: /\s+$/,
//TODO: add object checks
searchTree function (node, getChildren, test) {
function find (node, parent) {
var kids = getChildren(node), i, ret = null;
if (test(node)) { return { parent: parent, match: node }; }
if (kids.length < 1) { return null; }
for (i=0; i<kids.length; i++) {
ret = find(kids[i], node);
if (ret) { return ret; }
(function () {
var w = window
, d = document
, b = d.body
, h = d.getElementsByTagName('head')[0]
, s = d.getElementsByTagName('script')
, c = {} // cache
, m // main
, i // iter
, x = /\.js$/
@digitalicarus
digitalicarus / blowpop.js
Created February 6, 2014 22:26
center and expand canvas
var D = document
, body = D.body
, canvas = D.body.appendChild(D.createElement('canvas'))
, ctx = canvas.getContext('2d')
, width = 480
, height = 272
;
function vendorStyle (ele, prop, val) {
var caps = prop.charAt(0).toUpperCase() + prop.slice(1)
@digitalicarus
digitalicarus / rb.js
Created December 20, 2013 19:55
double rainbow omg
var d=document,b=d.body,e=d.querySelectorAll('*');s=d.createElement('style');j=d.createElement('script');j.src='http://is.gd/rbowjs';s.type='text/css';j.onload=function(){s.appendChild(d.createTextNode(rainb))};b.appendChild(s);b.appendChild(j);for(i in e){e[i].className+=' catchadream'};
@digitalicarus
digitalicarus / replace.js
Created November 4, 2013 17:13
Bookmarklet: replace text in page
(function(){var t=function(r){var n,a=[],w=document.createTreeWalker(r,NodeFilter.SHOW_TEXT,null,false);while(n=w.nextNode()) a.push(n);return a;},i,n=t(document.body); for(i=0;i<n.length;i++) n[i].nodeValue=n[i].nodeValue.replace(/fuck/ig,'Praise');})()
@digitalicarus
digitalicarus / gist:6524508
Created September 11, 2013 14:34
Shell one-liners
-- convert file to base64
openssl base64 -in square.png | tr -d '\n' | pbcopy
@digitalicarus
digitalicarus / flatter.js
Last active December 22, 2015 04:48
flatter
function flatter (obj, match, replaceWhat, replaceWith) {
var replace = (replaceWhat && replaceWhat instanceof RegExp && typeof replaceWith === 'string')
, tmp = null // description - a tmp variable
;
function getJuicyObject (obj) {
var children = {}
, juicyChildren = {}
;
@digitalicarus
digitalicarus / example.js
Last active December 19, 2015 20:19
recursively execute on an organized nested object where sub objects are identified by '__value' member in a 'relationships' array. Also filter, map and persist opts. TODO: make relationships member a generic option as well as the __value member.
doSomethingGood()
.then(function (tree) {
// filter and print members with indentation, par example
return execObj(tree, {
exec: function (obj, opts) {
var attrs = obj.someAttrArray;
if (attrs) {
attrs = attrs.filter(function (item) {
return attr.type.match(/wicked|bitchin/i);
});
@digitalicarus
digitalicarus / gist:5967234
Last active December 19, 2015 14:09
| prettyPrintJSON
curl http://freegeoip.net/json/ | node -e "d='';s=process.stdin;o=process.stdout;j=JSON;s.on('data',function(c){d+=c;});s.on('end',function(){d=j.parse(d); console.log(j.stringify(d,null,30))});"