« first day (841 days earlier)      last day (4109 days later) » 

2:00 PM
STOP RUINING THIS FOR ME!
 
@OctavianDamiean Yeah, I know
 
Fixed the answer though. It is beyond me how twelve people could up-vote it without fixing it.
 
!!/choose something nothing
 
@rlemon Both!
 
Hahaha
 
2:01 PM
@rlemon lol I barely got it
 
physically impossibru chatbot
 
@rlemon nothing
 
haha third day in a row the bot commands lazieness from me
will do bot man!
 
hey, I'm working on split screen on my laptop, is there any way to make the chat look reasonable on ~400 px horizontally?
 
2:02 PM
That's what took me so long to figure it out, these avatars are tiny, until you scale them up
 
remove the sidebar
 
I removed div id='widgets', seems to help
 
@BenjaminGruenbaum Split it in two pieces, and rotate the part with the chat room by 90°.
 
Yeah, bitch.
:P
@BenjaminGruenbaum Could just remove #sidebar
 
Why are you guys posting images of two pugs all the time? :D
 
2:04 PM
Leaves only the chat itself
 
removing '#sidebar' and changing main from 70% width to 100% width did the trick :) Also removing user image and SO logo
ty
 
Does this have any meaning -> width=device-width in the viewport
if I use it iPhone 5 does not show web app in full screen
so can I remove it
 
So I've got this: pastebin.com/bCCcxyd2 which is supposed to replace any word in the string that starts with $ to "var". It only works when called once, though and in the current situation I cannot use regexes because I need to identify the value of that word.
 
I readed it
but @rlemon I couldn't find the answer there. I know I should use the width=device-width
but that causes iPhone5 problems
 
2:15 PM
@lawn use regex, javascript regex has back reference
 
bah
 
@BenjaminGruenbaum I need to do an array lookup for the word(s) that start with a $.
 
if you can do it without regex it would often be much much faster
 
@lawm, string.replace with a regex first parameter and function second parameter lets you do this, see the example at mdn
!!> mdn string.replace
 
@BenjaminGruenbaum "SyntaxError: Unexpected identifier"
 
2:17 PM
whoops
 
@rlemon So this was my solution: pastebin.com/bCCcxyd2 but it only works when called once.
lol fail
 
@BenjaminGruenbaum
(function() {
  var sb = $('#sidebar'), m = $('#main');
  sb.hover(on, off);
  off();
  function on() {
    sb.css('right', '-0%');
    m.css('width', '70%');
  }
  function off() {
    sb.css('right', '-25%');
    m.css('width', '95%');
  }
}());
@lawm give me an input and expected output please
 
Okay here's where it's called: val = replaceVars(val);
 
and val is?
"$1 $2 $3" you want var 1 var 2 var 3?
 
2:18 PM
@lawm, please read the API first, this is doable with string.replace
 
@BenjaminGruenbaum he doesn't want to do it with string.replace
regex is stupid
 
@rlemon Anything like "$foo bar $baz" replace with "var bar var"
 
@rlemon because he wants to keep track of what he found, it's a regex one liner and it's very simpler
He said he didn't want to use regex because he needed a reference to the match, this is possible in javascript
 
I want to access it from an array though.
 
function replaceVars(val) {
    var splitted = val.split(" ");
    var done = "";
    for (i = 0; i < splitted.length; i++) {
        if (splitted[i].charAt(0) == "$") {
            splitted[i] = "var";
        }
        done = done + splitted[i] + " ";
    }
    return done;
}

console.log(replaceVars("$foo bar $baz")); // var bar var
 
2:20 PM
@lawm I don't want to spell out the answer for you, please see the example in mdn and if you don't figure it out after you read it and try for yourself I'll help you figure it out. I can assure you String.replace is the easiest way to do this
 
I don't get what doesn't work.
 
I got this from yesterday: return val.replace(/\$[a-zA-Z]+/gi, "var");
But I want to have a value that changes depending on what the $ sign word is.
 
val.replace(/\$[a-zA-Z]+/gi, function(match){
  //here match is what I found in the text that matches the pattern
  //the return value of this function is what I replace it with, this is a normal JS function
 //it can change your 'done' variable and so on
});
 
can any one help me in posting a question . it's saying your question does not meet our quality standards
 
@rlemon Yes but try adding another console log to it. Can our bot run it?
 
2:23 PM
@vamsi did you read the FAQ?
 
!!> function replaceVars(val){var splitted=val.split(" ");var done="";for(i=0;i<splitted.length;i++){if(splitted[i].charAt(0)=="$")splitted[i]‌​="var";done=done+splitted[i]+" "}return done}; console.log( replaceVars("$foo bar $foo"), replaceVars("$foo bar $foo") );
 
@rlemon "SyntaxError: Unexpected identifier"
 
bah
 
can't understand i tried some of the methods they have given @BenjaminGruenbaum
 
@rlemon Does it always say that?
 
2:23 PM
@vamsi, did you read the stackoverflow FAQ?
 
@BenjaminGruenbaum If I have "$foo bar $baz" I might want to replace it with "goo bar bat", it's not a static value.
 
@lawm which is what the function callback is for,
 
@rlemon Where can I find console output? Chrome dev tools?
Got it
 
you can implement a tokenizer that checks all the values yourself like @rlemon suggested or you can use the one the language already has to offer in its built in methods. I like not repeating myself when I can but some people don't like regular expressions, both options are valid
 
2:26 PM
@rlemon Wait but isn't this the same exact thing as my original code?
 
yup
lol
which is why I was asking..
@BenjaminGruenbaum for mundane tasks like this regex is magnitudes slower.
 
Indent four spaces to create an escaped <pre><code> block:
@BenjaminGruenbaum what's this ?
 
and a lot harder to read and maintain
 
@rlemon But If I call "val = replaceVars(val);" a second time it returns nothing!
 
idk I changed the code because I didn't like yours.
 
2:30 PM
@rlemon I believe in optimizing when I have to. It's not harder to read it's actually easier in this case, it's a lot more semantic to do
 
mine works.
 
myString.replace(/match/,function(match){
   //here disclosed is my entire logic of what I do with the match
});
instead of
var strArr = myString.split('token');
for(...){
   if(my variable matches another condition as a token){
     //exact same logic as the callback of the String.replace method
   }
}
 
@rlemon can you help me out ?
 
@vamsi nope
busy battling regex
 
@rlemon :fine
 
@BenjaminGruenbaum lol. writing optimal code is a practice every programmer should take.
 
@rlemon it is a lot more important to write readable code than to write optimal code
 
spending hours micro optimizing is pointless - but to work some optimizations into your best practices should be a responsibility
if you can't understand key token then you should start maybe trying to get that?>
instead of using sub optimal regex for tasks that key token are better suited for
 
I've written parsers for programming languages before -_- I understand the concept
I just don't agree it should be used here
 
so why bastardize it in js
 
2:34 PM
readable and maintainable code is a responsibility, as far as I care you write code that is slow as you want as long as it is not the bottleneck
 
@rlemon Okay I'll try it.
 
ok. regex is never more readable but w.e
you have a strange idea of readable and maintainable
 
@rlemon maybe you should look into it, I was on agreement with you before I had to practice regex
 
I have. in depths.
 
Anyone want to offensive flag something to destruction?
 
2:35 PM
and I stand by my statement.
 
Do you know why mine wasn't working though?
 
I'll use regex to perform simple string manipulation statements just like you use query selectors to do DOM manipulation instead of iterating through the DOM myself
 
I don't use query selectors
they are stupid
 
Helloooo?
 
so if you want to choose all the elements of class "a" that are a descendant class "b" and are divs what do you do :)?
 
Oops! Your question couldn't be submitted because:

Your post appears to contain code that is not properly formatted as code. Please indent all code by 4 spaces using the code toolbar button or the CTRL+K keyboard shortcut. For more editing help, click the [?] toolbar icon. @BenjaminGruenbaum
 
@vamsi indent all your code by 4 spaces using the code toolbar
 
can you eloborate ? @BenjaminGruenbaum . this is my first time
 
@rlemon wants me to agree with him. Regular expressions are slow, people!
 
@BenjaminGruenbaum I structure my code so I never have to do a lookup that requires selectors.
 
2:41 PM
(Seriously, they are)
 
also not [human] readable
 
@rlemon, you mean your html?
 
@BenjaminGruenbaum and/or my js
 
Would you say ".b div.a" is not readable? I find it very readable
 
seriously.. how can people say they need selectors.. they sure do make life easier and devs lazier but they are surely never required
@BenjaminGruenbaum selectors !== regex
selectors are readable. we use them in CSS all of the time.
 
2:42 PM
I meant selectors in js
 
QSA is not slow per-say. but it is slower than the alternative.
js selectors are css selectors implemented in QSA / QS
 
so you are not arguing that css selectors are bad practice in JS?
 
I don't use them. I don't see a need for them. but i'm not arguing them.
makes people more productive and doesn't hinder readability
regex on the other hand is slower, AND hinders readability.
 
user986408
map/draggable question:
i'm implementing a draggable worldmap (fullscreen) using 800px x 800px large tiles .. therefore unless the windows resolution isn't science fiction it should render 9 tiles (should be enough - the rest is going to be loaded on the fly when dragging) -- this would make a 2.400 x 2.400 box which is getting dragged around.
would it be more performant to use smaller tiles (256x256) like google because this would minimize the total size of the whole container altough it would be more tiles in the end ?
 
there are cases where you cannot get around it - or it does make the most sense.
a mundane operation like this is not one of them
all I have been arguing ^^^
 
2:44 PM
There are many language features that are there for convenience, you don't need a lot of the features JS or DOM has to offer.
 
eval is very convenient. should we use it?
innerHTML as well.
 
@rlemon some rare times, yes.
 
just because it is there doesn't mean use it! :P
 
I wouldn't consider regular expressions bad practice though I am aware of their downfalls, just like javascript :)
 
ok so you agree rare cases - so why does regex not follow this same ideology?
ok now you're just being silly.
 
2:46 PM
I would rather use a feature when it makes my code better, I think eval mostly makes my code worse and regular expressions make my code better when used correctly
you can argue that regular expressions are not semantic and I'd argue that there are a lot of cases they are
moreover, I think that implementing an iterator/tokenizer over words is code repetition since the language already offers such a tool through regular expressions that does not require me to repeat myself
I would never use regular expressions to perform complex operations, I think it is exactly those simple cases that they should be used.
 
yea well. fact is you are wrong. @lawm don't use regex for this if you want to do it right.
 
@rlemon Here's my version that works too: jsfiddle.net/tt6qR
 
Just because I don't agree with you doesn't mean I'm wrong
 
and now i'm off to game. this conversation isn't even constructive anymore.
 
I haz a question!
 
2:48 PM
@rlemon it was never constructive, it was just interesting :)_
I love arguing
 
Wasting time is fun isn't it?
 
especially when I have to study
plus it's not a waste of time doing something you love :)
 
@BenjaminGruenbaum but your arguments make no sense and are wrong. regex is readable to almost no one - so "you" know it. big whoop - I do as well. I would still rather read 4 lines of code dealing with arrays for key token than a fucking regex.
 
I have been in the "I have to study" phase for about a week now
 
and from my experience most other devs agree with me
 
2:50 PM
Any of you played Antichamber yet?
 
no one likes reading regex. and in this case it's also slower.
so win win for loops
 
@rlemon your code implements logic that the language has to offer built in, if you're in the business of string manipulation you should use know at least basic regular expressions.
 
His argument isn't that one shouldn't know how to use regular expressions
 
@BenjaminGruenbaum again, pointless argument: The language allows me to do this less readable and slower - but in 3 less lines - YES I MUST DO THIS
 
It's that you should pick the correct time to use them, i.e. when they are faster, and more readable than other methods
 
2:51 PM
@AmaanCheval and my argument is that in this case they are more readable, and that speed is not a concern in this case
 
and my argument is that in this case they are not more readable.
 
@rlemon Look at this: jsfiddle.net/tt6qR/1 it only executes once!!! I have proved it!!!
 
I don't agree about them being more readable
The speed, with the kinds of optimizations done now, probably don't matter in this case
 
Versus this: jsfiddle.net/tt6qR
 
think parsing an email address.
in js would be a PITA and in regex would be a PITA - in regex and js would be hard to read and maintain - but in regex would likely be much much faster.
win: regex.
 
2:53 PM
@AmaanCheval they are more readable in some cases, there are times when regular expressions are a horrible option, I just don't believe this is one of them
 
Hang on a sec
 
actually, in the case of email addresses most regular expressions I've seen get it wrong and most code that splits by '@' gets it right :)
the spec is very misleading, for example a@a is a valid email address
 
Devil's advocate
@Loktar would like you :P
 
I'm not devil's advocate, if anything I am agreeing with him that regular expressions should no be used in a lot of cases where there is more than basic logic involved
 
@rlemon Look at this, it only works once: jsfiddle.net/tt6qR/2
Somebody!
 
2:56 PM
The problem with regex is that it introduces a new layer of logic, when I use regex what goes through my mind is 'is this worth it', specifically in @lawm 's question I think it is since it is a fairly simple regular expression that performs a task otherwise I would have to implement tokenization and matching myself, both of which regex does for me.
 
Enough with the argument, why is this only working once? jsfiddle.net/tt6qR/2
 
In the case of email I'm not saying parsing it with regex is a bad idea, just that most regular expressions I found online to check email do it wrong, which might reflect on the amount of logic required to get it right, which might in turn suggest in the case of email regex is not a sure thing.
 
JUST... ClICK... ON... IT... jsfiddle.net/tt6qR/2
Ah got it nevermind
 
and in either case I don't agree with @rlemon that optimization should be a concern just like I don't write my for loops from n to 1 instead of from 1 to n or that I don't cache an array's length when iterating over it
 
Nope it's stil a problem.
 
3:01 PM
lol so your excuse is : I do a bunch of known bad practices that are commonly avoided and just mark it up to: why micro-optimize.
 
Hi people, any quick regex for this ? "id_1_ul"... I want to check if a tagname matches the pattern id_anynumber_ul, id and ul are always the same. Thanks.
 
That said, I think @rlemon raises a valid argument in both cases, that not everybody knows or understands regular expressions and that they introduce logic into the code. My entire argument stands on the fact in @lawm 's code it is surely worth it. As it is in a lot of cases of string manipulation
 
we as developers shouldn't spend hours micro optimizing - but if a faster known solution exists and it is nominal time/effort to implement we should always do so
period.
 
@rlemon using regular expressions for simple string manipulation is not bad practice. Writing code that is more semantic but slower in a place that affects nothing is not bad practice
 
no arguments.
no exceptions.
 
3:02 PM
I completely disagree, readable code triumphs over faster code 97% of time
 
and regex isn't readable.
god you are a troll.
 
would you say that /\$[a-zA-Z_]/g is not readable?
 
@BenjaminGruenbaum yes
 
well first it would be : /\$[\w]+/gi and no I do not think it is
err. i is not needed
 
So I have a for loop that has a function that executes every time. Will the loop wait every time for the function to finish executing?
 
3:04 PM
then this is what we disagree on :)
 
just used to typing it
@lawm depends.
 
@rlemon Without a return
 
what does the function do
does it spawn a timer or an xhr call ?
 
@rlemon No.
 
then should
 
3:05 PM
But there's a lot of code in the function.
This is so weird. In jsfiddle.net/tt6qR/2 it works but in the rest of my code it doesn't.
Do you wanna have a look at the entire thing?
 
Is this regex \id_[0-9]+_ul\b good enough for matching id_1_ul , or do I miss something? "id" and "ul" are always the same, the number could be 0 to 999... thanks.
 
@MrSimpleMind change + to {1,3}
 
What does this do? It's loading slow as hell
 
@lawm showing you that the loop waits
 
3:09 PM
@rlemon oh
 
@BenjaminGruenbaum thanks Benjamin, but if I use + it will take any numbers from 0 to max... right? is your {1,3} only for 3 digits? thank you
 
id_[0-9]+_ul should work for those cases - if you want to {1,3} that will limit the results to being 1 to 3 numbers
{1,3} will fail if the number is 4 digits but will pass from 0 to 999
 
Ok thanks ppl!! appreciate your help!
 
Oh well, already back :) .. I dont know whats wrong with this.. e.id.match(\id_[0-9]+_ul\b)
 
3:15 PM
BTW @rlemon I don't like the fact you're calling me a troll just because I don't agree with you, I raised valid arguments you are (obviously) entitled not to agree with but I would appreciate if if you did not try to refute them ad hominem
@MrSimpleMind is it possible your slashes are inverted?
 
no I call you a troll because your arguments don't make sense.
 
Does anybody want to test the rest of my code to see what's wrong with it?
 
And with that! I'm out!
 
you don't agree with them, that does not mean they don't make sense. They make perfect sense to me along with quite a few coders I know
anyway, I would appreciate if you avoid doing that in the future :)
 
libssh2 is driving me crazy
@BenjaminGruenbaum don't be offended for being a troll, just say he is instead!
 
3:25 PM
I'm not offended :) I just appreciate coding practices arguments being about coding practices and not about questioning someone's sexual preference or a parent's profession
 
heh
at least you didn't reach godwin's point :P
btw, what's the website to generate pretty images of your code again?
 
Hitler hates regex
 
ah right, thanks!
 
3:32 PM
Okay. I think I can prove it now. Why is this only working once in the loop? jsfiddle.net/tt6qR/3
(the loop at the bottom)
 
@lawm your code works as expected
your variable i is global
javascript has no block scope for loops and conditions
your loop only executes once because you're changing i in replace var, which btw you wouldn't have had to think about if you were using a regex :P (though thatin itself is a poor argument)
 
Okay... soo... how can I fix this?
 
change i=0 to 'var i=0'
 
@BenjaminGruenbaum Which loop?
 
that will declare it in the scope of the current function, or the global scope when running globally
@lawm, both, read about variable scopes in javascript, and about hoisting while you're at it.
getting a specific piece of code to work is a lot less important then learning the language
 
3:37 PM
Yay!
Thanks a lot!!
 
PHP has some nice functions
like get_defined_vars()
 
I strongly suggest you check out String.replace , even if you agree with rlemon you should know what your options are. Also you should acquire an understanding of the language
 
I wish there were this in C++
 
@FlorianMargaine as far as I remember php has 9 different functions to sort an array :)
 
3:39 PM
yeah
the API is not really consistent with itself
but at least, you can say that you're not going to miss something :P
having a lot of functions is not a problem
 
what use case have you found for get_defined_vars?
 
debugging
var_dump(get_defined_vars()); // <- and you know everything
 
when I asked what the way to do something similar in javascript people here got mad at me and told me I don't understand function scope :(
 
those people suck
although it depends on js
the debugger is really easy to fire up
 
turns out you can do _parent_ in some js implementations to get the context you're in
 
3:41 PM
not the same for PHP
 
yeah, there are ides that let you debug php as far as I recall
I think phpStorm does anyway
 
yeah, there are
it's just way less convenient the browsers' built-in debuggers
 
so for js, just use the debugger; it's cheap & quick
 
I think javascript still has a long way to come in terms of testing though
I really miss interfaces
 
3:43 PM
for php, var_dump(get_defined_vars()) is a quick way
 
@BenjaminGruenbaum why?
 
I can't define a construct that lets me validate that my data is of a certain type
 
typeof/instanceof isn't good enough? also, why do you need to validate this in the first place?
 
It allows me to do two things. One, validate data, I can know what something is which I currently have to do manually. Second of which it defines a contract
typeof is broken, instanceof makes me define classes which I think is a mistake
a language that makes me define my own variable types is somewhat broken
 
3:44 PM
I don't understand why defining a contract is really important
typeof can be fixed
 
just like I don't do int a but var a and let the language figure it out, I don't want to do that for classes either
 
then why do you want to define a contract?
 
let's say I'm working on a project with 10 other people, and we're making pieces of code that need to interact with eachother
I would like to work with a defined API of what the code I'm importing can and what it can not do
I would also like to be able to validate that objects I get for this code abide to that API
 
you don't need an interface for this
 
interfaces let me do that
 
3:46 PM
why do you need to validate this? you don't trust the other developers?
 
yeah, I miss interfaces :)
 
user986408
has anyone a tip on how to improve this prototype in webkit? .. in firefox the draggable is quite smooth .. mt111102.students.fhstp.ac.at/draggable/game.html
 
@FlorianMargaine first of all no, of coruse not. I don't even trust my own code which is why I write a lot of unit and integration tests
Second of all, even when I do I still need to work with an API as clear as possible
coding to an interface and not an implementation is very important, the behavior of different models needs to be strictly defined
I might use (by mistake) a method that another code wrote but did not intend for me to use externally, and he might end up changing it thinking I'm not using it
but more importantly I need to be able to know what I'm working with, I don't care how he wrote is code as long as it behaves the way I expect it to behave, which is what the contract promises me
 
please, I need some help here: stackoverflow.com/questions/14670456/…
 
3:50 PM
I agree that it's useless in projects that are relatively small, but in large projects it's a PITA to not have
 
I don't see how an interface is supposed to enforce this. If it doesn't work, it throws errors right away
 
If what doesn't work?
 
if the interface doesn't do with you expect it to do
 
which is great
I would like to know right away
I would like to find errors as soon as possible
 
Any reason why this returns undefined? (splitted[i] is "$foo") and the vars array contains "foo"
        splitted[i] = splitted[i].substring(1);
        var index = vars.indexOf(splitted[i]);
 
3:57 PM
then we're getting in the compiled/non compiled argument
 
OOH! OOH! I HAVE OPINIONS!
 
and honestly, I found the compiled languages mostly longer to program in, i.e. you have to do more stuff to get it working, so in the end you don't really gain somethng
 
@lawm It works for me. Fiddle/CodePen/whatever we're using now?
 
i wake up with a question in my mind : "how do i get an element offest().right" ?
 
"mostly", this is where I think CL shines again :P
 
3:59 PM
@SomeKittens hang on....
 
do you know?
 

« first day (841 days earlier)      last day (4109 days later) »