« first day (127 days earlier)      last day (4823 days later) » 

3:00 PM
I wrote a small PHP page that uses the SO API to filter out the top voted answer and question in the last 3 hours
If it starts misbehaving please shut it down, hrump...
 
3
Q: Facebook blocked, show alternative content?

Anders PalmHi, I run a bunch of websites in Vietnam, such as www.nyc.vn about New York City. The problem I have is that Facebook is blocked in Vietnam and that both the fan-box and like-buttons are shown as broken links in iframes "Page could not be found" when a blocked user views it. I know that around...

 
Well the second one worked, but not the first
 
obj.trigger("foo"); obj.trigger("bar");
Is it reasonable to assert that the eventhandler for foo runs before bar?
Or is the async nature supposed to abstract away order?
 
4 messages moved to Sandbox
 
@Raynos depends... in Node right now (although fixes are pending) there is no such guarantee that foo will run before bar in case the event loop is involved
 
3:04 PM
@IvoWetzel is it supposed to ? Is it going in the wrong order considered a "bug"
I'm writing a unit tests which demands that events trigger should happen in order. Is that breaking the unwritten laws of the asynchronous event loop?
 
well how do your events get triggered?
just a call? or setTimeout?
 
obj.trigger("foo");obj.trigger("bar");
 
what's inside trigger?
 
@Raynos jQuery?
 
Either the event emitter or some custom code
 
3:09 PM
@Raynos Event emitter
 
so emiter.emit("foo");emiter.emit("bar");
 
At least, if obj is a jQuery object, then that's the case
 
hm, i don't know the exact situations when the order might get screwed up, but I guess in 99.9% of all cases it works as expected
and as said, fixes are on the way for node
 
@IvoWetzel and 0.1% is a bug rather then "bad luck" ?
@YiJiang jquery uses an event emitter? I dont know how the native DOM events API works
 
Well if the underlying engine is "buggy" it's not your fault
 
3:11 PM
@Raynos It doesn't, afaik - it uses it's own event model
Actually, I don't know
 
It could be either way. One could argue that events are asynchronous and thus do not garantuee order
as in bar should not rely on the fact that it was emitted after foo and that foo must have been completely handled.
Is it bad practice for bar to rely on that?
 
I've found out a thing in jQuery some days ago. No more need for:
$('.obj').click(function(e) {
	if (!e) var e = window.event;
	alert(event.type); // click
});
This works, too:
$('.obj').click(function() {
	alert(event.type); // click
});
@YiJiang Huh?
 
Something else entirely, I was guessing about what you were trying to do
Anyway, I've always thought that jQuery normalized the event object that's passed to the callback?
 
@Raynos I know it isn't possible to do an AJAX call for the question updates or get push notifications from the SO server for them, is the best way for them to update "near realtime" by refreshing the JSON call on a timer?
 
Probably yes
@YiJiang it does. the paramater is a normalized event object
 
3:24 PM
@MylesGray What are you calling here? The API?
If you want to poll it you should get a key
 
@YiJiang I have a key I think
 
What are the pitfalls with this function?
 
it's the consumer key right?
they said they would send me an API key but i never got one so i assume that is it
 
@MylesGray You should be able to see it here: stackapps.com/apps
 
3:29 PM
@YiJiang Yeah I have this: Consumer Key: [letters here]
I assume this is for the API?
 
Yup, you're good to go
 
im limited to 10K poll's per day per IP however
does that mean if I port to android it will work better than browser as there will be different IP's and not all from the one github site
 
@MylesGray Eh, you're using jsonp - every request from each visitor will have unique ips
 
@YiJiang I assumed it used the web-servers IP?
not the visitors external IP?
 
@MylesGray Only if it's the web server that's doing the requests
 
3:34 PM
@YiJiang you mean if it was server-side java/asp etc?
 
@MylesGray Yes, think about it - it's the browser that's loading the json data by appending the script tags, it's the client browser that's doing the call, of course it's the client's IP that's logged
 
does anyone know how to advance the time by 24 hours?
This waiting sucks
 
@IvoWetzel You mean in JS?
 
no RL
 
@IvoWetzel LOL you don't know that?
 
3:46 PM
no I still haven't wrapped my head around time travel
 
@IvoWetzel First, install the RLJSL library… (and no, I don't have RAS syndrome :P)
 
Hey, if i want to have a value in textarea to appear only when empty/and not clicked in it how can i do that?
 
@IvoWetzel Just use jQuery - $.timeTravel('+24 hours')
 
@YiJiang ahhh
unfortunately RL seems to use a older version of jQuery which does not include that function
 
@IvoWetzel Dammit! Can't you point RL to the Google CDN version?
 
3:51 PM
0
Q: removing public access to methods on an object

RaynosI would like to take an object and remove some methods from it. i.e. I have internally have an object with getter/setters on it and I want to give external users access to it. I don't want them to have access to the setter functions. I don't want to change original object reference by removing...

 
@YiJiang Don't think quantum mechanics allow for such things
 
Seriously. How do I go about doing such a thing?
 
don't expose them in the first place?
I can't see how this can be done at runtime in a 100% compatible manner without the use of crazy eval stuff
 
oy!
 
@IvoWetzel I want to expose them
I want one function to have getter/setters
and another function to only have getters
 
3:55 PM
Any link of tut/sample of where i can do this exactly: webune.com/forums/20101025cgtc.html but in jQuery?
 
@IvoWetzel whats wrong with my implementation? Apart from the fact that the constructor might be stupidly expensive
 
the constructor looks strange, how would you copy state?
or is the object in question stateless?
 
@IvoWetzel state is copied by binding the reference
As in all the methods are bound the instance of the object
the _.bindAll call
 
how do you make sure that the constructor call has no side effects?
 
@IvoWetzel Who the hell writes side effects into a constructor! Bad code breaks. I'm not going to fix bad code!
A constructor should only effect the state of this not anything else
 
3:58 PM
I would rather create a thin wrapper, that has it's prototype set to obj
to instanceof etc would work
but you would still know that it's a wrapper in case you need to
 
@IvoWetzel nesting it up the prototype chain seems like a right pain
 
Anyone knows what does oy mean?
 
@Raynos Let me try
 
The object just became instanceof readonly.f
And it doesn't remove calls from the prototype
 
4:01 PM
there's still the question what hinders one from use doing wrapper.prototype.allAccess = original.prototype.allAccess
 
This isn't something that needs to be hack proof. It just needs to work under normal use
and be as transparent as possible. For all you care its the same object
except I've made some of the methods private
 
How come I can create gallery chat rooms? Is the rep thresold lower now?
I can do that only on SE chat, not on SO/MSO.
 
@Nyuszika7H SE uses your combined rep
 
4:19 PM
@YiJiang And is it normal that all my newly-created rooms on Chat.SE have the SO logo?
 
Whats a monad?
@IvoWetzel did ou figure something out?
 
only in part hm
the best / easiest thing I could come up with
function AccessWrapper() {}
function wrap(obj, methods) {
    var wrapper = new AccessWrapper();
    wrapper.is = function(other) {
        return this instanceof other || obj instanceof other;
    };

    for(var i in obj) {
        if (methods.indexOf(i) !== -1) {
            if (obj.hasOwnProperty(i)) {
                wrapper[i] = (function(func) {
                    return function() {
                        return func.apply(obj, arguments);
                    }
                })(obj[i]);
need refactoring, but there's no "easy" way of getting obj onto the prototype chain without exposing all the stuff yet again
 
I just realised my method doesn't remove anything from the prototype
 
yeah, you would need to create another object between obj.prototype and wrapper.prototype
and then set every key that's on obj.prototype to undefined on that.prototype
 
4:43 PM
@IvoWetzel jsfiddle.net/Raynos/tykBJ/15 I overwrit all the methods defined on the nearest prototype so that they are undefined
Now I need to write unit tests for it :(
I'm suprised such a method isnt used more commonly
 
well I see no real use for it
it's hard to secure against people who still want the internals
and if you don't want something to be used, just don't use it
 
I want to pass things onto external users
I have a state object with get & set
and a Entity.bind("event", function(data, state) {})
I only want state to have the method set when "event" === "update"
So I pass on _.allow(state, ["get"]) or _.allow(state, ["get","set"]) depending on the situation
Is there something else I should be doing instead? Is this a bad use case?
 
5:05 PM
0
Q: XML with namespace. Issue with Internet Explorer

sissonbI am having an issue rendering data from XML with namespacing in Internet Explorer 6, 7 and 8(haven't checked 9). It works in Chrome though. The XML is formatted like this, <?xml version="1.0" encoding="UTF-8" ?> <pre:customerAddress xmlns:pre="http://www.example.org/"> <pre:c...

 
I don't see the point in this
seems like doctoring on restriction from languages which have those built in, onto JS objects which can be hacked in any given way
 
is there no point because JS runs on the client so the user can run any code they want?
 
This is on nodejs. This isn't for security or public/private but more of a were not going to make this method accesible because you shouldnt be using it
 
ohhh ok.
 
@Raynos: I'm probably off-context (didn't read everything) but it sounds like you should not use classical inheritance patterns for that purpose
 
5:10 PM
@jAndy It sounds like I am but I'm not really.
I'm just taking an object and going You only need these x methods so heres the object with these x methods
Exactly the same way $.Deferred.promise removes the ability to resolve or reject a promise
 
@Raynos: still, this can easily be done with methodical/closure patterns no ?
 
A promise is the same a deferred except you can reject/resolve a deferred, a promise is just there to wait
@jAndy I dont see how I can without defining a method like $.deferred.promise
 
@Raynos: hm I guess i don't fully understand what you are actually trying to achieve then
 
Look at what jQuery.deferred.promise is doing. Something similar to that.
Basically remove any methods from an object that a function doesnt need
 
hm yea, they just copy all methods from the deferred object into a new object and return that
"all methods they want to have there"
 
5:17 PM
Yep. I'm just generalizing it to a method
_.allow(obj, ["method1", "method2"])
 
but that's a pretty special way, I won't even think about why they took that route to expose only a few methods
In general I wouldn't do it that way, THAT is clunky
imo
 
Hi again! :)
 
Ah, what would be a better way?
@jAndy do you know any alternatives?
 
@Raynos: I still believe it's an easy task with methodical patterns, but I don't know your requirements enough. Anyway, if your code is so similar to the deferred object, why not use it that why? (copying methods)
 
5:29 PM
I have an object with a get & set
I pass this object to many methods. Only one method should have access to set
The other methods should only have access to get
 
5:42 PM
function makeObject(key, value) {
    var obj = {};
    obj[key] = value;
    return obj;
}
Is there something obvouis I'm missing that makes this trivial?
9 messages moved to bin
@sdleihssirhc so how are you doing?
 
Pretty good.
Gonna do some disc golfing later today.
What about you?
Good to see that the bin is still around.
 
I'll sit here and wait till the weekend is over
Then, tomorrow I'll be extremely nervous all day long >_>
 
Im just gonna continue ccoding
 
@Raynos I remember at some point we had approximately the same rep.
And then all of a sudden you're a top JS user
and I'm a lowly disc golfer
 
They even gave him ownership of this room!
 
5:48 PM
Inconceivable!
@sdleihssirhc I don't think that word means what you think it means
 
I'd've used "unbelievable"
 
If I was a better poet, I'd come up with a word that rhymed with "unbelievable."
And if I was a better coder, I'd also make it a JavaScript pun.
But alas.
 
@sdleihssirhc You gave up on rep hunting!
 
@Raynos I did, kind of.
 
@IvoWetzel I know. I'm suprisingly not that bad.
 
5:51 PM
@Raynos Not entirely.
 
@sdleihssirhc I think you should go to codereview.stackexchange.com >_>
 
yeah! the site needs some activity
 
@Raynos I'm a fan of any site that gives me ten new privileges just for signing up.
 
:D
 
And yet, I still can't vote down!
 
5:53 PM

rchern's smileys

Feb 7 at 14:44, 5 minutes total – 7 messages, 3 users, 0 stars

Bookmarked 8 secs ago by Nyuszika7H

 
Stack Exchange is awesome.
 
There just happen to be two javascript questions at the top of the active list! Off you go.
 
these guys seem kind of familiar
 
yeah, I wonder who they are
@Raynos Do you have any ideas?
 
@IvoWetzel No clue. I'm afraid but their code can use refactoring! Off you go @sdleihssirhc
 
5:56 PM
spreading the meme!
0
Q: Jquery advantages?

PeterHi, I've been using JQuery for quite sometime now and I'm pretty much happy with the performance. I'm just wondering if there is any performance comparison between Jquery, YUI, Dojo, Prototype, Mootools etc., What are all the advantages of using JQuery framework over others? Peter

(see comments)
Dang I'd really like to post "JavaScript was written in jQuery" as an answer...
 
Are joke answers really frowned apon?
3 messages moved to bin
I heard JavaScript was written in jQuery.

So it doesn't matter which framework you use, they all rely on jQuery under the hood.
 
stupid comments ahoi!
0
A: Jquery advantages?

LufthansaAll javascript framework never give better performance then others in Every function they implemented in framework so they never compare them. if you want to performance comparison between jQuery 's it's own version then you should read jQuery blog to know about them.

wut?
 
(read: 1.675)
I dont get that?
 
jQuery only handles 1.675 things not
everything else is handled
or is the "read" superfluous?
 
What are the 1.675 things jquery does not handle?
 
6:03 PM
the 1.675 that it doesn't handle
Truth is, nobody knows what they are
as Resig silences everyone who dares to tell the world that jQuery doesn't handle EVERYTHING++
 
@IvoWetzel What does ~~ do?
I thought it was kind of like !!
 
a more or less "replacement" of Math.round
 
But it was a while ago that I messed with it
 
!! is a "cast" to boolean
 
right
@IvoWetzel So its like Math.floor?
How did I miss that the last time around?
 
6:06 PM
yeah, bascially Math.floor
~~(5.9 / 2) == 2
 
what is ~
 
bitwise stuff
dunno, I just copy paste random JavaScripts from the GitHubs until it works
 
:D
 
then I show up at CR and let the people their do the rest
afterwards I copy paste parts of their answers over to SO and get lots of reps
 
@IvoWetzel i didnt know people on chatroulette could do javascript
 
6:14 PM
uhh
 
user1385191
if crockford is to believed, bitwise stuff could be a lot faster than it is right now
 
Well in FX4 Math.floor is 92% slower
 
user1385191
"In Java, the bitwise operators work with integers. Javascript doesn't have integers. It only has double precision floating-point numbers. So, the bitwise operators convert their numbers operands into integers, do their business, and then convert them back. In most languages, these operators are very close to the hardware and very fast. In Javascript, they are very far from the hardware and very slow. Javascript is rarely used for doing bit manipulation."
 
user1385191
6:24 PM
verbatim from Javascript: The Good Parts
 
well 223.000.000 ops in FX4 seem fast enough to me
Good Parts was written way before the JS engine race started
 
@IvoWetzel Can you explain this part to me? [^\\^\}]
What's the other ^ doing there?
 
actuall nothing
removes it
 
thanks for spotting :)
 
6:27 PM
I'm just glad I have any idea what I'm doing :S
 
How can i do this webune.com/forums/20101025cgtc.html, in jQuery
 
@sdleihssirhc the second ^ was just part of the not group in this case so ^ would not have been matched
 
That's all I could come up with.
But I couldn't figure out why you didn't want to match ^
So I went to my trusty fallback: I don't understand.
 
I hate JavaScript. Piece of shit!
I found my bug. :D
 
@IvoWetzel Do you mean to match strings like '{{}'?
 
6:34 PM
just the {}
 
From the first { or the second?
 
second
so
    var string = '{1} {} {{2}} { {3}} { 4} {5 } {6}} {{7} } \\{8\\} \\{9} \{{10}}';
becomes
    var expected = '001 foo {002} { 003} 004 005 006} {007 } \\{8\\} \\{9} {010}';
a bit of double escaping in there but you get the idea
 
right
one second
let me make sure I know what I'm talking about
Yeah, it's catching the whole thing.
I guess I should put this in an answer?
 
hm? the ^ thing?
 
No, the {{} thing
It sees the second { as content inside the {}
That's not intentional, right?
 
6:38 PM
ah indeed
hmmmm stupid regexp
that's a bug I suppose :)
 
crush it
stamp
 
6:53 PM
@IvoWetzel Do you want to allow escaped { and }?
Like, '{\{}'?
 
yes
guess I figured it out now
of course the regexp is even more complicated...
 
I was gonna say.
 
var exp = /([^\\]|^)(\{([^\{\}]+[^\\\}]||[^\{\\\}])\})/g;
 
Is that supposed to be a single |?
 
problem was the * instead of the +
it's two
 
6:57 PM
What does that mean?
 
so it matches {} <- nothing inside
 
right right
o_O
 
{1} {{} {} {{2}} { {3}} { 4} {5 } {6}} {{7} } \{8\} \{9} {{10}}
{1} 1
{}
{}
{2} 2
{3} 3
{ 4}  4
{5 } 5
{6} 6
{7} 7
{10} 10
foo {foo foo {foo} { foo} foo foo foo} {foo } \{8\} \{9} {foo}
 
very nice
And now, after all the incredible help I was able to offer, I must go throw plastic at metal.
 
Hi again! :)
 
7:00 PM
Good luck @IvoWetzel
 
well or not nice
all tests fail :D
 
oh
snap
:s
 
ah
one matching group to many :)
all tests pass!
 
I had to come back because I realized why it was failing...
But you got it...
cool...
nm
 
var ufo_rx = /^<<<([A-Z]{3})>>>$/;
 
7:53 PM
0
A: My First JQuery

Nyuszika7H// If you use selectors multiple times, always cache them into variables, else jQuery has to search for them multiple times. var $cont = $('.cont'), $expandAll = $('#expandAll'), $trigger = $('.trigger'); function expandAll() { $cont.removeClass('hid'); $trigger.html('-');...

 
 
1 hour later…
8:54 PM
Writing unit tests for games is a pain in the ass
 
that's why you pay lots of people to do QA
And in the end, you can never write tests for "fun"
 
user1385191
is it more of a pain than subversion? my artist is having a ton of problems with it
 
What?
Anyways, I'm off to bed, tomorrow I'll either cry all day long or be really really happy
(that is, in case the made a decision...)
 
:P:
What simple game can I write where the input is an odd or even number :D
Actually the input is i++ until the game ends
 
 
1 hour later…
10:28 PM
@Raynos colour scheme anymore to your liking? mutanttractor.github.com/StackOverflow-Android-Dashboard
 
@MylesGray its better. The ui is annoying :P
 
Whats wrong with it? not flashy enough? :P
@YiJiang How do I use the API key that SO gave me, there are no instructions about it on the dev site :(
 
10:51 PM
@MylesGray Simply include it as api={key} in all your queries to use it
 
@YiJiang thanks! - Found it in a question on the dev site
 
what framework do you use for unit tests?
 
11:12 PM
jasmine?
 
I wrote my own >_>
It tries to comply to commonJS unit testing. But it has a few bugs
 
Is it okay to use setTimeout ( expression, timeout ); as a timer for polling for new questions
 
@MylesGray if the expression is a function and not a string, yes
 
oh better one found setInterval
setInterval (tagLookup(), 65000); looks good to me
@Raynos UI-wise what would you say about the site?
 
11:28 PM
every 65s?
 
mhmm
you cant poll faster than once a minute
thats abuse aparrently
 
I have to type on the tag and click
its just not easy enough
 
What I'm aiming for is that when they hit enter OR put in a comma it will auto poll
that would be nice
I'll try implement something like that
 
11:41 PM
@Raynos I was thinking auto-complete would be really nice, unfortunately With it not being AJAX and with the low polling rate I cant do that...
 
grab a list of tags
cache it
then auto-complete againts that
Remember common tags
Have floating buttons of common tags so I dont have to type them
 
The API stipulates that: Polling for changes should be done sparingly in any case, and polling at a rate faster than once a minute (for semantically identical requests) is considered abusive.
So maybe I can get it to work
I may be able to get away with this, as soon as the user types a letter it starts searching and every letter that is typed is then added into the search box, thus narrowing the search
hmm.. im not sure my polling is working
 
etc. etc. etc.
 
stupid... the function needs to be wrapped in quotes
 
Dont poll that
Grab an entire list of tags
from somewhere else
 
11:49 PM
@Raynos the entire list of tags... thats like 10K tags?
 
yes
cacche it into an array
then look up into that for auto completion
 
hmm that works :)
"total": 27945,
oh dear
would that not absolutely rape the apps performance?
 
No
because you only do it once
at page load
Then query the array
Or a subset of the array
do some clever caching
 
Thing is I am limited to a response of 100 elements per page from the API
so I will need to poll the URL 280 times to get the list
 
Cant you get it from somewhere else?
 
11:53 PM
the JSON limit I believe is 30/5seconds
I don't think it can be pulled from elsewhere
 
then scrap auto complete
 
Man thats 50 seconds to poll it
yeah i thought so
not practial at all
 
just hardcode in the list of tags :D
 
I suppose I could get synonym tags for the selected tags?
 
im going to bed
 
11:55 PM
kk night man
 

« first day (127 days earlier)      last day (4823 days later) »