Skip to content

Instantly share code, notes, and snippets.

Abbey Hawk Sparrow khrome

Block or report user

Report or block khrome

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@khrome
khrome / gist:7d87534748545f576fd2
Last active Sep 6, 2018
__dirname in the browser
View gist:7d87534748545f576fd2
(function(){ //make __dirname, __filename work in the browser
if(window && !window['__dirname']){
var stackTrace = function () {
var lines = (new Error()).stack.split("\n");
// 0 = message, 1 = stackTrace
lines.shift(); lines.shift();
var result = lines.map(function(line){
if(line.indexOf('(native)') != -1){
return {
View Element.optimalWidth.js
Element.implement({
// if called with callback, the element is set to the optimalWidth and called back when ready
// else the optimalWidth is calculated and returned
optimalWidth : function(callback){
var increment = 10;
var fuse = 10; //how many unchanged iterations before we're done?
var originalSize = this.getSize();
var lastForwardChange;
for(var lcv=0; lcv < fuse; lcv++){
var currentSize = this.getSize();
View soup_talker.php
<?php
$soups = array("Avgolemono ", "Borscht ", "Caldo verde ", "Fasolada ",
"Goulash soup", "Islensk Kjotsupa ", "Kimchi jjigae ", "Lentil soup",
"Menudo", "Mulligan Stew", "Philadelphia Pepper Pot ", "Pho",
"Sundubu jjigae ", "Snert ", "Solyanka ", "Tomato soup", "Cold borscht",
"Dashi soup ", "Okroshka", "Sour cherry soup", "Vichyssois", "Ginataan",
"Naengmyeon ", "Fruktsuppe", "Cioppino ", "Fanesca ", "Lan Sikik ",
"Sliced fish soup", "Ukha or Lohikeitto", "Bird's nest soup", "Fuhn",
"Mian", "Ramen", "Saimin", "French onion soup", "Tinola", "Crab bisque",
"Chestnut bisque", "Cream of Crab Soup", "Clam chowder", "Chupe",
@khrome
khrome / load_parse_render.js
Created Dec 19, 2011
Loading an SVG in JS and using raphael to render it, just for fun
View load_parse_render.js
var parser = new SVGParser();
var svgRequest = new Request({
url: 'awesome.svg',
onSuccess: function(responseText, responseXML) {
//once we recieve the SVG, we parse it
parser.parse(responseText);
}
}).send();
@khrome
khrome / font_styles.tex
Created Dec 19, 2011
XeLaTeX section additions
View font_styles.tex
\setsansfont[Mapping=tex-text,Scale=1.1]{Scrawler}
\setmainfont[Mapping=tex-text,Scale=1.0]{Lucida Grande}
\setmonofont{Courier}
@khrome
khrome / draft_watermark.tex
Created Dec 19, 2011
XeLaTeX watermarking environment macro
View draft_watermark.tex
\usepackage{everypage}
\newenvironment{water}{\AddEverypageHook{\waterb}}{
\AddThispageHook{\waterb}\AddEverypageHook{\watere}
}
\makeatletter
\newcommand{\waterb}{
\AddToShipoutPicture*{%
\setlength{\@tempdimb}{.5\paperwidth}%
@khrome
khrome / code_environment.tex
Created Dec 19, 2011
Code environment for XeLaTeX
View code_environment.tex
\definecolor{altlinecolor} {rgb}{0.7,0.7,0.7}
\renewcommand{\FancyVerbFormatLine}[1]{%
\ifodd\value{FancyVerbLine}%
\colorbox{altlinecolor}{
\hspace{-0.04in}\makebox[\textwidth - 16pt][l]{#1}
}\else#1\fi}
\DefineVerbatimEnvironment{CleanCode}{Verbatim}
{
@khrome
khrome / String.whenInDOM.js
Created Dec 19, 2011
String.whenInDOM : call a function on a DOM element from the future
View String.whenInDOM.js
if(!String.whenInDOM){
if(!String.defaultReplacementTimeout)
String.defaultReplacementTimeout = 16384;
String.implement({
whenInDOM : function(
callback,
delayCallback,
timeoutCallback,
timeout,
counter
@khrome
khrome / MooToolsEntityEncoding.js
Created Dec 19, 2011
MooTools Entity Encoding
View MooToolsEntityEncoding.js
if(!String.regexEncode){
String.regexChars = ['\\', '&','^', '$', '*', '+', '?', '.', '(', ')', '|', '{', '}', '[', ']'];
String.regexEncodeRegexObject = new RegExp('([\\'+String.regexChars.join('|\\')+'])', 'g');
String.implement({
regexEncode : function(){
return this.replace(String.regexEncodeRegexObject, '\\$1');
}
});
}
@khrome
khrome / Function.whenTrue.js
Created Dec 19, 2011
Function.whenTrue polling a boolean function with geometric falloff
View Function.whenTrue.js
if(!Function.actionTimeout) Function.actionTimeout = 16384;
if(!Function.whenTrue){
Function.implement({
whenTrue : function(actionFunction, args, delayFunction, timeoutFunction, timeout, counter){
if(!timeout) timeout = Function.actionTimeout;
if(!counter) counter = 0;
if(!timeoutFunction) timeoutFunction = function(event){
throw('Condition not met after '+event.time+'ms');
};
var result = this();
You can’t perform that action at this time.