« first day (82 days earlier)      last day (4852 days later) » 

9:00 PM
Maybe freelancer.com is what I was thinking about, or maybe one of the sites mentioned here
@Darren you should be safe unless your javascript has variables named $ or jQuery
or functions etc
 
2
A: How do I do a "for ...in ...." loop in Javascript?

RocketIf you are using jQuery you can use $.each. $.each(data, function(i,v){ alert(v); });

Did I quote it wrong?
 
nope, he should indeed use jQuery
and now ALL up vote that comment
 
:D
Should I add an answer thats just a jQuery advert? :P
 
@Raynos if you do I'll be sure to upvote it with vigor
 
@IvoWetzel +1 at your comment
Can we please upvote whore the useless jQuery answer. I guess irony wouldn't be recognised
what is peoples opinion on
 
9:05 PM
I'm pretty sure Jacob will complain about people only up voting jQuery answers tomorrow on Twitter then
Oh, Mr. w3schools copy deleted his answer
 
    while(x) {
        if (foo) {
             // do stuff
        } // no else block
        // end of block
    }

    while(x) {
        if (!foo) continue;
        // do stuff
     // end block
     } // fail @ formatting
 
depends
if you end up with arrow style programming use the latter one to get rid of one indentation level
if you don't care use the former one, or if possible move the body out in a function
 
I like the latter a lot
 
> Uh, the what now? – Rocket 1 min ago
haha
 
upvotes that one
 
9:11 PM
while(x)
i think the latter one you can do with { }
*without
 
NOOOOOOOOOOOOOOoooooooooooooooooooooooOOOOOOOOOOOOOOOOOoooooooOOoooOOoooOOoooOoooOoooOOoooOOoooOoooOOoooOOoooOoooOOoooOoooOooooOoooOoo
always use {}
 
@Darren ew one line code
 
ALWAYS
and always put them on the same line
 
while (condition) if (another condition) continue, console.log("one line programming fuck yeah");
 
@Raynos You should totally drop that, you know
 
9:13 PM
while (x)
if (foo)
break;
with tabs f course
1 tab,2 tabs,3 tabs
why use ! when you can match it cleanly
 
tabs... gosh
kill them!11
 
@Darren you tricked me :( and you broke the code. Stop changing the meaning
 
see, that's why you use {}
This isn't Python
 
lol
tats not python
JS does not require brackets if there is only one block after it
 
your code above does not work
while (x)
if (foo)
// guess what the while ends here
break;
and it's horrible to read too...
what's to hard about using some {}?
 
9:19 PM
break is in wrong place
you do what you want
my goals are different
less code and less depedency
yours are
your own
 
back to the original question, I like if (!foo) {continue;} (with braces) because it's readable
 
less code... no comment on that one :)
 
Though I'm partial to the next unless $foo; syntax from Perl.
 
0
A: How do I do a "for ...in ...." loop in Javascript?

RaynosIf your using underscore.js you can use _.each _.each(data, function(value) { // do something with value });

Give underscore.js some love
 
I still want the for on loop...
 
9:21 PM
@Darren a bit aggresive. But no {} will break. the while only takes one statement
 
@Raynos You know...
 
@IvoWetzel don't you dare tell me to drop that and use jquery instead ;_;
 
@Raynos too late
 
i like jquery and extjs
 
@Darren extjs isn't free >:(
 
9:22 PM
i know
i bought a license
it paid for itself after 1 project
 
@Darren your crazy :\ Theres plenty of OS alternatives that will take longer but not worht $600 (thats 3 weeks in my books)
 
're
 
1 license gives the developer to code any commercial application on any machine
 
@Darren extjs is only worth it if youve got stable work flow
 
If I were TIMEX I would be extremely puzzled about to whom I should award the answer. Prolly just go with the jQuery one.
 
9:26 PM
you can use extjs core to accomplish jquery
which is free
for commercial and non
@Raynos extjs is $335
the $500 i with the support pack
 
@Darren that's not so bad then
 
Raynos are you a frelancer?
 
@Raynos is stable work flow something like this?
 
@Darren I'm a student. And im not writing code! :( I need to write code
 
@Raynos Write some stuff for the garden if you want to :P
Yes that's not code, but markdown is just as great
 
9:31 PM
@IvoWetzel I've got plenty of code to write
 
@Raynos Then write it :P
 
Raynos what school you go to
 
@IvoWetzel I'm waiting for java to install so I can use my java based IDE (and continue to procrastinate)
@Darren University of Bath, 4 year CompSci & Maths. sandwich course. currently on month 6 / 14 of a placement.
 
@Raynos Use VIM
@Raynos Or drop both...
 
What you guys think of Aptana
 
9:39 PM
Only had a quick look at it, but it's Java so meh...
:kitten quote
 
> "Computer science education cannot make anybody an expert programmer any more than studying brushes and pigment can make somebody an expert painter." - Eric S. Raymond
3
 
@IvoWetzel theres too much downtime in using VIM atm. I want to get this done and in pre alpha state.
@Darren Aptana is a pain. In terms of java based IDEs its defiantly WebStorm > netbeans > aptana > eclipse
 
@Raynos Well right now all you do is waiting for Java to install..
 
@IvoWetzel learning vim is on the todo list
 
@Raynos Just keep trying, it took me 3 tries to make the switch
 
9:44 PM
guys i really like jetbrains
here at work i code in 3 languages though
and one of them happens to be coldfusion :(
which makes it really hard to go with a perfect ide
 
Coldfusion... now I'm sorry for you :(
 
yeah :(
trying to convince the switch to python or ruby
ive used php for a long time and want a more mature language
 
@Darren you can't get one IDE for everything. Eclipse/netbeans for java, webstorm for javascript, vim for c++ VS for C#
 
is shocked at your insinuation that PHP is "less mature"
 
@Nathan php is ugly. Real ugly. It takes at least 2 years of using php for you to stop writing hacked code
 
9:47 PM
and JavaScript?
 
@Nathan javascript is nice. I blame the dom. node.js is nice :) one javascript spec. V8
 
:D
 
@Nathan Well at least I don't have to look up the docs for each other string function :P
 
Nathan, trust me I am a ZCE
I just want change
 
Python3 <3
 
9:48 PM
@IvoWetzel why python if you want to replace php :\
 
so like remember I was whining a bit earlier about being forced to learn .NET?
 
I find PHP is nice if I am working with programmers who can organize and comment their code
 
@Nathan .NET isn't that bad if you can garantuee usage only in windows
 
C# is actually designed unlike PHP and JavaScript which kind of accidently evolved, so it's more elegant. But I don't like it.
 
@Raynos I don't want to replace PHP, I want something superior :P
 
9:49 PM
You take 2 paths when you are born a programmer
you go down the windows path or the other path
do you want a cubicle or do you want a studio
 
@Darren you can do both
 
@Darren I have enjoyed PHP more since using a framework (symfony) that comes with a "do it right or don't do it" attitude.
 
yes
Symfony is a blessing
 
has a cubicle
 
we dont ave cubicles
 
9:50 PM
"do it right or don't do it" <--- that
 
we have areas
lol
 
my cube is smaller than jail cells in most countries
but we have good coffee!!!
!!!!!!!
 
yeah i bring my own
 
we take turns bringing in the good stuff and get along pretty well.
 
i do find it is a privilege to work with other programmers who understand frameworks and like clean code
 
9:52 PM
I secretly kind of even like dirty code. Is that so bad?
 
yeah
makes me want to drink
 
I only like dirty code I never have to look at again... which never happens
 
I inherited a big glop of copy-pasted code a couple months ago and it's fascinating that it works at all.
 
i heard python forces clean code so i am looking at it
but coldfusion guys
is buggy
and a middleman to java
 
0
Q: jQuery and AJAX?

MosheI'm making a simple form which has 5 input elements for parts of an address. I use jQuery to build and send an AJAX request to a PHP file on my server. For some reason my jQuery is not properly able to read the values from my input elements. What could be wrong? Here is my jQuery: $('#submitB...

^^^^^Completely confused here.^^^^^
 
9:59 PM
Does your alert work?
as in does it display the correct values?
 
It displays undefined, however, the jsFiddle mentioned in that thread does work.
My JS is fine syntactically, otherwise the rest of the page would not work.
 
@Moshe thats a false assumption. javascript can fail silently and horribly
 
Ok
 
hmm i need to try this symfony you speak of
sounds pretty sweet
 
Hello, can anyone help me with mootools and chaining?
If have a function which when I call it, I want to chain it with some other events. Is that possible?
 
10:14 PM
@Yash, yes
 
Is it a function you wrote yourself?
 
:kitten chaining?
 
Hold on a second, googling that for you... "chaining? did you mean horrible typo?" There you go!
 
Its a custom function which has a request.html inside. I just want to call the function this way:
requesthtmlfunction().chain(function(){do some stuffs});
 
0
Q: Javascript: Move to a div after page load. "onmouseover" works but "window.onload" does not

Jane WilkieHi guys! I have a page (and divs) that are being dynamically generated and what I need for this page to do is to scroll to a particular div immediately after the page loads. What is screwy about this code is this... The "button" code below, when you run the mouse over it (or onclick), works perf...

more half true answers >_>
:kitten quote
 
10:17 PM
> "In the one and only true way. The object-oriented version of 'Spaghetti code' is, of course, 'Lasagna code'. (Too many layers)." - Roberto Waltman
 
how can I do this?
 
@Yash be @IvoWetzel and thus awesome
 
Trading awesomeness for real life
 
@IvoWetzel how low a $/hour will you go for ask no questions codemonkey? :D
 
yc
hi room, I have a bounty expiring on this question tonight, and I was hoping to get some feedback on the quality of the answers. I'm not totally satisfied with any of them, so I'm not sure what I'll be doing about the bounty and accepted answer
6
Q: How dangerous is e.preventDefault();, and can it be replaced by keydown/mousedown tracking?

ycI'm working on a tracking script for a fairly sophisticated CRM for tracking form actions in Google Analytics. I'm trying to balance the desire to track form actions accurately with the need to never prevent a form from not working. Now, I know that doing something like this doesn't work. $('f...

 
10:21 PM
@yc just pick the answer that mentions jQuery the most.
 
@yc Hm, is there any chance that _gaq supports synchronous requests?
hm, seems to be async only
 
@Yash If that's really the syntax you're after, you could try something like this:
var requestHtmlFunction = function(){
    var myHTMLRequest = new Request.HTML();
    var successFunction = function(){};
    myHTMLRequest.onSuccess = successFunction;

    return {chain: function(fnc){
        successFunction=fnc;
    }};
};


requestHtmlFunction().chain(function(){alert("test");});
 
Thanks david i will try this
 
I've not used mootools before, so i'm just going by the docs... you will need to make the Request.HTML thing actually work...
 
10:27 PM
is that supposed to change myHTMLRequest.onSuccess?
 
gyar you're right what the fuck
var requestHtmlFunction = function(){
    var myHTMLRequest = new Request.HTML();

    return {chain: function(fnc){
        myHTMLRequest.onSuccess=fnc;
    }};
};
try that instead ><
 
just keep in mind that don't have access to myHTMLRequest inside the callback
 
ok thank you for ur efforts i will try this instead
 
is there a reason you want to do requesthtmlfunction().chain(function(){do some stuffs}); instead of just requesthtmlfunction(function(){/*whatever*/});?
 
@IvoWetzel I want to use both "private" variables within closures and the prototype
 
10:32 PM
@Raynos Not possible
 
@IvoWetzel it most be. Hacking time >:(
 
anyone can change the prototype, so your private variables can't be private
 
I should rename all the "Example" things to something that's more useful
but I'll do that tomorrow
 
Under your 'closures and references' section, would it be better to replace var foo = new Counter(4); with just var foo = Counter(4);
 
the thing is I have to add some events to the elements loaded in the html request, and i have to wait for the elements to actually load. Since the html request is in another fucntion is cannot use oncomplete within the html request.
I cannot**
 
10:40 PM
@david Hm yes might be better since it's essentially a factory
changed, commit has to wait till tomorrow since it's bed time now
have a nice ((morning|noon|afternoon|night)|day)
 
Did you read the article where the guy talks about 'hoisting'?
woah copypaste fail
you're covering it already, but it might give some different wording
 
gonna read it tomorrow :) Yes, my wording need changes... the whole thing needs to be rewritten a couple of times
I already did one partial rewrite today
 
<script type="text/javascript" src="http://www.google.com/calendar/...json-in-script&callback=insertAgenda&orderBy......

The above HTML calls this Javascript Function:

function insertAgenda(root) {
listEvents(root, 'agenda');
}

My question is: insertAgenda is being passed "root". Where is "root" coming from? What is root? Is it the DOM root? How does it know that root is being passed to it?
 
Use Firebug / Chrome Inspector, set a breakpoint, find out
anyways I'm off now
 
that is the function definition, you will need to look where it actually gets called
you can pass anything you want when you call the function
 
10:50 PM
Oh, ok. I thought callback=insertAgenda from the HTML was calling that function
 
close, that line will be setting the function as a callback. somewhere else though the callback will be called
 
callback is where the end data is finally returned to?
 
@yc I updated the jsfiddle code I gave you yesterday, this code should no longer break inserting the Image into the DOM.
 
yc
@Na7coldwater interesting!
 
@MALON here is kinda what i think is happening, jsfiddle.net/7z3wE/1
the 'root' is passed into the function that you set as the callback
 
11:02 PM
Thanks, I think.
I didn't fully understand it, but that's ok
 
yeah it wasn't very clear :S
 
Are you busy david? maybe you could help me out. Right now I'm using Google's calendar API and I'm using their example code to crap out some calendar events on a site, however their example code does not take into consideration "if no events", so instead of returning "no events" it returns empty.
 
@david thanks for that link about "hoisting"; I have been dimly aware JavaScript scoping wasn't as I expected but didn't know why.
 
basically 'root' is coming from whatever is executing the callback
 
I've been working on this for about 4 hours now, I'm missing something
 
11:06 PM
@Nathan no prob, it blew my mind the first time i read it. definitely should be required reading
surely if it returns empty then you know there are no events?
or do you want to actually display the string 'no events'?
 
Preferably the string "no events"
 
do you have a live example? it should be as easy as checking the length of the list of events and then unhiding a div
 
prestonservicemen.com/events.php is what I'm working on.
If you need me to remove the events, let me know.
 
which page is the problem on?
events? or calender?
 
events
I will explain it as verbally as I can. There are 3 parts:

#1. cal.js (provided verbatim from Google)

#2. <div id="agenda"> (this is where the results are returned to)

#3. a very long href that gets json from google calendar.
 
11:13 PM
in cal.js, replace
if (feed.entry.length == 0)
    return "Nothing here yet!";

with
if (feed.entry.length == 0){
    var li = document.createElement('li');
    li.appendChild("No events");
    ul.appendChild(li);
    events.appendChild(ul);
    return;
}
 
yc
@Na7coldwater so, i'm a bit confused by this code. It seems to be totally breaking GA (which I'd guess is a bug :P), but if I construct an image manually, it seems to work. Maybe there's something in the obfuscated GA code that prevents this kind of overloading?
crowdlistr.com/custom is my test page
 
@yc Is it creating an error or is it failing silently?
 
I will try what you said David, but I've been down this path and it didn't work. The problem is that feed.entry.length does not return zero when there's no elements.

Basically, if I do

alert(feed.entry.length);

It will reflect how many events there are. But if there are no events, it doesn't do anything. it doesn't print null, zero or anything. It's as if the entire alert is skipped.
But I'm about to try what you said
 
yc
@Na7coldwater oh, pardon the idiocy, its working. Forgot to include jQuery...
 
11:16 PM
oh, okay that's weird.
 
Does anyone have some suggestions on how to implement that?
 
Ok, I did what you said and no go. I've removed all events from the calendar.
I am completely stumped, this has been killer.
 
yc
@Na7coldwater this is kind of amazing. you might want to consider using your code to answer this: stackoverflow.com/questions/4590696/… ; I'll even post a bounty on it
 
@MALON okay, replace the if line with this: if (!feed.entry || feed.entry.length == 0){
 
Done and it didn't work :(
This is also shorter code:

if (!feed.entry || feed.entry.length == 0){
events.innerHTML('sorry no events');
return;
}
But it doesn't work haha
Feel free to copy all the code to your local machine, I'm not running any server specific code.
it's all HTML and JS
oh wait, that's right, I didn't build this site, but even so, you could still copy the HTML and JS to your local machine
BTW Thanks a shitton david, even if you don't fix it. Just thanks for helpin' :)
 
11:22 PM
gyar
im doing stupid shit
that's why it's not working
replace the "no events" line with this:
li.appendChild(document.createTextNode("No events"));
 
@yc Posted my answer.
0
A: Google analytics _trackPageview callback

Na7coldwaterOverloading the current Image() function in the page is one solution: var oldImage = window.Image; window.Image = function() { var self = this; var theImage = new oldImage(); $(theImage).load(function(){ alert("Loaded!"); // Do something here });...

 
if (!feed.entry || feed.entry.length == 0){
var li = document.createElement('li');
li.appendChild(document.createTextNode("No events"));
li.appendChild("No events");
ul.appendChild(li);
events.appendChild(ul);
return;
}

That code?
 
not quite
get rid of the old "no events" line
it was stupid ><
 
oops, I meant to
 
yc
@Na7coldwater interesting, do you really think Malvolio's solution is ideal? I work a lot with GA, and I've never seen someone push a non-GA function into the _gaq array.
 
11:26 PM
Thank so much David, it wors
But I did this, I SWEAR I did this. I spent 4 hours trying combinations of about 6 lines of code
I can't believe I never tried this
Thaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaank you
 
@yc I don't know. But overloading a global function to work around unloading canceling ajax seems a bit extreme.
 
@MALON ahah, no problem
 
yc
@Na7coldwater right, i'm a long ways away from using that on a live website; gotta do some testing to make sure it survives under extreme conditions
 
0
Q: Javascript object encapsulation that tracks changes

RaynosIs it possible to create a wrapper for an object where any changes to the object can be tracked. Said object is a complex nested object of data. (compliant with JSON). The wrapper interface should have a getter for the object and a showChanges method that displays any changes. Does there exis...

im stumped for emplementation that don't rely on serialization
 
@Raynos How about every time Container.update is called it adds the changes to an array?
 
11:42 PM
Hi! Can anyone take a look at this snippet? jsfiddle.net/dN5ma/4
 
@Na7coldwater how does it know what the changes are? Without cloning the object and keeping a local copy when get is called. Or passing a clone through the get method
 
I'm using RightJS, because that's what the site is using for other things.
 
is jsfiddle dying?
 
@david yes
 
weeps quietly
 
11:43 PM
it now appears to be... dead
 
@Raynos Is the wrapped object just holding simple types like numbers, bools, and strings? Or is it containing sub-objects?
 
@Raynos doesn't your update() have to have some arguments, in order to make an update happen? In other contexts I've inserted an "audit" row in a log with a nice message every time an update happens.
It's kind of like a changeset and a comment from version control
 
@Na7coldwater sub objects. hence the issue
 
update(foobarbaz, true) should just log "nathan set foobarbaz to true" right?
 
@Rayno What do the arguments to Update look like?
 
11:47 PM
@Nathan @Na7coldwater update doesnt need any arguments since the object that was gotten has been changed. the changes have been applied to the internal "private" variable since im just passing it by reference
 
@Raynos that's like having a version control system check in the whole file rather than a changeset/patch
if you are directly working with the child object then what's your update() function for?
 
@Nathan Yes, but I want to check in the changeset/patch. I dont know how to handle that
 
I'm sorry I don't think I understand the subtlety of what you're doing.
 
@Nathan update is used to tell the container that the object changed
Let me give an example
 
So in a centralized version control system, the diff happens locally, and the diff is sent, right? It doesn't get calculated at the server.
 
11:50 PM
@Nathan oh im lost here.
 
ok, so you're saying your update() doesn't effect changes like SQL UPDATE, it just notifies?
 
var foo = state.get();
// change state
state.update();
client.tell(state.recentChange());
If it pleases you, you can call state.update(foo);
 
and by 'change state' you mean like foo.bar.baz = true;?
 
@Raynos It sounds like each sub object should also be wrapped in a container.
 
@Na7coldwater they cant. you only get one container
@Nathan yes. Then state.recentChange should say "foo.bar.baz was false, but now true"
 
11:54 PM
OK so for "design pattern" I'm thinking of version control or a database, or a database with ORM...
 
my current implementation is to pass out a deep clone through get rather then a shallow clone
@Nathan I may have used the word wrong. You can think of it like that. But the implementation should be pure JS
 
@Raynos I understand, I'm just thinking for a pattern, you want your JS to behave like VC or a database.
 
@Raynos Use Object.defineProperty on each property you want to check for changes.
 
Let's see... in a database with ORM, objects are loaded into memory from the database, but when they're "saved" then UPDATE statements happen, and you can hook an audit log into the save event, and you could have notifications go out when the audit log is updated.
In centralized version control, you change your working copy locally, then commit changes, which sends a diff to the server, and you could hook notification to the commit.
sorry hope it's helpful; brb.
 
The thing is there is only one copy of the object. The object stored internally and the object you have and manipulate. With both the above there are two copies saved (especially with a database)
 
11:59 PM
@Raynos There are only two solutions, I think. Either capture each change as it happens, or keep a copy of the object to compare the changed object to.
 

« first day (82 days earlier)      last day (4852 days later) »