« first day (436 days earlier)      last day (4737 days later) » 

18:02
Plus the semicolons align that way, which is always nice. What do you use Object.create(null) for anyways?
Pure hashmaps
No prototype, nothing to screw it up, nothing to slow it down
You can also use it for weird shit that doesn't behave like anything
Right, I think I'll rather use the javascript object notation. :-)
Plus with __proto__ you can always do this:

var a = {foo:"bar"};
a.__proto__ = null;

Heck, we really need a standardized prototype setter.
Object.create is a standardized prototype setter
Yes, but with one caveat - only at creation.
That's not very bad, really...setting it after creation seems weird. It's mutating it.
18:06
I have no problem with being able to mutate an object. :-)
Then you enjoy __proto__
Sure, but it'd be nice if it were standardized :-)
Just my wishful thinking
It's probably for the best. Dynamically fucking someone's DNA isn't nice.
Come on. This is a scripting language, I should be allowed to do stuff. The descriptor monstrosity in ECMA5 is someone trying to solve a problem, which doesn't exist.
Really? I like the idea of setting the meta-attributes
But I see your point in __proto__, I'm just biased.
18:11
In my opinion the descriptors serve no purpose other then allowing people to micromanage stuff, but really do nothing. I liked it as well, when I first saw it, but then I asked myself why would I want to do that?
Setting things on Object.prototype without fucking for in loops, for example
Making awesome getters/setters
Screwing with people by not allowing them to change an object property shiver
Getters and setters are the only thing that I really really like about that :-)
hrm, try and ping me with a command
@Zirak /die
@Witiko I'm dead!
A different one :P
18:15
@Zirak /jQuery ajax
Awesome, thanks
I'm thinking of making a /learn, so it can learn new commands automatically
A subset of JSON for commands will likely suffice...
That should be interesting!
But if you do, I'll while(true); you ;)
I'm still trying to figure out how specifying the output will look like
{ "commandName" : "arguments parser comes here" }
@Witiko Hahaha
I don't want to give js control, one of the reasons being just what you said, but maybe a reg-ex thing?
18:23
Well, what do you want for us to be able to do with it?
If it's just learning a text response, that's fairly safe, but hardly useful :-)
If you wanna let us add something like that hangman game over the chat, functions will be necessary
{
    "name" : "something",
    "arguments" : "{} me a {}"
}
/something spill, drink => "spill me a drink"
That's far from turing-complete :D
I don't want it to be turing complete. Making full-fledged functionality via something like this is very dangerous
You can spam the chatroom to oblivion, for example
2
No, You would. That'd be the interesting part :D
hehe
18:28
Well, you could always sanitize the input, not allow us to eval and disembed us from the DOM.
Anyway, how about a regular expression? One for input arguments, one for output. It's a simple string.replace
That'll be a bitch. You're asking me to make a subset of js.
Or, at least, detect every plausible way for something to access something. I'm not sure that's even possible without sandboxing you.
Yes, I was talking abt. sandboxing, but you'd need to do it by altering the input before evaling it.
But yeah, it'd be hard.
RegExp could be more entertaining
{
    "name" : "meep",
    "input" : "(\w+), (\w+)",
    "output" : "$1 me a $2"
}
/meep spill, drink => "spill me a drink"
Problem is figuring out if it's a good regex, enabling you to test it, and to have the bot un-learn it
And then someone could trololol and have the bot unlearn everything
why not let us input a RegExp literal?
What's the difference?
18:33
Well, you don't have to escape everything.
Nah, it'll be harder to parse that way. With a string input, I can just new RegExp( obj.input )
Wrapped in a try catch for error-handling
"(\w+), (\w+)" is wrong, you'd need to "(\\w+), (\\w+)" - and that'S what I'm talking about. Why not /(\w+), (\w+)/
It won't be harder, you wouldn't need t do even that, ust instanceof RegExp check
Because that's not valid JSON
Well, screw that. :-)
ok, how about we use something different than `\` for identifiers?
Like ~w
18:36
That could work.
Or $w
What about flags?
input can optionally be an object
"input" : {
    pattern : "...", flags : "ige"
}
Sounds fine
hm, inserting a literal ~ could be a problem...I'd have to actually parse the input, so that ~~w would mean ~w
This is hard
Well, not hard, just annoying
18:40
@Zirak Do you know what the minimum time for SO Chat messages is?
@Amaan Game finished or didn't start. Ping me with /new to start
Oh, man
@Zirak /die
@Zirak I'm dead!
About 5 seconds
Okay. I'm trying to make a basic Google Search bot
So I'm just going to set a timeout of 5 seconds between any messages I send
I'm trying to procrastinate over my procrastination, which serves as an additional procrastination :P
18:42
@Zirak input.replace(/~(?=~)/g, "~") should work, but for some reason the lookahead doesn't work.
Watching House -> Making the bot -> doing real work
aaaa, it works
"~~~~~".replace(/~(?=~)/g, "")
I'ma change @Zirak to !Zirak
Yeah, that'd be better
@Witiko Awesome
18:44
No, actually this works as expected: input.replace(/~~/g, "~")
Wait, shouldn't that output '~~'?
Dear lord you're a genius
:D
input.replace(/~./g, function(text) {
  var $ = text.charAt(1);
  return $ === "~"?"~":"\\" + $;
});
That should turn the input to a string ready to new RegExp(string)
yep, made something like that
This has progressed a lot more than what I expected
19:01
@Zirak /new
@Zirak /die
Turned it on again
@Zirak /new
  +---+
  |   |
  |
  |
  |
__+__

------
@Zirak /die
@Witiko I'm dead!
I can already see the trolls turning the bot off just before ppl get the word right :D
hehe
I wanted to make that command so if it starts spamming or anything, you can safely turn it off
19:07
Hm, thought of checking your username in the message and giving you access to several admin commands?
Besides, the memory isn't wiped, so once the bot is on again you can continue as if nothing happened
I can do that
Still, I think the idea of you having a special subset of commands available is not a bad one
It'll make command handling a little tougher...each command is a complex object...
learn: function(args, usr) {
    var command;
    try {
        command = JSON.parse(args);
    }
    catch (e) {
        bot.reply(e.message, usr);
        throw e;
    }

    if (!command.name || !command.input || !command.output) {
        bot.reply('Illegal /learn object ' + args, usr);
        return;
    }

    //a shitty way to do it, I know
    if (!(command.input instanceof Object)) {
        command.input = {
            pattern: command.input,
            flags: ''
        };
    }

    command.input.pattern = command.input.pattern.replace(/~./g, function(c) {
Before I humiliate myself even further, thoughts?
oh, there should be a check to see if the command already exists
If I make a new object based on a prototype, and I alter the prototype be e.g. adding properties to it, will the changes be reflected in the object based on that prototype?
@Pjotr: Why, of course. Since the object isn't "based on it", it just references the prototype object.
19:21
Ah, of course
okay, changes: You now use !botName. Try and /learn
Not anything rule breaking, just something simple to see that it works
But if I make a object (let say A) that act as prototype for another object (let say B). Does that mean that invoking objectB.prototype.someVariable is equal to objectB.someVariable if someVariable is defined on objectA?
yes
just to avoid confusion .prototype actually isn't the prototype. :-)
Is it not the reference to the object which created it?
no, that's actually constructor
Every function comes with a prototype property, which is an object with a constructor property pointing back to the function.
19:29
I haven't read much about constructors yet
The function itself is a constructor. :-)
I am just trying to re-program my head to understand this prototype thing instead of classical classes
I guess it is just a much more simplier model.
It's very simple. But the way it's implemented in js (with functions acting as constructors) is unintuitive
var a = {}, b = {property: 1};
a.__proto__ = b;
a.property === b.property;
How would you organize your applications in terms of your own prototypes? In Java you would make a own class named Car with all its properties and methods....do you make own files with prototypes in JS as well?
You can do that using prototypes as well, the only thing you cannot really do is multiple inheritance
19:34
But you can't do that in Java either so I am not used to do that :)
But is it the common way of organizing your application? Having common prototypes in their own files, or are there a own JS way of doing it?
function Car(color) {
  this.color = color;
}
Car.prototype.boastColor = function() {
  alert("I am " + this.color);
}

new Car("red").boastColor();
That's how basic inheritance's done.
@Witiko IT WORKS
At least based on my local tests
So object oriented programming in JS doesn't differ much from classical way of doing it, but instead of defining classes you just make objects, and those objects acts as archetypes/prototypes for other objects?
@Zirak I can finally sleep again. :-)
The code is awful, but it works!
19:39
@Pjotr Indeed, it's a much more simple, but very dynamic approach.
@Pjotr It does differ a lot from classical way of doing it, it's just that ecmascript 3 (ecmascript === javascript) provided a java-like way of doing it.
@Zirak why, run it! :-)
Yes
It looks like java but it doesn't quack like java
Indeed, the stuff with functions acting as constructors
Prototypal inheritance is just the chaining of prototypes on objects.
19:40
Not just. A whole bunch of others. Now try and /learn something simple (remember it's now !botname, not @botname)
Multiline supported?
I dunno
Try one-line first
!Zirak /learn {"name" : "greet","input" : ".*","output" : "Hello, $1!"}
@Zirak /learn {"name":"greet","input":".*","output":"Hello, $1!"}
!Zirak /die
okay...unforseen problem
SO chat encodes stuff, so "name" turns into "name"
What is this?
19:44
I'm making a chat bot :D
oh, the output will work now
Forgot to reset it from local testing
@Pjotr, wait a sec, I'll get you a great article about prototypes. :D
Damn it...I'll have to make a look-up table for decoding
4
Q: Unescape HTML entities in Javascript?

Joseph TurianI have some Javascript code that communicates with an XML-RPC backend. The XML-RPC returns strings of the form: <img src='myimage.jpg'> However, when I use the Javascript to insert the strings into HTML, they render literally. I don't see an image, I literally see the string: <img sr...

First answer
Ugly, but gets the job done
@Witiko cool
I thought of doing that, just wanted to see if there was another easy way first
19:51
@Pjotr Didn't think I would find it, but voila: steve-yegge.blogspot.com/2008/10/universal-design-pattern.html
Actually, this is super risky
Someone might inject a script tag with something
@Witiko Should I read all of it?
you can always sanitize
If you like
You could send the bot a <script>alert('trololol');</script> and it'll execute
I think I'll stick to just rewriting quotes and colons
@Pjotr: There'S a section talking specifically abt prototypes. But the article overall makes for a good read. :-)
19:53
I will read it
thanks
Yeah, Steve Yegge is awesome. Read that article some time ago, a really good one, worth every minute
@Pjotr Just Ctrl+F for The most specific event
But as I said, it's worth reading
I g2g for some time. The bot's running, feel free to (ab)use it
!Zirak /die
@Witiko I'm dead!
19:56
Alright!
I hate you
Is the /learn working?
:D
Nope
!Zirak /die
There, re@Witiko Could not process input. Error: Property 'die' of object #<Object> is not a function
muakaka
Now it can't die!
19:57
It's an undead bot alright :D
!Zirak /resurrect
@Witiko Invalid command resurrect
!Zirak /die
@Witiko Could not process input. Error: Property 'die' of object #<Object> is not a function

« first day (436 days earlier)      last day (4737 days later) »