Skip to content

Instantly share code, notes, and snippets.

@ezmiller
ezmiller / wrap_strings.R
Created August 22, 2016 05:54
R function for wrapping long strings
## Function to wrap long strings
# Source: http://stackoverflow.com/a/7367534/496488
wrap_strings <- function(vector_of_strings,width) {
as.character(
sapply(vector_of_strings, FUN=function(x) {
paste(strwrap(x, width=width), collapse="\n")
})
)
}
@ezmiller
ezmiller / stacktrace.js
Created January 19, 2016 16:54
How to log a strack trace anywhere in Javascript
var e = new Error('dummy');
var stack = e.stack.replace(/^[^\(]+?[\n$]/gm, '')
.replace(/^\s+at\s+/gm, '')
.replace(/^Object.<anonymous>\s*\(/gm, '{anonymous}()@')
.split('\n');
console.log(stack);
@ezmiller
ezmiller / gist:3289017
Created August 7, 2012 20:26 — forked from robflaherty/gist:1129904
Stylus conversion of Normalize.css
/*
* Normalize.css converted to Stylus
* http://github.com/necolas/normalize.css
*/
article, aside, details, figcaption, figure, footer, header, hgroup, nav, section
display: block
audio, canvas, video
display: inline-block
@ezmiller
ezmiller / index.html
Created July 25, 2012 01:38 — forked from anonymous/index.html
css3 translate expanding menu
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>CodePen &middot; Pen</title>
<!--
Copyright (c) 2012 Mahroof Ali, http://codepen.io/anon
Permission is hereby granted, free of charge, to any person obtaining
@ezmiller
ezmiller / gist:1a4a364fa167b90ed133
Created June 23, 2015 13:21
A example method for preloading html5 videos in a queue
// Have to use an object so that count can function as a reference
var loadQueue = {
count:0
}
/**
* Preloads videos
*
* If limit has been reached video is not preloaded but an
@ezmiller
ezmiller / parseUrl.js
Created June 11, 2015 14:51
A quick way to parse a url using the DOM
var parseUrl = function(url) {
var parser, urlInfo;
parser = document.createElement('a');
parser.href = url;
urlInfo = {
protocol: parser.protocol,
hostname: parser.hostname,
port: parser.port,
@ezmiller
ezmiller / CustomErrors.js
Created January 21, 2015 20:01
One way to create globally available custom errors as a service in SailsJS
'use strict';
/**
* Indicates an error where an invalid argument or input to a method.
* @param {string} message The error message.
* @param {string} stack The stack trace.
*/
function InvalidArgumentException(message, stack) {
this.name = 'InvalidArgumentException';
this.message = message || 'Invalid Argument';
@ezmiller
ezmiller / gist:acb0d91c8b48984e385a
Created October 5, 2014 09:49
bash script command line code to watch a stylus file for change and then compile on change
while true; do
change=$(inotifywait -e close_write,moved_to,create .);
change=${change#./ * };
if [ "$change" = "style.styl" ]; then
echo $(date); stylus style.styl -o ../..;
fi;
done