« first day (919 days earlier)      last day (4255 days later) » 

22:01
> For Windows users I'll show you how to get a basic Ubuntu Linux system up and running in a virtual machine so that you can still do all of my exercises, but avoid all the painful Windows installation problems.
**WARNING: Do Not Use An IDE**
> An IDE, or "Integrated Development Environment" will turn you stupid. They are the worst tools if you want to be a good programmer because they hide what's going on from you, and your job is to know what's going on.
> Maybe you've learned Prolog and you think the entire world should just be a database that you walk around in looking for clues.
^^ lol
really good writing
turtles. why don't run turtles over my screen?
@hakre can you rephrase that ? :P
22:23
@kaᵠ I think there's truth in that statement. And zealous lunacy. But truth as well...
performance question in PHP:
@hakre lol
Is it faster to define a static variable with an array or to check for NULL on first call and assign it then?
Or is this a memory question?
user652649
@Jimbo did you use this ( paypal.com/cgi-bin/… ) for the button creation? should work... main problem in your code is "_s-xclick" -> "_xclick"
user652649
evening
22:30
So the decision is between:
function fooZoo() {
    static $array = array('...');
    # ...
}
/*** and ***/
function fooZoo() {
    static $array;
    $array || $array = array('...');
    # ...
}
@hakre first is faster, as the assign becomes a no-op
I tend to say the later does not have any benefit.
so no JMP tokens
sorry, yes jmp tokens
no jmpif tokens
also the memory must not make much difference, because for the second the data must be still in memory, right?
compare:
line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
   4     0  >   FETCH_W                      static              $0      'array'
         1      ASSIGN_REF                                               !0, $0
   6     2    > RETURN                                                   null
with
line     # *  op                           fetch          ext  return  operands
---------------------------------------------------------------------------------
   9     0  >   FETCH_W                      static              $0      'array'
         1      ASSIGN_REF                                               !0, $0
  10     2    > JMPNZ_EX                                         ~1      !0, ->6
         3  >   INIT_ARRAY                                       ~2      '...'
         4      ASSIGN                                           $3      !0, ~2
22:32
okay, looks fair.
So next question. If you look into the array, you can see it is a map. ordinal value as index to a character (actually the ascii codes).
Basically that array is a variant of this string: 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-._~'
ok...?
If I prefix the string with a space.
I could use strpos
instead of doing the lookup in the array with isset()
@ircmaxell yes, there's a fair share of truth there. Learning programming with an IDE is not efficient learning, while using an IDE after you know programming is almost a must.
I don't use an IDE, and I like to think that I know programming :-P
3
@ircmaxell you can't be serious, at least notepad++ ?
22:36
@hakre What exactly is wrong with ord() ?
Sublime Text, Netbeans and VIM, but with autocomplete and type-ahead (IDE features) turned off
the only "ide" feature I use is syntax highlighting and error detection
@hakre the array should be faster, but you're talking slight differences at this point
@DaveRandom nothing.
@ircmaxell yes the one was just concerned about the assignment to a static and this now is about the lookup.
@DaveRandom ord() is plain wrong!!! he's talking about optimizations, that would require a function call to each character needed (every time he needs it) a precomputed array is the way to go
well, no, what I mean is that the array lookup is O(n log n) where the strpos is O(n), where n is small (in terms of complexity at least), meaning not measurable
@ircmaxell I use Geany, 120 char limit bar, coloring, autocomplete (my own long variables too) and function parameter hints, why would you turn off autocomplete?
@hakre what's the usage?
22:42
@kaᵠ the usage is to find out if an triple-encoded (percentage encoded exactly as in url-encoded), such a triplet is within the range of unreserved characters.
@hakre eg. ? and why reinvent the wheel?
@kaᵠ what do you mean?
@hakre not sure i got it, have an example?
%5a is normalized to Z while %5b is normalized to %5B
22:46
@hakre but you need hex there, not ascii dec
@ircmaxell You don't know about RII I guess ;)
That is autocomplete in PHPStorm and you just typed RecursiveIteratorIterator.
It's a really useful kind of autocomplete.
@kaᵠ no clue what you mean. maybe you can show where I re-invent the wheel (show me the wheel), so I can use that instead?
@hakre your array has the index 90 for Z (i mean it has decimal indexes) and urlencoded chars are hex (hex 5a = dec 90). does that make sense?
@zerkms I updated it earlier today :)
I go back and forth between literally 20 to 30 different environments. if I muscle learn typing things like that, it will make my life worse, not better.
@kaᵠ sure, but how do you find out if 5a is an unreserved character or not?
@ircmaxell depends. it maps pretty well, but it's good to program in a bare editor from time to time.
maybe not specifically line-editing mode, but just without anything around incl. syntax highlight.
22:54
@hakre can't you just rawurlencode(urldecode($str)); ?
@hakre not sure how you're doing it now, but you could have hex indexes for your allowed array
oh and not to forget - the internet switched off.
@hakre my brain is what limits me anyway... so
@DaveRandom I also thought about that, yes. let's try.
@DaveRandom rawurlencode( urldecode($str) ); :D
@DaveRandom hmm, rawurlencode() also encodes ~ in PHP 5.2.x and earlier which is an unreserved character.
and that version is under support for that lib.
but there is a userspace replacement because of that flaw in PHP.
I will take it for the moment until this needs optimizations.
@hakre maybe php.net/manual/en/filter.filters.sanitize.php ? can be of some use?
thanks @DaveRandom!
@kaᵠ nope, my character classes are not covered, also ctype_* is crap here because of locales plus these classes are not covered.
@hakre np - although if you're really intent on the user-space impl then preg_replace() with a static lookup table array from the ascii-hex form to the decoded form is probably your best bet (since you are presumably using PCRE to find the target elements anyway)
hexdec()ing the encoded form is pointless
23:03
yes, I also was sniffing preg_replace, but this is already inside a callback for normalization of the triplets.
I wanted to do both steps at cone: case + unreserved.
instead of hexdec I though about using sscanf($urlenc, '%%%x', $ord);
@ircmaxell so you went the Jon Skeet way: "Jon Skeet does not use revision control software. None of his code has ever needed revision." via this
but I go now with two function calls. that is also doing the normalization and it somehow feels good.
@hakre you sure it's worth optimizing this little bit? how many urls are you going to normalize in a row?
@kaᵠ in a row? I have no clue, but this library is intended for widespread use.
23:07
a
most users don't do URL normalization, however those who need this deserve something that covers at least the RFC if the class is announced to be based on the RFC.
I could see some uses where this micro-optimization would be handy, not sure by how much
yes, probably micro optimizations ;)
at least not only to scratch my own back^^
and tests pass.
user1125394
23:23
possible to do a double IN sql query?
user1125394
my table have a composite key, and want to select a group of pairs
Vin
Vin
Can anyone please tell me the steps to get JSON data from another website's api to my web server? Many thanks in advance
who ever setup 3v4l.org that guy deserves more than a beer.
@Vin what have you tried? which terms have you searched for? what went wrong with the approaches you took so far?
user1125394
23:26
it's not a real double IN, it would be WHERE (col1,col2) IN ((1,2),(1,14),(2,3))
slightly related: whathaveyoutried.com
@c'c good question. you are talking about a product here, in your case IN matrix
also related: google.com
user1125394
@hakre ah not the cartesian product
lol @igorw lmgtfy also?
user1125394
23:26
need the strict keys
Vin
Vin
@kaᵠ Many thanks.
user1125394
ah let's do a php loop on col1 keys
@c'c this is simple: WHERE col1 IN (1,2) AND col2 IN (2,14,3) - Mysql wil make use of the compound index, use explain so that you get the order right (for the benefit of the index)
Vin
Vin
@igorw I tried for ages to do it all client side using javascript only to realise its not possible because the api in question doesn's support cross-origin requests or JSONP. My life would be made much simpler if it did.
23:29
@igorw not to forget to mention: the internet (in general)
user1125394
@hakre wow if that actually do what I need
@hakre you had that 'the internet' line starred up high for some time :)
@c'c AND - it's logical. It's not "and and or" or "or and and" or something like that. It's AND (and only AND).
@kaᵠ what? where? when? - you mean the three Ws of WWW?
Apr 19 at 20:52, by hakre
(hint 1: it's in the internet)
user1125394
@hakre yes logic handy since order doesn(t matter WHERE col1 IN (2,1) AND col2 IN (2,14,3)
user1125394
23:33
thanks
@c'c yes in IN order does not matter.
also in SQL most time order does not matter.
you only add ORDER BY at the end to give back in order.
The rest is data only, not ordered.
@igorw new vid ^^ (very short this time :D)
@Vin that's already a start, next step would be actually searching for solutions. for instance, "php request json api" yields a pretty good description of how to do it.
23:36
Evening everyone!
morning !
heja!
Guys, why I can read uploaded tmp_name text files with file_get_contents, but not image files?
what do you get @Eugene ?
null
23:38
you sure images get saved?
Have you tried turning it off and on again? :P
WAT?
indeed, what is the value of $_FILES['foo']['error']?
@igorw No error
yes, each f*ck*n* dictionary has the term GIT in.
GIT is super marvelous.
can you dump the whole _FILES array?
also, what does file_exists of the tmp_name give you?
23:40
@Eugene but you can verify the image is actually saved on the server?
How can such a sane person like @Gordon say GIT is not (at least) loved?
lol
@igorw Yes. tmp_name gives value
and error is == 0
@igorw yes
Vin
Vin
23:41
@igorw thanks
@Eugene please define image files
0 =>
        array
          'name' => string 'VPN_CONFIG.png' (length=14)
          'type' => string 'image/png' (length=9)
          'error' => string '0' (length=1)
          'size' => string '57711' (length=5)
          'tmp_name' => string '/tmp/phpRoUVSO' (length=14)
          'content' => null
      1 =>
        array
          'name' => string 'IMG_12112012_204751.png' (length=23)
          'type' => string 'image/png' (length=9)
          'error' => string '0' (length=1)
          'size' => string '137729' (length=6)
@Eugene you mean !empty() == value? in "gives value" ?
hi @Jocelyn!
@hakre I mean, that file_get_contents( ...['tmp_name'] ) gives null when it is an image file
@Eugene file_exists returns true?
23:43
@Eugene 'content' is not part of $_FILES by PHP, so I assume the array has been modified?
@hakre yes
@Eugene the (image)type is not allowed by any chance?
@Eugene Take care with that. Not that we all have done this here or there, but it's playing with PHP's famous global static state, so it's sometimes calling for the demons. (just say'in).
because what's happening there is you image doesn't actually get saved
@kaᵠ easily said. I don't see file_get_contents() returning NULL documented. Do you?
23:45
the fact that error and size are strings also seems fishy to me
but maybe they just are that way
@hakre here:
array
  'attachments' =>
    array
      'name' =>
        array
          0 => string 'VPN_CONFIG.png' (length=14)
          1 => string 'IMG_12112012_204751.png' (length=23)
      'type' =>
        array
          0 => string 'image/png' (length=9)
          1 => string 'image/png' (length=9)
      'tmp_name' =>
        array
          0 => string '/tmp/phpuI8hNw' (length=14)
          1 => string '/tmp/phpvpNNRv' (length=14)
      'error' =>
        array
          0 => int 0
          1 => int 0
@hakre seems logical to do so with an existing empty file
@kaᵠ empty file; existing = empty string ("")
@hakre No I haven't changed $_FILES array, this is another array
@Eugene ok.
23:47
@hakre or that
@hakre only reading from $_FILES array
@Eugene you mean the last print_r, right? (ack style)
@hakre yes, not print_r -> var_dump (xDebug)
@Eugene how's your receiving code look like?
so both give you NULL on file_get_contents() within the same request?
@kaᵠ $_FILES is not tainted. receiving code is PHP.
23:49
@hakre what do you mean both? If I do file_get_contents( $_FILES['tmp_name'][0] ) I will get null. Have no clue why. When trying same with text files, works fine.
@hakre trying to follow the breadcrumbs...
@kaᵠ sure, we all do, always (unless we know).
@Eugene what gives var_dump($_FILES['tmp_name'][0]); in case of an image.
Stream (chrome, firefox): protonradio.com:8000
@hakre ?
@Eugene just some music
@hakre ou. okey
@hakre here
var_dump( $_FILES['attachments']['tmp_name'][0] ); exit;

string '/tmp/php6uT2YU' (length=14)
23:57
read+write permissions ?
@kaᵠ why would that matter? There should be at least read permissions and reading is what I'm trying to do.
@hakre nice jam

« first day (919 days earlier)      last day (4255 days later) »