Hello, here are some random bits and pieces

^ Contents [automatic]

Home
Contents [automatic] (#auto_id_0)
Javascript Projects (#js)
Web Design (#auto_id_2)
Sliding left-right (#auto_id_3)
Pie Chart +example heading item (#auto_id_4)
Overlay Progress Effect +example heading item with it's own id (#testEG2)
Math(working) (#auto_id_6)
Border collapse (#auto_id_7)
Progress Bars (#auto_id_8)
fake link (#auto_id_9)
.js GET request (#auto_id_10)
Hammer & wrench (#toolsAsText)
unit tests (#auto_id_12)
Chart.js (#auto_id_13)
stacking (#auto_id_14)
table (#auto_id_15)
set cascade generator (v3) (#auto_id_16)
slowMult (#slowMult)
mutate (#auto_id_18)
fake yield (#auto_id_19)
FizzBuzz (#auto_id_20)
Symbols to words tricks (#auto_id_21)
Standardized DateTime formatting (#auto_id_22)
Events (#auto_id_23)
messagebox (#auto_id_24)

^ Javascript Projects

(this page - auto generated contents and links from header elements)
Spoilers
Noughts & Crosses (Tic-Tac-Toe)
Graph eg (WoT guns)
Pie Chart eg
Sorting speed curiosity
merge-sorting
quicksort
Rolling demo
Rolling example - Web Typography (Web Book)
Map Reduce (Web Book)
css compiling + applied example
Horizontal scrolling
Gradients on 'borders' and text
datePicker
highlighter
piegress
b�zier curve & cascading html creation
mandelbrot rendering
Math.pow optimising
js file editing/saving
similarity detail
util
util tests

^ Web Design

Resources

Regular Expressions
jQuery plugins : alerts, checkbox, uploader, datepicker, dropdown, etc

All sensible stuff is above this line ... below is a mishmash of bits and pieces


- Only misc testing stuff from here on in ... -

^ Sliding left-right

hello there, said bob
see also v3 - final version and v1 - a preliminary attempt and v2

^ Pie Chart +example heading item

Key

^ Overlay Progress Effect +example heading item with it's own id

^ Math(working)

k=1 vs \(k=1\)
When \(a \ne 0\), there are two solutions to \(ax^2 + bx + c = 0\) and they are \(x = {-b \pm \sqrt{b^2-4ac} \over 2a}.\)
also : \(\left( \sum_{k=1}^n a_k b_k \right)^2 \leq \left( \sum_{k=1}^n a_k^2 \right) \left( \sum_{k=1}^n b_k^2 \right)\)
more : \(\mathbf{V}_1 \times \mathbf{V}_2 = \begin{vmatrix} \mathbf{i} & \mathbf{j} & \mathbf{k} \\ \frac{\partial X}{\partial u} & \frac{\partial Y}{\partial u} & 0 \\ \frac{\partial X}{\partial v} & \frac{\partial Y}{\partial v} & 0 \end{vmatrix}\)

^ Border collapse

hiya some stuffand then?
ah, tables only :-/ hacked -ve margin above

^ Progress Bars

100%
95%
50%
20%
10%
5%
0%
0%

^ fake link

link

^ .js GET request

Hammer & wrench

^ Hammer & wrench

Hammer + wrenCh
more like pliers, unfortunately :
wrenCh

^ unit tests

testAppend : passed (result : 4)
testPrepend : failed (error : TypeError: Cannot set properties of undefined (setting 'c'))
testYield : failed (error : ReferenceError: yield is not defined)
yieldMaker : passed (result : true)
yieldMaker_ExternalEffects : failed (error : global_count==3 expected 2)
testAdd : passed (result : 1 + 2 = 3)
testThrow : passed (result : true)
testStringGenerics : failed (error : TypeError: String.replace is not a function)
testString : passed (result : string-value)
testSet : passed (result : {"item":"cosy-cat","colour":"tabby","sound":"purrrr","legs":4,"age":3.5,"state":"cosy"})

^ Chart.js

^ stacking

Error().stack : Error at https://imma.neocities.org/misc:533:38
function getStack() { return Error().stack.replace(/^(.|\n)*at getStack(.|\n)*?at /, "") }
function bob() { return jim(); }
function jim() { return getStack()}
bob() produces :
jim (https://imma.neocities.org/misc:532:26)
at bob (https://imma.neocities.org/misc:531:26)
at https://imma.neocities.org/misc:537:46

^ table

Today's Opinion Poll QuestionPolitical Party
DemocratRepublicalIndependant
"Do you favour or
oppose increasing
the minimum wage?"
Favour70%35%55%
Oppose25%60%30%
Unsure5%5%15%

^ set cascade generator (v3)

function set(o,v){for(var n in v) o[n]=v[n];return o}
(v1 was function set(o,s){s=function(a,v){o[a]=v;return s};s.o=o;return s} eg: set(acat)('sound','purrrr')('legs',4) )
(v2 was function set(o){return function s(a,v){o[a]=v;return s}} eg: set(acat)('sound','purrrr')('legs',4) )
init: acat = {"item":"cat","colour":"tabby"}
set(acat, { sound:'purrrr', legs:4, age:3.5, item:'cosy-cat', state:'cosy', purr:function(){alert('purr!!!');} });
acat: {"item":"cosy-cat","colour":"tabby","sound":"purrrr","legs":4,"age":3.5,"state":"cosy"}
acat.purr: function(){alert('purr!!!');}
acat.state = "cosy"

^ slowMult

slowadd(901003, 572389) = 1473392

slowmult('1000002000000003','90005720003892') = 90005900015332277801160011676

slowmult('12345','1000002000005000000400000300000200001') = 12345024690061725004938003703502469012345

slowmult('1000002000005000000400000300000200001','1000002000005000000400000300000200001') (correct value) :
= 1000004000014000020800027200005600005960006240010250000920000640000400001

1000002000005000000400000300000200001 x 1000002000005000000400000300000200001 (built in multiplication causes quite a big rounding error) :
= 1.000004000014e+72
= 1.000004000014e+72

^ mutate

pre, a=1,2,3
post, a=1,3,6

^ fake yield

yieldMaker : function yieldMaker(f) { var code = (f+"").replace("{","{var yield_iteration_match=1;yield_iteration++;") .replace(/yield\s*\(/g,"if(yield_iteration_match++==yield_iteration)return("); f = eval("(function(){var yield_iteration=0; f="+code+";f.reset=function(){yield_iteration=0};return f;})")(); /*f = function(){ var yield_iteration=0; return eval(code); }(); f.reset=function(){yield_iteration=0}; */ return f; }
arr=1,2,sally,bob,43,1
arr.item = yieldMaker(function(){ for(var n in this) if(n != "item") yield(this[n]); })
arr.item==function(){var yield_iteration_match=1;yield_iteration++; for(var n in this) if(n != "item") if(yield_iteration_match++==yield_iteration)return(this[n]); }
arr.item()=1
arr.item()=2
arr.item()=sally
arr.item()=bob
arr.item()=43
arr.item()=1
arr.item()=function(mutate, thisArg) { var a = this, l = a.length, n = 0, p = 0; for(;narr.item()=undefined
and slowly ...
arr.item()=1
arr.item()=2

^ FizzBuzz

1, 2, Buzz, 4, Fizz, Buzz, 7, 8, Buzz, Fizz, 11, Buzz, 13, 14, FizzBuzz, 16, 17, Buzz, 19, Fizz, Buzz, 22, 23, Buzz, Fizz, 26, Buzz, 28, 29, FizzBuzz, 31, 32, Buzz, 34, Fizz, Buzz, 37, 38, Buzz, Fizz, 41, Buzz, 43, 44, FizzBuzz, 46, 47, Buzz, 49, Fizz, Buzz, 52, 53, Buzz, Fizz, 56, Buzz, 58, 59, FizzBuzz, 61, 62, Buzz, 64, Fizz, Buzz, 67, 68, Buzz, Fizz, 71, Buzz, 73, 74, FizzBuzz, 76, 77, Buzz, 79, Fizz, Buzz, 82, 83, Buzz, Fizz, 86, Buzz, 88, 89, FizzBuzz, 91, 92, Buzz, 94, Fizz, Buzz, 97, 98, Buzz, Fizz

^ Symbols to words tricks

var s = ([]+![])[+!+[]+!+[]+!+[]][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+![])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]]+([]+!![])[+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+!![])[+!+[]]][([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+![])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]]+([]+!![])[+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]]+([]+!![])[+!+[]]](([]+!![])[+!+[]]+([]+[][+[]])[+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+!![])[+!+[]+!+[]]+([]+!![])[+!+[]]+([]+[][+!+[]])[+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+([]+{})[+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]]+(+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[]+!+[])[([]+{})[+!+[]+!+[]+!+[]+!+[]+...
s ... = Strange thing

^ Standardized DateTime formatting

var id = function(){
  var id=0;
  function getNextId() { return id++; };
  return function(){ return getNextId(); }; }();

optimised from :
get_time = function() {
	var date_part, local_time, now, time_part;
	local_time = new Date();
	now = new Date(local_time.getTime() + (local_time.getTimezoneOffset() * 60000));
	date_part = "" + (this.zero_pad(now.getFullYear(), 2)) + "-" + (this.zero_pad(now.getMonth() + 1, 2)) + "-" + (this.zero_pad(now.getDate(), 2));
	time_part = "" + (this.zero_pad(now.getHours(), 2)) + ":" + (this.zero_pad(now.getMinutes(), 2)) + ":" + (this.zero_pad(now.getSeconds(), 2));
	return "" + date_part + " " + time_part; };
zero_pad = function(number, length) {
	var str;
	str = "" + number;
	while (str.length < length) str = "0" + str;
	return str; };

to :
Date.prototype.ymd = function getYMD() {
	function p2(s) { return ("0" + s).slice(-2) }
	function p4(s) { return ("000" + s).slice(-4) }
	return [p4(this.getFullYear()), p2(this.getMonth()+1), p2(this.getDate())].join("-") + 
		" " + 
		[p2(this.getHours()),p2(this.getMinutes()),p2(this.getSeconds())].join(":"); };

to :
Date.prototype.ymd = function getYMD(d) {
	var d = d || this;
	function p2(s) { return ("0"+s).slice(-2) }
	return [d.getFullYear(),p2(d.getMonth()+1),p2(d.getDate())].join("-") +
		" "+[p2(d.getHours()),p2(d.getMinutes()),p2(d.getSeconds())].join(":") };
compacted:
Date.prototype.ymd=function ymd(d){d=d||this;function p(s){return("0"+s).slice(-2)}
	return[d.getFullYear(),p(d.getMonth()+1),p(d.getDate())].join("-")+" "+
	[d.getHours(),d.getMinutes(),d.getSeconds()].map(p).join(":")};
most efficient, but less fun:
Date.prototype.ymd=function ymd(d){d=d||this;function p(s){return('0'+s).slice(-2)}
	return d.getFullYear()+'-'+p(d.getMonth()+1)+'-'+p(d.getDate())+' '+
	p(d.getHours())+':'+p(d.getMinutes())+':'+p(d.getSeconds())};
customPI
customPI('0.7239898304019381test')
customPI2
customPI2('0.7239898304019381test')

^ Events


compact:
function evnt(s,i){s=[];return{sub:function(h){s.push(h)},go:function(p){for(i=s.length;i--;)s[i](p)}}}

simple:
function newSimpleEvent() { return {/*
		simple public event pattern
		unsubscribe must be done manually,
		subscribers list is visible(pro/con?) */
	subscribers: [],
	subscribe: function (handler) { this.subscribers.push(handler) },
	fire: function newEvent_Fire() { for (var h = this.subscribers.length; h--;) this.subscribers[h].apply(this, arguments) } } }

full:
function newEvent(name, arguments) {/*
		event pattern 
			with private subscribers,
			unsubscribing, 
			bound 'fire' & 'subscribe' functions (can be localised and still connect),
			optional logging with default built-in logger */
		var subscribers = [],
			event = {
				name: name || "unnamed event - " + Date(),
				arguments: arguments || "unknown",
				subscribe: newEvent_Subscribe,
				fire: newEvent_Fire,
				unsubscribe: newEvent_Unsubscribe };
		if (log) log("created event '" + name + "' (" + arguments + "), " + log);
		return event;
		
		function newEvent_Subscribe (handler) {
			if (log) log("added subscriber to event '" + event.name + "' : " + handler);
			subscribers.push(handler); }
		function newEvent_Fire () {
			if (log) log("firing event '" + event.name + "' (" + JSON.stringify([].slice.call(arguments)).slice(1,-1) + ")");
			for (var h = subscribers.length; h--;) subscribers[h].apply(event, arguments); }
		function newEvent_Unsubscribe (handler) {
			if (log) log("removing subscriber to " + event.name + " : " + handler);
			subscribers.splice(subscribers.indexOf(handler), 1); } }

egs:
{"events":{},"state":"not connected","server":"none"}
{"newEmail":{"name":"email arrived","arguments":"email object"},"connected":{"name":"connected to server","arguments":"server ip"},"disconnected":{"name":"disconnected from server","arguments":"server ip"},"state":"not connected","server":"none"}

^ messagebox

Are you sure you want to answer this question?
cancel yes, Yes i do