Skip to content

Instantly share code, notes, and snippets.

@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 = {}
@josher19
josher19 / casual.test.js
Created September 15, 2020 23:49
casual locales pollute default casual namespace ... does not support multiple locales
const assert = require('assert');
const casual = require('casual');
const loc = casual;
const de = casual.de_DE;
const arabic = casual.ar_SY;
const us = casual.en_US;
// address_formats should not be changed by loading a new locale, but they are.
assert.deepStrictEqual(us.address_formats, loc.address_formats);
var recog = new SpeechRecognition();
recog.addEventListener('result', function (event) {
for (var i = event.resultIndex; i < event.results.length; i++) {
if (event.results[i].isFinal) {
console.log(event.results[i][0].transcript);
}
}
});
recog.start();
@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 / 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 / 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 / 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 / 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}}]);
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]