Skip to content

Instantly share code, notes, and snippets.

outp=(inp="<html>Documentation Permission is hereby granted, free of charge, to any person obtaining a copy of this Software and associated Documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:</html> {:ABC:} , 123456.").replace(/([^A-Za-z0-9 ]+)/g, " {:$1:} ").replace(/([A-Z]+)/g," {:$1:} ").split(" ").map(function (it,n) { return it.length > 10 ? it.substring(0,10) + " {::} " + it.substring(10) : parseInt(it, 36) || it}) .join(" ").split(" ") .map(function(it,n) { return it.match(/^\d/) ? (+it).toString(36) : it }).join(" ").replace(/ \{\:([^a-z ]*)\:} /g, function(all,m) { return m.toUpperCase() }); [outp, inp == outp]
@josher19
josher19 / gist:4983413
Created February 19, 2013 05:48
webcheck.ls LiveScript code (easily converted to CoffeeScript) to check the title of a website and notify if the site is down. Requires: growl (npm install growl).
#!/media/DATA/Mobile/git/josher19/LiveScript/bin/livescript
request = require 'request'
fs = require 'fs'
growl = require('growl')
docheck = (url, expectedTitle, cb = barf) ->
return (err, req, body) ->
try
return cb(err) if err;
@josher19
josher19 / rss_reader.js
Created February 19, 2013 04:18
RSS / Atom Feed Reader in Javascript
(function() {
var pre, div, txt, desc, here = 0;
function startup() {
pre = document.body.querySelector('pre');
txt = pre.innerText;
document.body.appendChild(div=document.createElement('div'));
div.innerHTML = txt;
div.style.display="none";
@josher19
josher19 / jQueryRx.js
Created December 3, 2012 07:59
Plugin to allow use of RxJS in jQuery
jQuery.fn.toObservable = jQuery.fn.toObservable || function (eventName, action) {
var dom = this;
return Rx.Observable.create(function(observer) {
var handler = function(ev) {
if (action !== undefined) {
action(ev);
}
else {
if (ev && ev.preventDefault) {
ev.preventDefault();
@josher19
josher19 / i18n-jqueryui-dialogtitle.js
Created November 30, 2012 10:11 — forked from jlgrall/i18n-jqueryui-dialogtitle.js
i18next: Adds support for data-i18n and data-i18n-options to jQuery UI Dialog's title
// Adds support for data-i18n and data-i18n-options to jQuery UI Dialog's title:
if( $.fn.dialog ) { // Checks the presence of the dialog component of jQuery UI
var rTitleKey = /\[title\]([^;]*);?/,
// Keep a reference to the original _create function:
dialog_create_orig = $.ui.dialog.prototype._create;
$.ui.dialog.prototype._create = function( ) {
var data_i18n,
i18n_options;
if(!this.options.title) { // Because as defined in Dialog, the options.title should override the title attribute
var old_data_i18n = this.element.attr( "data-i18n" );
@josher19
josher19 / minidoc.js
Created November 29, 2012 08:30
document code using title attributes
/** Give documentation (via mouseover) in title attributes for functions in code highlighted with rainbowco.de */
function minidoc(docs,funcs) {
funcs = funcs || document.querySelectorAll('code span.function') // Could also do 'code span.method'
for(var i=0, len=funcs.length; i<len; ++i) {
var t = docs[funcs[i].textContent];
if (t) funcs[i].title = t;
}
}
@josher19
josher19 / tangled.html
Created November 9, 2012 10:27
Using Tangle for changing values
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<base href="http://worrydream.com/Tangle/" target="_top" />
<title>Tangle: Getting Started</title>
<link href='http://fonts.googleapis.com/css?family=Lato' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="Fonts/Insolent/stylesheet.css" type="text/css">
<link rel="stylesheet" href="Fonts/BorisBlackBloxx/stylesheet.css" type="text/css">
@josher19
josher19 / raytracer.js
Created November 9, 2012 10:26
Raytrace in Canvas. Next up: animating it (takes over 1 second to render, though).
var Vector = (function () {
function Vector(x, y, z) {
this.x = x;
this.y = y;
this.z = z;
}
Vector.times = function times(k, v) {
return new Vector(k * v.x, k * v.y, k * v.z);
@josher19
josher19 / surreal.js
Created November 5, 2012 10:36
Surreal Numbers (Conway)
// Surreal Number generation. Not exactly like Conway's version.
// 4 is [4]|[4] rather than [3]|[]
// so average of leftmost(left) and rightmost(right) is the value of the number
//
// Optimized for usage in Javascript and Node.
// TODO: Create Surreal class and github project.
function surreal_init(e) {
var left = [Math.floor(e)];
var right = [Math.ceil(e)];
@josher19
josher19 / randomFrom.js
Created October 26, 2012 10:33
Semi-random number
function randomFrom(s0) {
return (1103515245 * s0 + 12345) % Math.pow(2,32);
}