This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // dan's naive css formatter for editors | |
| // reliably parses and formats css using browser's CSS engine: | |
| // sorts properties in rules, removes property repeats (and fallbacks), removes vendor-specific syntax, and removes comments. | |
| // punctuationReplacements are executed while quoted strings are removed, making rule content predictable | |
| //////////////////// | |
| // DOES NOT SUPPORT NESTED RULES - MAINLY TO FORMAT SNIPPETS IN A TEXT EDITOR - NOT PRODUCTION MACHINERY!!!! | |
| //////////////////// |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // a function wrap that lets you put functions as event handlers in template strings, allowing closure w/ event code | |
| // returns an html event=uid into the string template, then soon later swaps for the actual passed function | |
| function on(string) { // tag template function to bind local variables in templated html | |
| let values = [...arguments].slice(1); | |
| values = values.map(function(expression) { | |
| if(typeof expression != "function") return expression; | |
| let id = "on_" + Math.random().toString(36).slice(-6), | |
| evtName = expression.toString().split("=")[0].trim(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //a function wrap that lets you put functions as event handlers in template strings, allowing closure w/ event code | |
| // returns an html event dec = uid into the string template, then soon later swaps for the actual passed function | |
| (function(){ // non-global scope | |
| function someLocal(){ alert(123); } | |
| function on(evtName, f){ | |
| var id = Math.random().toString(36).slice(-6); | |
| setTimeout(x=>{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function toSource(o){ // quick and dirty object literals w/ methods. good for refactoring. | |
| var old = Function.prototype.toJSON; | |
| Function.prototype.toJSON = function () { | |
| return "#>"+this.toString()+"<#"; | |
| }; | |
| var s = JSON.stringify(o, null, "\t"); | |
| s=s.replace(/"#>([\w\W]+?)<#"/g, (a,b)=>eval('"'+b+'"')); | |
| Function.prototype.toJSON = old; | |
| return s; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function tokenize(s) { // OPS TERMS | |
| return s.match(/([+*\-\/])|([\d\.]+)/g).map(function Token(t, i) { | |
| return { | |
| token: t, | |
| type: isFinite(t) ? "num" : "op", | |
| index: i, | |
| value: isFinite(t) ? +t : "-+*\/".indexOf(t), // data value/op priority | |
| }; | |
| }); | |
| }//end tokenize() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| "☺☻♥♦♣♠•◘○◙♂♀♪♫☼►◄↕‼¶§▬↨↑↓→←∟↔▲▼ !\"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{|}~⌂ÇüéâäàåçêëèïîìÄÅÉæÆôöòûùÿÖÜ¢£¥₧ƒáíóúñѪº¿⌐¬½¼¡«»░▒▓│┤╡╢╖╕╣║╗╝╜╛┐└┴┬├─┼╞╟╚╔╩╦╠═╬╧╨╤╥╙╘╒╓╫╪┘┌█▄▌▐▀αßΓπΣσµτΦΘΩδ∞φε∩≡±≥≤⌠⌡÷≈°∙·√ⁿ²■" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // ccby@dandavis | |
| function ImmutableArray(){ | |
| function odp(k,v){ Object.defineProperty(r,k,{value:v}); } | |
| let r = [...arguments]; | |
| if(r.length===1 && Array.isArray(r[0])) r = r[0]; | |
| odp("push", function(){return ImmutableArray(r.concat(...arguments));}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function odp(obj, get, set, isHidden){ | |
| Object.defineProperty(obj, /^\w+/.exec(get), {get, set, enumerable: !isHidden}); | |
| return odp.bind(this, obj); | |
| } | |
| // example usage in a class | |
| class Ohm { | |
| constructor(V, I){ | |
| odp(this, _=>Ohm) | |
| ( v=>V, _=>V=_ ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function Ohm(v, i, _){ | |
| (_=(k, get, set) => Object.defineProperty(this, k, {get, set, enumerable: 1}) && _) | |
| ("v", _=>v, x=>v=x) | |
| ("i", _=>i, x=>i=x) | |
| ("w", _=>v*i, x=>i=x/v) | |
| ("r", _=>v/i, x=>i=v/x); | |
| } | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| * A JavaScript implementation of the Secure Hash Algorithm, SHA-1, as defined | |
| * in FIPS 180-1 | |
| * Version 2.2 Copyright Paul Johnston 2000 - 2009. | |
| * Other contributors: Greg Holt, Andrew Kepert, Ydnar, Lostinet | |
| * Distributed under the BSD License | |
| * See http://pajhome.org.uk/crypt/md5 for details. | |
| */ | |
| // smooooshed by dandavis 2024. tested in jscript5.5 |
NewerOlder