Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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;
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 / brain_zero.js
Created March 22, 2013 02:59
brain does not likes "0"
// Requires: http://cloud.github.com/downloads/harthur/brain/brain-0.6.0.js
// Contrived example using string "0" as output.
var net = new brain.NeuralNetwork();
net.train([{input: [0, 0], output: {"F":1}},
{input: [0, 1], output: {"1":1}},
{input: [1, 0], output: {"1":1}},
{input: [1, 1], output: {"0":1}}]);
@josher19
josher19 / mSpeak.html
Created April 2, 2013 07:41
mSpeak -- Speak using Microsoft Speak API and Google speech input.
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<h1><a href="https://api.microsofttranslator.com/V2/http.svc/Speak?appId=TSzWLRnblSPavH9y7i7I52Hl2qfRvb4Lk2YDo2YtRwZw3n6eWHZuShsUxrHX9VzWV&text=Welcome+to+the+Audio+Site&language=en&format=audio%2fwav" target=_blank>Welcome to the Audio Site</a></h1>
<form method=get action="https://api.microsofttranslator.com/V2/http.svc/Speak" id="speakForm">
<label>App ID: <input name=appId disabled=true value="TSzWLRnblSPavH9y7i7I52Hl2qfRvb4Lk2YDo2YtRwZw3n6eWHZuShsUxrHX9VzWV" /></label> <br/>
@josher19
josher19 / weather.ls
Created April 3, 2013 09:50
Ask questions about the weather using Fuzzy Logic and LiveScript
fuzzylogic = require 'fuzzylogic/lib/fuzzylogic'
temps = {"freezing": [ 'reverseGrade', 0, 5 ], "cold":["triangle", 0,15],"cool":["triangle",10,20],"roomTemp":["triangle",16,26],"warm":["triangle",21,32],"hot":["grade",27,32]}
temps.is = (temp, description, verbose) ->
[fuzfcn,...args] = this[description];
fcn = fuzzylogic[fuzfcn] || fuzzylogic.triangle;
args.unshift(temp);
args=[temp,args[1],(args[1]+args[2])/2,args[2]] if args.length==3 && fcn && fcn.length == 4;
if verbose
@josher19
josher19 / mousetrack.js
Created May 13, 2013 10:28
Track & display mouse movements
jQuery(function($) {
if (!Date.now) Date.now = function() { return new Date().getTime() }; // shim
var prev = {x:0,y:0,time:Date.now(),lastEv:{}}, mover = function (e) {
// send event to server with X and Y
var tdiff = e.timeStamp - prev.time;
if ( (Math.abs(e.pageX - prev.x) + Math.abs(e.pageY - prev.y) > 150) || (tdiff > 1500) ) {
oAJAX.send("send Mouse X & Y, tagName " +
"and Current Date/Time to the millisecond", prev.x=e.pageX, prev.y=e.pageY, prev.time = e.timeStamp || Date.now(), describe(e.target), prev.lastEv=e);
marker.animate({top:prev.y,left:prev.x},'fast');
@josher19
josher19 / README.md
Last active January 3, 2016 20:19
Weather classification module using Fuzzy Logic. Default is Celsius. Ask whether the weather is very or somewhat hot, warm, cool, cold, or freezing.

Weather classification module using Fuzzy Logic. Default is Celsius.

npm install fuzzylogic node

> weather = require('./weather')
> weather("is 30 very hot?")
[0.36, 'maybe', 'hot']  # 36% correct -- maybe 30C is very hot
> weather("is 30 somewhat hot?")
@josher19
josher19 / MACRO.ls
Last active January 9, 2023 21:35
Macros for LiveScript version 0.0.1
global or= this;
safereg$ = (it) -> RegExp " " + it.replace(/([\.\*\?\\])/g, "\\$1") + " ", "g"
MACRO = (op, _options, cmd, cmdName) ~>
MACRO.S or= {}
if typeof _options isnt "object"
cmdName = cmd
cmd = _options
_options = {}