« first day (126 days earlier)      last day (4825 days later) » 

user1385191
7:04 PM
ugh the questions in the flash section are so terrible
 
can someone rip my code to shreds please?
 
user1385191
post it
 
preferrably not @Raynos I don't feel like killing myself today :P
 
0
Q: String interpolation library Review

Ivo WetzelSo I was bored over the last couple of days and wrote up a string interpolation library for JavaScript. I'm very pleased with its functionality, it passes it 67 tests cross browser and the comments and README seem fine too. My main concern here are the regular expressions, I'm not a real pro in...

 
7:06 PM
@MylesGray I'm not that mean!
 
Well, your not exactly a tellitubby either :P
 
user1385191
are you building this like a snippet or like an application?
 
imagines Raynos in a tellitubby costume
ahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
 
Well, im prototyping my functions in JS then Ill build it into an android widget
 
@MylesGray Do your own debugging! It's not even working
 
user1385191
7:10 PM
first off, your js is obtrusive
 
@Raynos It is now ;)
 
Hmm I don't like these red eyes, changing my Gravatar.
 
foo.length() :D
 
@Raynos length()?
 
7:12 PM
@MylesGray clicking the print button adds to the array :D
 
@Raynos prints out Invalid date twice if it's invalid
 
@Raynos are you sure you're on the new version? I fixed the length() error
 
@MylesGray you forgot to empty the element when you print
 
@Raynos Right you are :)
 
@IvoWetzel not enough underscore.js Why define extend when you can _.extend instead :)
 
7:15 PM
haha
sure!
I'll include underscore just for that :P
 
:D
Awesome
 
And just to make sure it works
 
Why do you "use strict" ?
 
I'll throw in Prototype, Mootools and jQuery
@Raynos Because it's supported by FX4?
 
@IvoWetzel dont forget ExtJS & backbone
 
7:16 PM
And allows for further optimizations
oh yeah, the whole ExtJS
 
I just expect IE9 will implement "use strict" and do it completely wrong and all your code will break over night
 
"Only 5mb in size!*" *when gzipped
because IE9 will change :P
 
I rememebr seeing a post recently where a guy had a 200MB GZipped script
 
@IvoWetzel seriously though When other browsers implement use strict over night your codes going to break!
On second though
I think that comment isn't any good there
 
what is use strict? like a stricter JS syntax?
 
7:21 PM
Kind of
Read the ES5 spec
Ill go back to writing code now :P
 
I like strict syntaxes :D
 
jsHInt is one epic fail
 
I only just realised I ahvnt eaten for 24 hours :D
Thats why Im hungry
 
@IvoWetzel srs?
Man that looks silly
 
7:23 PM
As of now the things is completely useless
JSLint throws less warnings and errors...
 
Its ok
It also doesn't post back the data. Which is really useful so I can dump "confidential" code into it because it doesnt go to some server
 
@IvoWetzel would there be a reason why a carriage return wouldn't work? im just using it like this: "text blah blah\n"?
 
@MylesGray try \\n
 
Nahh that just escapes the backslash and prints the \n
 
:D That's not what you wanted?
use a carriage return "\r\n"
 
7:33 PM
hmm.. still doesn't work
had to use <br/>
 
\n won't work in HTML.
 
@IvoWetzel most of those issues where created recently. From which news site did you read about it? I presume someone blogged it?
 
function nl2br(string, is_xhtml) {
	if (is_xhtml == null) is_xhtml = true;
	return text.replace(/\r\n|\r|\n/g, (is_xhtml) ? '<br />' : '<br>'));
}
 
@Nyuszika7H Wouldn't you want to check for undefined instead of null?
 
@sdleihssirhc == null will check for both undefined and null.
 
7:42 PM
@IvoWetzel Is it possible to use split to delimit a string separated by commas?
 
@Nyuszika7H Right, right. I'm so used to === that I keep forgetting == is even an option.
 
@sdleihssirhc And the bang (!) operator isn't OK there, because then even if the user sets it to false, it will be true.
 
user1385191
of course you can split commas
 
user1385191
that's how it's meant to be used
 
0
A: Is defining every variable at the top always the best approach?

RaynosThis is a style question. Not a functionality question. The javascript parser will take this code function() { dostuff(); var i = 4; } and turn it into : function() { var i; dostuff(); i = 4; } As for the style question. No thank you I thought we left that behind with ANSI C.

The parser does do that right?
I always assumed it does
 
7:45 PM
@Raynos yep it does
 
@Nyuszika7H Right. Pretty tricky.
 
@Nyuszika7H check for undefined not null. Why the hell would you call the function with nl2br("foo", null)
 
@Raynos !!!!
3 mins ago, by Nyuszika7H
@sdleihssirhc == null will check for both undefined and null.
 
I'm saying that you don't need to check for null.
 
@Raynos You completely misunderstood it.
 
7:46 PM
Because if someone passes in null you point them at the API and tell him he's an idiot
use === undefined
 
> nl2br('hello\nworld');
"hello<br />world"
> nl2br('hello\nworld', true);
"hello<br />world"
> nl2br('hello\nworld', false);
"hello<br>world>"
 
@MattMcDonald so how would I push the elements singularly to the array?
I have this: var array = string.split(','); (found on SO)
 
user1385191
.split is an array
 
user1385191
so you just iterate through it
 
@sdleihssirhc don't use == there is barely no use case for it.
 
7:47 PM
so do i need to iterate through the array?
oh okay cool thought so :)
 
user1385191
remember, .split is string to array, .join is array to string
 
@Raynos Except for tripping up Crockford fanbois.
 
function nl2br(string, is_xhtml) {
	return text.replace(/\r\n|\r|\n/g, (is_xhtml === false) ? '<br>' : '<br />'));
}
Fixed it.
 
@Raynos almost
 
@Raynos false not alse
 
7:48 PM
(is_xhtml === false)
 
user1385191
it's good to get into a habit of figuring out what datatype a function returns
 
my f key is acting up
 
too much swearing and flaming ;)
 
@MylesGray Then it's a good thing the "f" key is acting up, or else it would be even worse.
 
So sdleihssirhc is Chris Sheilds backwards? :D
 
7:51 PM
Almost.
Chris Shields.
 
Shields
;)
 
I'm hiding from dyslexic hitmen.
 
just watching Bear Grylls giving himself an enema on TV
 
More spam…
From alert@notification.messagelabs.com to MemberInfo-ctg.
Your email address needs verification for your Security.



Your account will not be interrupted after following the instructions and your service will continue as normal. We apologize for any inconveniences.

Thanks for using Google.
 
@MattMcDonald I share your 'this' confusion
trying to do this.value=""
doesn't work :/
 
user1385191
7:59 PM
the problem is this is so ambiguous and can break so often
 
Do you know what this is? :d
@MylesGray only when using .bind in jQuery can you garantuee this is the element for the event handler. It doesn't work without jQuery
 
@Raynos yep - I am running it within the input element inside an onfocus
 
Thats raw DOM not jQuery :) jQuery goes behind your back and makes sure that this is the element in your onfocus function
 
ohh okay :/
 
use event.target
 
user1385191
8:00 PM
note event.target is event.srcElement in IE
 
function eventHandler(event) {
     var event = event || window.event;
     var el = event.target || event.srcElement;
}
Starting to see why we use jQuery? (Because IE Sucks)
 
@Raynos i want to learn production JS - I benefit more in other platforms if i learn real language constructs
 
user1385191
there's nothing wrong with that
 
user1385191
the point is IE has their own version of JS (jscript) and it causes a lot of problems
 
user1385191
I'd suggest you bookmark quirksmode.org
 
8:03 PM
@MattMcDonald I thought JScript was EXACTLY the same as JS?
Here's my new version: it's all nice :)
 
user1385191
well IE expects different properties in certain cases
 
@MylesGray that was a joke right? JScript & JavaScript are miles apart
 
By all means use the DOM natively :) It's a good thing. Whilst your at it
 
18
Q: What's the difference between JavaScript and JScript?

Brian GI have always wondered what the heck is the difference between JScript and JavaScript.

 
8:06 PM
Ugh that website lacks hash bangs for redirection to sub parts of it
 
@Raynos Im just saying what I read in the Definitive JS Guide
 
They are pretty close @MylesGray you on difference is you have access to activeX stuff via jscript
 
@MylesGray Admittedly what your learning is a good thing. I'm just saying its painful :) You will find there are a lot of diferences between the IE and mozilla DOM
 
@Raynos Well learning doesn't have to be fun, but if I learn the hard way first time, I'll have no problems with the easy stuff :)
 
@MylesGray go learn C++ first :P
 
8:09 PM
@Raynos pass :P
 
If you can understand C, C++ Objects, C++ templates & stl and then use all 4 of them together in an effective and elegant manner then everything else is trivial
 
It's that bad? :P
 
It'd take me about 2 years to write effective & elegant C++
 
@Raynos That's a long time for one program.
 
If you can do C++ you can do anything.
 
8:11 PM
Maybe you're TOO strict.
 
@sdleihssirhc the rest of the code I write in that 2 years is just hacked C++
 
user1385191
quick question, what are the pitfalls of using setTimeout(callback, 1) as opposed to setTimeout(callback, 20)?
 
That it runs in 1 ms instead of 20 :D
@MattMcDonald If you recursively do that with a timeout of 1ms your going to block the UI. So if you throw yourself into a recurisve calling loop by accident you pretty much freeze the browser
 
@Raynos I don't think that's true.
 
@sdleihssirhc you write elegant C++ ?
 
8:12 PM
I thought setTimeout wouldn't freeze the browser.
Ha!
 
Oh that
lets try it
I guess it doesnt
 
setInterval(function() {}, 1) – it doesn't freeze the browser.
 
I also thought most browsers actually put a minimum of, like, 10-15ms between each setTimeout thing.
Even if nothing else is going on.
 
I thought JS actaully froze the browse
I guess its not noticeable
 
user1385191
coming from an as3 background, it's been recommended I use 20 as the min value for timers
 
8:14 PM
@MattMcDonald using 0 is fine
setInterval(f, 0) is different though
setTimeout(f, 0) is safe even if it just throws it into an infinite set timeout loop
setInterval slows the browser down a bit
 
setTimeout(f, 0) is just like f().
 
user1385191
yep, I've had problems with setInterval
 
user1385191
I use recursive setTimeouts instead
 
var f = function() {
     console.log("called");
     setTimeout(f, 0);
}
f();
//setInterval(f,0);
 
@MattMcDonald you have had?
 
8:16 PM
try it here. Only setInterval lags the browser
only tested chrome
IE might just crash and burn
 
@Raynos Shouldn't that cause a Stack Overflow exception?
 
@Nyuszika7H nope. Its not recursion. The function ends. The stack gets destroyed, the function gets called asynchronously and starts a new stack
synchronous recursion keeps the stack
Async code destroys the stack
 
nice :)
 
Damn my comma separation is broken :(
if i add a space after the comma it breaks
 
8:18 PM
@MattMcDonald I didnt look at CPU usage :P yes itll throttle the hell out of your CPU
setTimeout 0 throws my CPU2 to 97%
 
setTimeout 20 doesn't throttle the CPU
 
user1385191
cross-browser animating function I started today
 
setInterval(f,0); throttles both my CPUS to 100%
setInterval is multi-threaded. I'm impressed it steals resources from both my cpus.
Someone try it with a quadcore
 
What was @IvoWetzel saying about catching if indexof = -1?
@Raynos If you link me I can try it on an 8 core
 
8:21 PM
is leaving for a hour
 
@MylesGray no clue.
 
user1385191
indexOf will return -1 if it doesn't find anything
 
user1385191
so adding logic for it avoids things breaking
 
@MylesGray Thank goodness for modern technology. Now we can try to use 100% of 8 different cpus with setInterval(f, 0)!
 
@sdleihssirhc - I have a 12 core sitting here too if you really want to ;)
 
8:22 PM
 
@MylesGray YES
 
@MylesGray why do you have a 8 and 12 core?
actually setInterval(f,0) does nothing bad
 
@Raynos Because he's Batman.
 
var f = function() {
     setTimeout(f, 0); // This is the problem
}
setInterval(f, 0);
That exponentially increases the amount of f's to be called :)
 
@Raynos Max 4 cpus's
 
8:24 PM
@MylesGray run it in chrome :D. its because you've got two quadcores in your machine
 
I am running it in chrome
:)
 
It only taps into one of your quadcores.
 
I dont man
 
I.e. the threading is dealt with by your quadcore CPU.
 
its a single CPU
 
8:25 PM
A single CPU with 8 cores?
Link.
 
its a quadcore hyperthreaded - the OS sees it as 8 physical cores
I also Have a 6-core which with hyper threading is 12 cores
 
Oh that's cheating
You've got an i7 and you need a new netbook, or a new gadget thingy
Where do you get the cash to get so much gear. Bet you rob!
 
@Raynos Not cheating - I just love hardware
I spend all the money I earn on software and tech :P
I work a 9-5 during the summer and as a web dev during uni time
 
Anyone have a good guide on backbone.js ?
 
@Raynos This is my computer atm: mutant-tractor.com/2010/08/31/…
made it onto the a russian tech news site for it :D
 
8:32 PM
Guess i'll just read the source.
 
How would I check if indexOf = -1?
tagArray.indexOf((document.getElementById('removeFromArray').value))
 
@MylesGray You could check for tagArray.indexOf(...) + 1
If falsy, then it was -1
Else it's good
 
check === -1
 
@sdleihssirhc Sorry I don't follow
 
array.indexof(someElement) !== -1; // in array!
 
8:42 PM
@Raynos Ah okay I see thank you :)
 
Have you guys seen the backbone.js documentation. This guys a genious!
it has a little play button that runs the snippet of code and then hoists the stuff you care about to global scope so you can inspect in your console
Thats a great way of seeing what a piece of code does.
 
user1385191
awesome, basic OOP structure
 
Thats pretty cool :)
 
user1385191
though the MVC part I don't like so much
 
@MattMcDonald whats wrong with MVC? I'm thinking of building an entire framework on top of backbone MVC
 
user1385191
8:46 PM
I've been working with design patterns lately and MVC is my least favorite because I haven't been able to figure it out so it's readable in my head
 
What do you prefer?
 
"MVC is my least favourite because I don't understand it"
It's a lot better then forms :)
 
Well that solved deleting the last elemetn in the array issue
 
@MattMcDonald do you know how games are written, MVC is very similar
 
but I still cant remove the leading and preceeding spaces >.>
 
user1385191
8:48 PM
games as in AAA games?
 
Games as in have you ever written a game? Know how a gameloop consists of read input, update State, render screen
 
user1385191
I've written partial games
 
user1385191
working on a flixel one right now
 
In MVC, the model is your state, the view is your screen to render. The Model and View are coupled such that you don't have to call render to your screen you just have to change the model and the model will trigger an event that the view binds to and then the view re renders itself.
The controller is basically the input your read from a user.
Basic gameloops and MVC are very similar, except that MVC is event driven rather then procedural.
 
user1385191
yeah I've made a basic mvc demo using event dispatching
 
8:52 PM
What alternatives do you prefer to MVC ?
 
user1385191
I've tried two other patterns at this point: factory and decorator
 
There very different.
 
user1385191
yep
 
MVC be viewed more as a framework
design patterns are things you use in code. Design patterns can be used side by side. MVC you either use or don't. You can't use MVC side by side
I may be wrong here
 
user1385191
right now, I just code my applications over a bunch of class files with a bit of inheritance
 

« first day (126 days earlier)      last day (4825 days later) »