« first day (427 days earlier)      last day (4521 days later) » 
00:00 - 17:0017:00 - 00:00

12:00 AM
eih
 
@ircmaxell I thought you were done for the day?
 
I am home
 
Anyone of you guys can tell me why my DateTime stuff doesn't work?
http://stackoverflow.com/questions/8541466/getting-first-last-date-of-the-week/8541481
Am I doing it wrong? Isn't it possible?
 
@ircmaxell Do you want to write an API for a LinkedList of some sort?
@PeeHaa Looking at it now, no promises.
 
hehe. np. Thanks in advance
 
12:09 AM
not really right now
 
@PeeHaa I get warnings on the ones with week 50 in it. "Failed to parse time string (last day of week 50) at position 12 (w): The timezone could not be found in the database in /code/3hBLqI on line 13"
 
peehaa how long you have to get it right?
googled it and got the following: you might have a go at it :
Getting the first day of the week is basically straight-forward once you know the trick. Each day of the week is represented by a number from 1 to 7, with 1 being the first day of the week. Given any day of the week, to get back to the first day, you simply have to subtract from the current day the number of days equal to the day of the week then add 1 day.

For example, if today is the fifth day of the week, to get back to the first day, subtract 5 days from the current day and then add 1. So, if today is '09/01/2005', a Thur
 
@LeviMorrison hmmm strange. it works on codepad. http://codepad.org/NnqZTDxc
@LondonBoy as long as it takes :) I could go the way of calculating it myself. But I would like it if this was possible
 
@PeeHaa I also get the same correct dates, despite the warning.
Which PHP version are you using?
 
12:17 AM
@LeviMorrison 5.3.3
 
peeha your answer is here :))
 
@ircmaxell Do you think we should include a SinglyLinkedList and DoublyLinkedList in our datastructures? If yes, should they use an interface/base class for the common details?
 
@LeviMorrison lemme try it on 5.3.8
 
2
Q: Finding First day of week via php

Future King Possible Duplicate: Get first day of week in PHP? Hi, I want to find first and last date of current week and last week. Similarly I want to find first and last date of current month and last month. This has to be done in PHP. Please help.

they already answered
 
@LondonBoy nopez it isn't :)
 
12:18 AM
whats wrong there?
 
@LondonBoy I need to use DateTime otherwise the world will end in the year 2038
 
@LondonBoy PeeHaa wants the first day of the week based on an arbitrary date.
 
so you want something beyond 2038 :))
 
yup
and also what @levi said
 
@LeviMorrison Not sure. On one hand, there appears to be a bit in common between the two. But then the other hand is that there really isn't enough in common to have in the same tree
 
12:21 AM
ok :)) i will have a look at it tomorrow i want to sleep early today :)
 
@LondonBoy that's ok
 
good night all & Charles :)
 
@LeviMorrison I get the following results on both Win 5.3.3 as Linux 5.3.8:

2011-12-01
2011-12-01
2011-11-30
2011-11-30
What version produced the correct results on your machine?
cya london
 
What is "flag weight" on SO?
 
@Ozbekov How well they pay attention when you flag something.
Higher is better.
 
12:26 AM
How high can it get?
 
7xx ish
 
ah
I've flagged something for the first time, I've just noticed it on my page
 
@PeeHaa Actually, they don't. I just noticed something: you are modifying the same date. Make a new one instead.
 
@CharlesSprayberry good night
 
@LeviMorrison when making new dates I get:
2011-12-01
2011-12-17
2011-12-31
2011-12-17
:P
 
12:31 AM
Same.
I think the format for week 50 is incorrect.
It's expecting a timezone according to the warning.
 
12:43 AM
@LeviMorrison HA! I think PHP just isn't as smart as I thought it was.
I can now at least get the correct first / last date of the current week:
$date->modify('Sunday this week');
$date->modify('Saterday this week');
not sure where to go now to get it by weeknumber though
 
12:57 AM
@PeeHaa You might actually have to make a date and add weeks to it.
 
1:07 AM
Does anybody here use Doxygen?
 
1:20 AM
@CharlesSprayberry I have.
 
@LeviMorrison Can't seem to get namespaces to properly document. Was wondering if you knew of any reference material outside of the doxygen site?
 
@CharlesSprayberry I haven't gotten namespaces to work properly either.
 
@LeviMorrison At least I know its not just cause I couldn't figure it out :P
 
1:34 AM
hi all, a good way to manage a db? Singleton class or instance of db class every time?
 
@LeviMorrison thanks for your help with my date issues! :)
 
@Zorb Don't use the singleton, mate.
Use dependency injection.
 
@LeviMorrison what is exacly "dependency injection." ?
 
@Zorb Research it, mate. It's definitely worth your time.
 
@LeviMorrison thanks
 
1:48 AM
as i can see dependency injection use multiple instance (for example of db class) across the project. this is not bad to have multiple istances so multiple open database connections?
 
@Zorb Who says it has to be multiple instances? You can inject the same database connection to any number of objects
 
@CharlesSprayberry the "right way" is to instantiate once the db class once at the top level and then pass it to used classes which will pass that reference down to sublevels?
 
@Zorb That is the basic principle
Reasons not to use Singleton: 1) You're just encapsulating global state, global state is bad. 2) The code calling the Singleton is now tightly coupled to that Singleton. 3) It can make unit testing more difficult.
 
@CharlesSprayberry never think about this approach, very interesting, .. but i have to create db connection on every page passing user, pass and so (or create a kind of DbHelper with this data to be included in every page) ?
[it sounds like a stupid question :-)]
 
does this make sense?
for($i = 0; $i <= $num; $i++){
	return $pdf->Cell(0,5,$cards[$i],0,0,'C');
}
 
2:01 AM
@Zorb I'm not sure what would be the best way to do this for you, it is really going to depend on your architecture
 
say $num = 2
 
@Purmou No
 
what about it doesn't make sense?
is there no return in PHP?
oh, should it be return($pdf->blah);?
 
Well, one your loop is only going to run once...assuming the conditionals pass on first check
 
how so?
 
2:03 AM
As soon as it runs it will return, this looks like a for loop bastardized into a conditional structure
 
is there a better way to accomplish what I'm doing?
 
Well, I really have no idea what you're trying to do.
 
i need to write $pdf->Cell( etc. for each value in the array $cards
 
What is $pdf and what does $pdf->Cell() do?
 
it's an FPDF instance
Cell just makes a new line
well
it's like a div but for a pdf document
$pdf->Cell(0,5,$cards[$i],0,0,'C');
 
2:05 AM
Do you have some kind of documentation for FPDF? I don't see it on php.net
 
this means make a new cell that is the width of the whole line, line-height is 5mm, content is $cards[$i[, border is 0, and is centered.
 
yes, but what do you mean make a new cell? Why are you trying to return the value? What is the calling code expecting this function to do?
I don't care about the technical details of what it is doing in the PDF
 
essentially i'm writing a new line in a PDF document generated with PHP
 
What is the function supposed to do
 
it's supposed to get the array $cards
 
2:07 AM
Does it return the line to be written? Does it write the line itself?
 
it should return $pdf->Cell(); for each value in the array
so if there are two
it should write two new cells
 
So, you want an array of $pdf->Cell() return values?
 
not an array
 
How else would you like to return multiple values?
 
that's what the for loop was for :P
 
2:09 AM
I see that the for loop is to turn some cards into the $pdf-Cell() call
From the look of the documentation $pdf->Cell() does not even return a value
remove return from your loop and it should do what you want it to do
$pdf->Cell() actually writes the appropriate values to the PDF. It does not return the values ready to be written by another function.
foreach ($cards as $card) {
     // maybe we should make these vars so we know what those numbers are
    $pdf->Cell(0, 5, $card, 0, 0, 'C');
}
 
the numbers are consistent
they just dictate the width/height/etc of the line being written
let me try this...
 
No, those arguments don't mean anything to me
 
not to you
 
$pdf->writeCell($x, $y, $card, $height, ...) would be more appropriate
 
what do you mean by appropriate?
 
2:16 AM
Even just using $x $y at least hints that it has some kind of axis
When you look at a function call in your code you should know what the function does just by looking at the call, even 6 months later after you haven't looked at your code.
After you're through with your PDFs and you move on to a new project you will likely forget what those 6 arguments are
 
okay
but why not just put it in a comment?
 
Because comments are prone to misinformation, improper placement and somewhat ignored
Why not just put it in the code?
 
// $pdf->Cell( width, line-height, content, border, placement, align);
well
i'm using those numbers all over the document
do we worry about global variables in PHP too?
global variables where they're not necessary?
 
Global variables are evil regardless of what language you are using
 
so since i'm using them everywhere in the document i'll be forced to use global vars
what do i get out of that?
i'll just put the url to the fpdf docs in comments :P
 
 
3 hours later…
5:23 AM
Please excuse the tests that are failing :) I don't think the SQLite in-memory DB is working on that server.
 
5:56 AM
Man, I love github so much
 
 
1 hour later…
7:19 AM
var display_message="";
$('input:checked').each(function(index) {

var profile_id=$(this).val();
$.ajax({
type: 'post',
url: 'myUrl',
data: data,
success: function(data) {
if(data=="ok")
display_message = display_message + data +", ";
}
});
});

alert(display_message);
alert(display_message);

if($.trim(display_message)!=""){
jAlert("Your birthdate already exits in "+display_message.substring(0, display_message.length - 2)+".", "Bdate");
return false;
}
in this code, i use two alert-box for display display_message variable value. when i run successfully this code, in 1st alert-box i get bla
 
oh god javascript.
I hate everything about Javascript.
 
@Ozbekov why so ?
btw, Good time everyone
 
@OmeidHerat I fail big time when it comes to Javascript. I just can't learn it, makes me angry :-P
It's 2:30 am. I shall sleep.
Good night, y'all
 
how can i look for more than one character with a regexp in php?
 
@Ozbekov Perhaps you need some better resources.
 
7:31 AM
i need to find , and -
i tried this:
 
@Ozbekov Night night
 
$c = preg_split(/\x2D\x2C, $cards);
does PHP regexp follow the same mechanics as JS's?
 
@Purmou /[-,]/
 
i thought it would be that easy
thank you
Parse error: syntax error, unexpected '/', expecting ')'
 
@Purmou its PCRE but I thing you can get POSIX as well.
 
7:35 AM
any idea why i'm getting a parse error?
oh, it has to be in quotes
who would have thought?
 
@Purmou anyone who has read the Documentation. ;)
 
I did read it beforehand, though i just skimmed
as i usually do
still getting the hang of PHP really
but i'm getting better
 
if you want to learn PHP, you should learn to read the Documentation.
 
i always read the docs for anything i'm trying to learn
except regexp doesn't have any really perfect documentation
 
7:44 AM
thanks
 
 
1 hour later…
8:51 AM
youtube.com/watch?v=7KvxOuC7Bhc - machine now is angry
 
Hahahaha
 
mornin
 
morning
 
9:28 AM
morning guys
Question, I am making a website, I want to structure it as follows:
example.com
example.com/category/id-catname
example.com/page/id-file-name
example.com/user/id-user-name
and so on
The thing is, each should have its own programming and scripts, and I'm not sure how to implement it.
Can anyone point me in the right direction?
 
@tereško But not using the webserver, I sure hope?
 
what do you mean ?
 
I hope that you are not using the webserver to rewrite the URLs and instead do it in PHP.
 
what else there is to use ?
how else can i turn http://foo.bar/random/crap into http://foo.bar/index.php?r=random/crap if not using webserver ?
 
9:38 AM
Ah, okay, that is okay
It sounded like you were trying to define individual rewrite rules in the webserver config
You'll obviously need some kind of catch-all rewrite, yes
 
where ? which line ?
 
what line?
 
> It sounded like you were trying to define individual rewrite rules in the webserver config
when did i sound like that ?
 
yes, well I understand that concept
what I mean is, how to structure the app?
do I do it from a single point of entry (index.php only)
or do I use multiple pages and use RewriteRules?
 
single point of entry
 
9:44 AM
Definitely single point of entry ;)
 
well .. no .. limited points of entry : it sometimes makes sense to direct XHR request or CSS/JS file lookups to a separate scripts
 
@tereško I feed CSS/JS files directly, but for XHR. your controller should care of that. Like use a JSON view.
 
there is an overhead when using framework
 
uuuh, just found that: xarg.org/2011/06/php-hacking terrible :(
 
you might not always want that
 
9:47 AM
Look I know I can have something like so
`RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?args=$1 [L,QSA]
`
but how do I program it to match?
 
emm , what ?
 
you mean on the PHP side?
 
I can't grasp the concept (also if you answer me please highlight me with @truth so that I see it)
this is .htaccess
 
var_dump( $_GET['args] );
 
yes, I know
I would get something like
$args = page/id-page-title
 
9:49 AM
So what's the problem then?
 
but how do I apply the specific page scripting?
this is obvioulsy a page
 
i think he wants use to write code for him
 
a simple split() will tell me that
 
@Truth You traek down the $args.
 
@tereško I do not, I am asking about how to structure my pages
 
9:50 AM
ofcourse you get it either from _REQEST or _GET.
 
You can match the URL with a regex and exptract the data from it. Then then run whatever code you want based on that
 
right now i am using a DBManager class as a singleton class,but i have to use two database connection with in a single script..how should i go for it,any suggestion?
 
so that it makes sense progrematically
you don't understand the question :P
 
@fluty "never use singletons" .. how about this for solution
 
@fluty Dependency injection. definitely not instantiating another database inside your objects.
 
9:51 AM
I've read all about design patterns and MVC
I'm just trying to undersatnd the concept behind it, because I can't see how I can fit it to be specific to the case I want
 
MVC is a design pattern.
 
obviously
 
@fluty That is the reason why one shouldn't use Singletons. You first think "I'll never need two DB connections" and thus use a Singleton - and then, well, then you do need two :)
 
@nic
@NikiC that's why you shouldn't use Signletons for database connections*
 
9:52 AM
did you try readin about MVC ?
 
@tereško I did, but the tutorials I have found don't properly explain the concept, just blast you with code
 
tutorial assumed that you can use google , a common mistake for people who write tuts
 
I understand that through the index.php you call for a controller fitting the arguments from the GET statement, then the controller calls for a module to get data, and a view to display it
sadly, yes @tereško
 
@Truth What else would you use Singleton for ?
 
@Truth No, not use it in general. You always think that you can't possibly ever need two of it, but then you do.
 
9:55 AM
@OmeidHerat I like to use a singleton for a Registry class
I pass all the variables in it and thus prevent myself from littering the global namespace
 
thanks nikic and teresko, but in my one controller class,i have to require_once list of model classes and all those classes using DBManager object,if i dnt use singleton then many objects of DBManager will create?
 
@OmeidHerat , if you examine why he should not use singletons , you will understand why you should not use Router::get_route( $_GET['r'])
 
the single Registry instance is then passed to all other objects, and all of them has access to the same exact instance.
 
the root cause will be the same
 
@Truth That creates heavy tight coupling.
 
9:56 AM
@fluty , watch the videos
 
I don't know english technical terms, could you explain what heavy tight coupling mean?
 
@Truth , you get your code tied to the name of the class
 
ok teresko
 
@tereško agree, but using static doens't always means singleton.
get_route could pass a new object every time.
 
@tereško what's wrong with that?
 
9:57 AM
@OmeidHerat but it does mean that you get stuck with name of the class instead of an instance
 
@tereško indeed, unless you do something like $obj->getInjection(something::getNew());
 
@Truth , i pasted few videos for @fluty .. you need to watch them too
now
 
will do
 
I understand what I posted is not good practice, but it has nothing to do with Singleton or Global state.
You can question passing an object rather then primitive data type, but sometimes that level of loose coupling is not possible.
 
10:03 AM
well .. the getNew() is a factory method , which IMO is an antipattern
if you need a factory method ,then you will be better of with a Builder
it makes you write on more line , but you gain additional flexibility in your codebase
 
agree.
or you can just go with $obj->getInjection(new something());
 
well , when you use a factory method , it usually is because you need to do additional manipulations to the object, before you "release" it in the rest of the application
for example , if you are initializing Router/Dispatcher in your application , before adding a Route , said Route has to be parsed
( and , as you cannot do it in constructor , because then you wont be able to write unittests for it , you need to either use a factory method , which executes parse() method on the Route instance , or a Builder class )
 
if you are using a static method, you can not manipulate the object, and also I am not a fun of object manipulation.
tell, don't ask is the way to go !
 
additionally , Cars does not make themselves , why should your object do it ?
 
@tereško Car === Object, Design == Class.
 
10:18 AM
the point still stands
 
$boj->getNew() Yes heaps bad. claas::getNew() is questionable.
but yeah I agree with you.
 
 
3 hours later…
12:52 PM
hello bodies
i temporary need some help about word press terms and taxonomies
 
 
2 hours later…
2:37 PM
@NikiC "store 100000 elements á 24 bytes" #fixme
 
Jon
Hey all :)
Tiny brainteaser for anyone interested:
yesterday I answered this question
0
Q: String with array structure to Array

PiKeyI have string: Main.Sub.SubOfSub And some kind of data, may be a string: SuperData Also I have an empty array: $k = array(); How I can transform it all to this array above? Array ( [Main] => Array ( [Sub] => Array ( [SubOfSub] => SuperDat...

the answer has code that I 've practically written anew a few times, and every time it was bugging me because it didn't look elegant enough and there had to be an elegant solution to the problem
the task: rewrite the code so that it also looks good
after sleeping on it, I finally hit the "right" idea; SPOILER here's my solution: ideone.com/9wJBU
any way of solving it is acceptable; I was after something that doesn't have as much procedural code
 
3:08 PM
someone experienced with code.google.com/p/oauth-php?
 
3:29 PM
@Jon stack instead of recursion (as in your spoiler): stackoverflow.com/questions/8537148/…
basically similar to your original answer, but not using count and array_shift and such but just a plain foreach.
We could start to collect some duplicates, it's asked from time to time. Probably for the FAQ: stackoverflow.com/q/6373457/367456
 
@Jon We get that question quite often, at least I remember answering it about ten times. E.g. stackoverflow.com/questions/8262644/…
@Gordon Thanks, I propably need to set some encoding header
 
Jon
@hakre, @NikiC: I can imagine it being asked a couple hundred times. Thanks for the feedback, I 'll get back to you shortly
 
@Gordon fixed now
 
Jon
@NikiC: Read your completed array mem usage analysis; congrats, very nice work
 
@Jon thanks :)
 
Jon
3:49 PM
@hakre Why unset($rv) at the end? To keep the symbol table clean? I noticed @NikiC's code (which packages stuff in a function) doesn't do that
 
@Jon nikic's code is inside a function, that will clean that up automatically. Mine is plain so I normally add unset to references as a pre-caution when posting code on SO.
 
Jon
I also didn't know that you could take a ref to a not-yet-existing array key without PHP complaining
that simplifies things
 
I remove the reference so that the $target array doesn't have one any longer, otherwise one value would have a refcount of 2.
(or was it one?)
 
Jon
2
 
@Jon I thought so, that's why I posted the example.
It's actually like your answer, just a bit less code.
 
Jon
3:53 PM
I tried var_dump($rv) inside the loop too... it prints a bunch of nulls, that was interesting
 
Because the value is always NULL until set.
The assignment is done after the iteration. Then NULL will be replaced with $value.
$array = NULL;
$array['key'] = 'value';
 
Jon
@hakre I grok that, it's the implication that is interesting
although it's not surprising really because you can do
$a = null; $a['foo'] = 42;
 
yeah, was slow on typing. codepad.org/uBP7D8Iq
:)
 
Jon
it's just that I 've trained myself to never do that, so you kind of forget that it is permissible to cut this corner
 
@Jon personally I won't advocate it. It's bad practice, in my opinion. To create an array key before the array.
 
Jon
3:57 PM
@LeviMorrison: what exactly?
 
This even works with zero length strings: codepad.org/09oqFL9i
 
Jon
@LeviMorrison agreed
@hakre: man, that's just showing off :P
I would really prefer it if PHP crashed in 10 different ways rather than letting you get away with it
 
@LeviMorrison hoi
 
For the fun, it's just if it would be a string like NULL not empty: codepad.org/EWuYCEBv
So I think it's okay to not crash in that edge case.
 
Jon
@hakre: sure -- "crash", as in flash the "cut out the BS and write humane code" sign
now back to your nice and short foreach solutions
I narrowed down what was holding me back to this:
didn't know there was a difference there
 
4:06 PM
@Jon If you access and undefined var or index by ref it is automatically initialized to null
 
Jon
oops, typo in the code (doesn't change things though)
 
You already used that behavior often without realizing ;)
 
Jon
correct is ideone.com/4d8f5
 
E.g. if you write preg_match(x, y, $matches) you are also passing a variable by ref which you did not explicitly initialize
 
Jon
that's a really good choice of example
but
lemme check something
 
4:09 PM
&$b['foo']    :=    &($b['foo'] = NULL)
It's imprecise, but I think you get the idea
 
Jon
yup
it's just that I did not know this for a fact, so while I accepted that the preg_match call should work
 
I think it's this sort of case you can't simulate with ArrayAccess.
 
Jon
I would have been surprised if I 'd tried something like preg_match('/a/', 'b', $foo['bar']['baz']) -- which also works
 
More because of the reference, then anything else, but first offsetSet will be called not offsetGet or so.
 
Jon
OK that was nice so far
 
4:13 PM
@hakre The other way around ;)
 
Jon
now for the bonus points
my recursive solution
function wrap($value, array $keys) {
return $keys ? wrap(array(array_pop($keys) => $value), $keys) : $value;
}
is it actually documented that the first argument to the recursive call will be evaluated before the second? if so, where?
because if this were C++ this would be implementation-defined, so no go
 
@NikiC ;)
@Jon PHP Expression in the manual.
 
-2
Q: Matrimonial website in PHP

Alwin AugustinI would like to know about is there any matrimonial/matchmaking scripts avialable in PHP..? or else some Joomla/Drupal modules will help..?

 
@Jon Seriously?
 
Jon
@hakre sorry, what am I looking for there?
 
4:19 PM
C does not guarantee left-to-right evaluation of arguments?!
 
Jon
@NikiC: I 'm no expert in C. C++ does not.
 
C and C++ is the same for me :P
 
Jon
10
Q: Compilers and argument order of evaluation in C++

RaptorFactorOkay, I'm aware that the standard dictates that a C++ implementation may choose in which order arguments of a function are evaluated, but are there any implementations that actually 'take advantage' of this in a scenario where it would actually affect the program? Classic Example: int i = 0; fo...

 
scary
good that I don't know C(++)
 
@Jon what are you missing?
 
Jon
4:23 PM
just looked it up in the standard (learning how to look things up in the C++ standard is a skill in itself)
8.6.3/9
"The order of evaluation of function arguments is unspecified."
@hakre anything that says "arguments" or "function" in the right context
 
people try my 20 minute twitter senchafiddle.com/#klLlO
 
Jon
it's funny how function wrap as given above works, but if you switch the two arguments around it blows up the stack or something
@NikiC: at least C++ explicitly tells you "do not even try to do that" ;-)
 
Oh my god! Why didn't you tell me sooner?!
 
user50049
4:58 PM
Any of you fine folks familiar with phpDesigner 7? (The editor)
 
@TimPost I only know text-editors as I should
 
user50049
I can't seem to find a keyboard shortcut to delete the current line.
 
00:00 - 17:0017:00 - 00:00

« first day (427 days earlier)      last day (4521 days later) »