« first day (657 days earlier)      last day (4276 days later) » 

12:01 AM
Is it possible to access a variable that's inside of a function if you're not inside of the function? If that really makes sense...
For example this:
Whoops second.
<?php
addFive(1);
echo $m;
function addFive($n) {
	$m = $n + 5;
}
?>
 
@draconis Thank you.
 
np
 
12:28 AM
Anyone used RecursiveTreeIterator?
 
no sir
 
@Alec Be weary of any answer that doesn't involve passing $m into addFive()
 
@Alec you shouldn't
 
i.e. the use of global scope
 
Basically this what what I'm trying to do:
//Database Query
function queryDB($q) {
	$query = "$q";
	$res = $db->query($query);
}
//Database Connect & Query
function connectQuery($q) {
	connectDB();
	queryDB($q);
}
And I want to call on connectQuery with the query in the args, then use $res in my main code.
 
12:35 AM
I have no idea what that code is supposed to do
Why do you have queryDB, a wrapper around $db->query
why not just call $db->query
 
@Lusitanian I want to make it flexible for multiple situations.
 
if that's what you want do though................
function connectQuery($q) { connectDB(); $res = queryDB($q); return $res; }
and in queryDB, add return $res; to the end of it
 
@Lusitanian Just making sure I got this right:
//Database Query
function queryDB($q) {
	$query = "$q";
	$res = $db->query($query);
	return $res;
}
//Database Connect & Query
function connectQuery($q) {
	connectDB();
	queryDB($q);
}
 
you didn't
//Database Connect & Query
function connectQuery($q) {
	connectDB();
	$res = queryDB($q);
        return $res;
}
do that
then when you call connectQuery
$res = connectQuery("SELECT * FROM internets WHERE answer = 42;");
 
Oh, ty.
 
12:40 AM
it's called a return value --- since you weren't familiar with them (a basic part of any programming language) you should probably read more about programming in general to get a better sense of the basic constructs which are similar across languages -- that way, it'll be easier to pick up new languages and understand the concepts at a more fundamental level
 
@Lusitanian I began programming two or three months ago in Java, I've just now been getting into PHP. I recall return, I was just having issues thinking of applying it with PHP. Quite honestly I didn't know you could do return in PHP.
 
Right, and that's my point. It's common across the majority of mid to high level languages
I'm not trying to criticize you at all, of course; but it's always better to learn the basics before messing with databases/etc.
 
Yes, I understand your point.
 
Also, your code implies you are making a database connection per query
 
@Charles I don't really know how to do more than one query per connection.
 
12:46 AM
Well, it appears you are using some procedural code
Instead of connectQuery($sql) you would just query($db, $sql)
Call $db = connectDB(); and then pass $db into the query($db, $sql) as needed
 
@CharlesSprayberry Alright, I'll give it a shot in a bit. Thank you.
 
@CharlesSprayberry actually he appears to be mixing some amount of oop (or at least objects) with his procedural code
 
@Lusitanian Ah, yes, scrolling back up it does appear this way
 
Probably.
 
you still aren't returning the resource inquerydb
also you need access to the $db object
tbh, you shouldn't be doing this the way you are
pick a paradigm and stick to it -- imperative is fine, so is oop
but mixing them gets messy
 
12:51 AM
I've always been a mixer.
 
not something you should do here
 
I don't really understand how something could be 100% OOP.
 
why not?
you've programmed in java...
 
Yes it's all classes inheriting other classes.
 
kinda
everything's an object though, that's the point i was making
php supports multiple paradigms
certainly imperative and object-oriented, and arguably functional (but not really and don't go there anyway :O)
 
12:56 AM
Is it bad to mix 'paradigms' if I'm the only person who's going to be touching my code? It makes the most sense to me.
 
php barely supports functional programming imo...the syntax for it still feels quite clunky compared to any language that decently supports it
 
@Alec yes
though i must say, i'm not sure how it makes sense
@cHao functional programming sucks anyway >:C
i say that just because i dislike it, it has its uses
 
dunno...i kinda like the idea of it, as long as one doesn't get all purist about it
 
I like it because I can call a function and fully connect to the DB and run a query with one line of code compared to 10.
I just do what works.
 
that doesn't make sense, why do you need ten lines of code in any paradigm to connect to a db?
 
12:58 AM
to connect, do the query, and fetch rows? 10 lines isn't outrageous
 
@Lusitanian And run a query. It was just a example, I was over-exaggerating.
 
ah and run a query
10 lines is reasonable in any paradigm then
 
That's just a small example, there could be a large function that does a lot of things too.
 
So?
 
Which you need to call multiple times, instead of re-writing all of that code multiple times.
 
12:59 AM
Right, which you can do with a class method
I'm not understanding your point
OOP is all about code-reuse
 
I haven't touched classes in PHP yet.
 
read about SOLID, DRY
 
@Lusitanian no, it's not.
that's just how the oop zealots sold it
 
lol
fine, it's partially about code reuse
inheritance + traits both promote extensive amounts of reusability
 
i've had maybe 3 occasions where code from one project could work unmodified in another
 
1:01 AM
i'm talking within a project, but meh; where are you going to get that in any paradigm without modifying code at all
anyway the point is mixing paradigms is not an effective or sustainable way to program
In computer programming, SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) is a mnemonic acronym introduced by Robert C. Martin in the early 2000s that stands for five basic principles of object-oriented programming and design. The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time. Overview {| class="wikitable" style="width: auto; font-size: 95%; table-layout: fixed; line-height:1.25; margin-left: auto; margin-right: auto;" |- ! In...
In software engineering, Don't Repeat Yourself (DRY) is a principle of software development aimed at reducing repetition of information of all kinds, especially useful in multi-tier architectures. The DRY principle is stated as "Every piece of knowledge must have a single, unambiguous, authoritative representation within a system." The principle has been formulated by Andy Hunt and Dave Thomas in their book The Pragmatic Programmer. They apply it quite broadly to include "database schemas, test plans, the build system, even documentation." When the DRY principle is applied successfully,...
 
at some level you end up mixing paradigms anyway
 
of course, but doing it forcibly and intentionally is like cutting yourself
and shouldn't be the way anyone starts out programming
 
i mean, oo and functional languages both end up turned into machine code, which is decidedly imperative
 
obviously, yes
so does any program written in anything
 
yeah
 
1:03 AM
besides code written by Jon Skeet
 
so at some point, you have to cross the line
 
right but doing it at a high level in a language like PHP for a beginner intentionally is pointless and harmful
 
dunno...c# does it pretty well with linq
 
code written by Jon Skeet gets executed by butterflies
 
I'd say it shouldn't be done at a high level when you can't explain or don't understand why you're doing it
 
1:04 AM
Okay, it's like this
 
@CharlesSprayberry k, that i can agree with :)
 
if you are writing a book and you jump from the third-person to first-person randomly
without explaining how it happens or why it happened -- or having a good reason for it -- you shouldn't do it
not a perfect analogy, but the best i can think of :P
 
really, though, you ought to be able to understand and explain why you did anything you did in a program
 
Yea
That's definitely true
 
that's a very generalized, excellent way of putting it
 
1:06 AM
I've seen some things that I wish I could have the original developer there to explain wtf he/she was thinking
 
@CharlesSprayberry happens to all of us
 
Yea, unfortunately I'm working in a high wtf/minute code base
 
that's never good... i love the little graphic "the only true measure of code quality is number of wtfs/minute"
3
holy shit Team USA won by 83 points today
 
Yea, I saw that
 
what the hell...no basketball team should win by 83 points
 
1:07 AM
That's utterly ridiculous
 
In my recreational basketball league (i know, totally different setting) I think we won one game by 45 and I felt awful for continuing to score after a certain point lol
I don't know why they'd continue piling it on
but I digress
 
Is there anything wrong if that's the first Basketball score from a game I've heard in 4 years?
As in I pay 0 attention to sports.
 
Probably not, if ya don't care about sports ya don't care about sports. What country are you from?
 
USA.
 
I say play to win all 4 quarters.
 
1:09 AM
@CharlesSprayberry I agree with playing to win, but you can't say that sitting on a 40 point lead isn't playing to win. There's something to be said for rest and injury prevention.
Derrick Rose effectively ended Chicago's season in May when he tore his ACL in the fourth quarter of a game at which point his team had a 16 point lead...
 
@Lusitanian Well, I didn't see the whole game. What if the other team is just that outmanned?
 
It's possible, they played Nigera and I'm not sure how good their team is.
I don't know, maybe I just don't have the competitive spirit of Olympic athletes :P
 
Sometimes I question how big companies like DICE can even keep up with the code in their Frostbite 2 engine. It probably has a lot of source code behind it. With that many people managing/(adding on) to it, I don't see how they remain unconfused.
I mean like, I get confused after my project goes after the 4,000 line mark or so.
 
@Alec by keeping a consistent paradigm and consistent design patterns
4000 lines isn't that big
 
@Lusitanian It is when you're a complete newbie.
 
1:14 AM
Windows 7 is 80 million lines
 
Microsoft also pays their developers per line of code.
 
@Alec I highly, highly, highly doubt that
 
no they don't
 
If anybody is still paying developer per line of code they are idiots.
 
Are you kidding me? That would be the sure-fire way to kill their products.
 
1:15 AM
That's what I was informed.
 
No, they don't.
You'd be hard-pressed to find any company that does
Debian's close to 400 million lines of code holy crap
 
I probably wouldn't work for a company that did pay per line of code. I'll bet the code base is utter balls.
 
I think it would take me 15 years to read through that much code let alone write it.
 
I would never.
@Alec its thousands of developers, they only look at the parts they need to
 
Oh.
 
1:18 AM
A programmer is defined as an inherently lazy unit which converts high amounts of caffeine and pizza into code on a logarithmic scale.
I just thought we'd clarify ;)
 
Probably.
 
Frostbite 2 is a really cool game engine, never seen this before [not a gamer]
 
Yes, I wish they would release a development toolkit for it; but I don't think they have any plans of it.
 
Meh I used to write cheats for the source engine that hooked into the game's virtual memory tables for fun
I had to reverse engineer their little anti-cheat, that was a fun time...
I actually learned more about C++ doing that than reading/anything else
Granted, Valve's coding is a little...flaky...but
 
I tried to get into C++, the Windows API stuff murdered me and I gave up.
So I think I'll stick with Java.
 
1:21 AM
You don't need to use the Windows API in C++, lol
It's useful if you need them
but kills cross-platform *** anyway
*** meaning anything
C++ is probably the most powerful non-(ASM/machine code) language you can use, period.
Flame me gogogogogo.
 
@Lusitanian I do agree, I believe Java is less-optimized since it's running in a JVM.
 
And you have no low-level access to anything...among over 9000 other issues
@ircmaxell I like how you emerged with that image.
 
@Alec ummm... You're kidding with that statement, right...?
 
no...probably not
 
@ircmaxell No, I'm not. It's running in a virtual machine. I doubt that could be anywhere near as optimized as running natively on the computer.
@ircmaxell Sure it's scalable & portable, but from personal experience I don't believe it's anywhere as fast as C++.
 
1:28 AM
no, it isn't -- in anyone's experience.
 
@Alec It can be much faster
the key is running in a VM allows for operations and optimizations that a statically compiled language just can't ever do...
 
so for certain use-cases, C++ can't even touch it...
 
but on the other hand
there are certain cases it gets smoked
 
absolutely
but a blanket statement like I doubt that could be anywhere near as optimized as running natively on the computer or I don't believe it's anywhere as fast as C++ is a downright gross overgeneralization
 
1:30 AM
i have limited cs experience but sort algorithms come to mind
this is interesting: theregister.co.uk/2011/06/03/…
 
@ircmaxell Thank you for proving me and my views incorrect, it's pointed out a lot of things to me in my theories between Java & C++ that are incorrect.
 
The point is that there's no golden solution
 
@ircmaxell totally random curiosity, where'd you go to college?
 
each tool exists for a reason, and has trade-offs...
@Lusitanian I didn't go for CS
 
it seems that so many here didn't
 
1:32 AM
I went for Mechanical Engineering, and switched to Math...
 
math is useful
 
@ircmaxell Do you actually enjoy math?
 
I taught myself much of what I know, and what I didn't teach myself I learned from some of the best I have met...
 
@Alec I like all math besides geometry
 
@Alec Eih, some parts of it. It was less about enjoy, and more about am really freaking good at
 
1:33 AM
@ircmaxell I am going to major in CS most likely
simply because there's nothing i'd rather major in :P
 
just realize that CS won't teach you anything that you'll need in the real world
I'm not going to say it isn't useful, just that what you really need to know to be a professional will be completely left out
 
so i've been told and surmised for myself -- i have a certain family member who totally disagrees with that but..meh
 
@ircmaxell "can't ever do" is a pretty gross generalization in itself, considering most if not all VMs are written in those statically compiled languages
 
@cHao he said certain things
not everything
nevermind you're right
 
@cHao well, not as the statically compiled binary. Sure, you can build a VM inside of a statically compiled language, but then the result is not statically compiled anymore...
 
1:36 AM
can you provide a concrete example -- not that i'm doubting, just curious
 
perfect, thank you
reads
for the record, though; the Boost format library (which i use in C++ over sprintf)
is somewhat faster (not incredibly so)
and the spirit libraries which use tpl meta programming extensively are fast as shit
and there's no template metaprogramming in java or python
 
@Lusitanian CS teaches you a lot of theory, and a lot of abstract stuff...while it could help a bit with understanding what's going on behind the scenes, it has very little to do practically with actually sending HTML to a browser
the places where it'd be useful...that's pretty much already been done
 
I know that: it'd still be interesting to learn
 
yeah
i wanna take one of those classes where you get to build a compiler :)
 
1:41 AM
I figure that college isn't going to teach me much that's useful for the real-world unless I want to be a professor
Everything I know related to computers and programming, I've picked up on my own and from a few people I know
learn better that way
gotta go though
 
i still don't quite get parsing, lexing, code generation and that stuff...i mean, i kinda sorta get it, but it's hard to really nail down without practice and a bit of guidance from somebodywho really knows how that stuff should be done
 
why not try to do it yourself based on what you already know?
take a simple, really small language, and build a compiler for it...
 
cause i have a habit of biting off more than i can chew...lol
 
which is why I stressed really small
 
what's worse is, i have other stuff i have to do...so once i get stuck, i end up putting it on the back burner
and eventually forget about it
then start all over again, and run into the same thing
if i were taking a class, there'd be that time that's already set up, and when i get stuck i have someone to ask
 
1:48 AM
Fatal error: Call to a member function query() on a non-object in /home2/pinkfluf/public_html/dv0nx/functions.php on line 13
function queryDB($q) {
	$query = "$q";
	$res = $db->query($query);
}
It hates me.
 
$db is not defined
 
Where is $db coming from?
 
Oooh whoops, I defined it in a different function in database connect.
Yay, I got it working. Thanks guys.
 
2:04 AM
Is it best to use SHA1 or MD5 for encrypting passwords?
 
28
Q: SHA1 vs md5 vs SHA256: which to use for a PHP login?

NMoneyI'm making a php login, and I'm trying to decide whether to use SHA1 or Md5, or SHA256 which I read about in another stackoverflow article. Are any of them more secure than others? For SHA1/256, do I still use a salt? Also, is this a secure way to store the password as a hash in mysql? functio...

 
wuzaaaaa !?
 
@Steve Thank you.
 
@tereško what does that mean?
 
you must be 15 or 16 , if you don't know
 
2:20 AM
17*
wuzaaaaaaaa?
 
Does anybody know why this regex isn't matching? codepad.viper-7.com/1p2Djy I'm not that great with regex but it seems simple enough, I'm stumped
 
@CharlesSprayberry /+[A-Za-z]/ matches 1 or more slashes followed by a single letter then a slash.
oh, new picture. hello Charles
 
Hello
And yes, that led me to the right solution. I should have tried it earlier, regex is still a little confusing to me at times.
 
i'm in that boat...
whatever happened to reviewmycode.com
 
2:31 AM
thank you for that :)
 
Somehow I think if I posted there I would instantly have -300 rep.
 
@Alec You don't necessarily get down voted just because you have bad code. That's the point of the site, to review code so that it isn't as bad as before you asked. It is more about how you ask the question and keeping the scope of the review appropriate.
I've found that a lot of the battle in any programming related endeavor is keeping the scope as small as possible.
 
Oh, I thought it was one of those 'time to brag about the code I wrote' sites.
 
No, I think it is more about Stack Exchange's overall mission. To make the Internet, and programmers, better.
 
@CharlesSprayberry Oh, well I can't lie. Stack Overflow has greatly improved the way I communicate with other programmers, and is beginning to improve the way I write my code.
 
2:36 AM
@rdlowrey Warning: stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages: error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol in /var/www/temp/oauth/Artax/src/Artax/Http/Client.php on line 113
:)
 
user895378
@Lusitanian how recently have you cloned the latest?
 
not very -- though i do believe it's simply because i didn't specify a port in the uri
going to clone now
 
user895378
@Lusitanian Wait two minutes -- I'll ping you. Need to push a fix.
 
To use SSL do I have to buy one of those pricy $70/yr SSL supportive things with GoDaddy?
 
okay, thanks :)
@Alec if you want SSL on your site, but they're like ten bucks now
or you can make your own cert
 
2:38 AM
Don't use GoDaddy
 
I don't know who else to go with that I can trust.
 
they lure you in with half-naked danica patrick
cough you can't trust godaddy
the world's best domain squatters
 
you can't trust GoDaddy, so...
 
I haven't had any issues with GoDaddy.
Who should I go with then?
 
user895378
@Lusitanian Okay -- pushed. Some fresh new awesomeness. Get it while it's hot. It will automatically add necessary ports and whatnot for you, so just specify your URI with https://www.bank.com and you're all set. Also, the requisite "Host" header is specified for you if missing, so you don't have to worry about that unless you want to set it explicitly.
 
@rdlowrey nice!
( ! ) Notice: Array to string conversion in /var/www/temp/oauth/Artax/src/Artax/Http/StdRequest.php on line 345
this is presumably something i'm doing wrong though
though even if it is you should catch it :D
$msg .= ' HTTP/' . $this->getHttpVersion() . "\r\n";
nevermind...
 
user895378
@Lusitanian mmm ... maybe not. I just wrote that code and haven't unit tested those few lines yet. Lemme check.
 
no
your commit just didnt go through
i pulled too quickly after you pinged me
 
user895378
lol
 
i take that back, still getting the error
lets see
nope
git submodule is completely borked thats all -- wth
Honestly, I'm not even sure if this is a problem with my submodule or your code. I just completely deleted the submodule and recloned and am still having an issue, but git might be working some voodoo shit on me so hold on
 
user895378
2:46 AM
@Lusitanian oh ... welcome to early submodule usage ... things can get hairy updating them at first. Do you mind sending me the specific URI that's causing you problems so I can mess with it?
 
    public function getAuthorizationEndpoint()
    {
        return 'https://accounts.google.com:443/o/oauth2/auth';
    }

    public function getAccessTokenEndpoint()
    {
        return 'https://accounts.google.com:443/o/oauth2/token';
    }
those two
specifically the accesstokenendpoint one
 
user895378
lol I was looking at line 345 in StdResponse and not StdRequest ... I was like, "HOW IS THAT ERROR MESSAGE POSSIBLE?"
 
rofl
i hate it when i do that
 
user895378
yeah, you definitely have an old version of the repo because that file only has 328 lines currently :)
 
what the
 
user895378
2:49 AM
best bet is to remove the submodule entirely as outlined here and re-add it.
 
i just recloned it -- still 373 lines
outside of a git repo
 
user895378
it may not be available on github yet. Let me see what happens when I clone the read only
 
user895378
I'm just making things up now.
 
what? lol
 
user895378
2:52 AM
Not on purpose. I don't even know what I was looking at when I thought the file was only 328 lines.
 
user895378
Give me a couple of minutes and I'll fix the issue though.
 
okay, great!
 
user895378
You are specifying your request like this, right? (forthcoming)
 
user895378
$request = new StdRequest('http://example.com', 'GET', $arrayOfHeaders);
 
yes, let me give you the precise line
$request = new StdRequest( $this->getAccessTokenEndpoint(), 'POST', [], http_build_query($parameters), [ 'Content-type' => 'application/x-www-form-urlencoded', 'Host' => parse_url($this->getAccessTokenEndpoint(), PHP_URL_HOST)] );
wait...
did you change the constructor
 
user895378
2:56 AM
yes:
 
oops.
 
user895378
__construct($uri, $method, $headers = array(), $body = '', $httpVersion = '1.1') {
 
user895378
Time to add strict type checking for $body and $httpVersion :)
 
user895378
And $method
 
that explains it :P
 
user895378
2:57 AM
sorry, stuff like that won't change anymore.
 
no problem
now i'm getting a 411 length required -- do you not automatically calculate content length?
oh no that's just because i had the old version
wait no it isnt - wow i keep backtracking on what is ay
 
user895378
I'm going to auto-fill that header as well in just a minute.
 
yeah that and host are the two i generally expect autofilled :d
i'll do it for now to test
okay...now its loading infinitely after i added that header...again, this is probably on me
 
user895378
@Lusitanian define "loading infinitely" ... you mean like sitting there forever with no output?
 
correct
that's the term i use...very scientifically correct obviously
it's the same issue as when there was no host header it seems
this worked just fine before you switched to sockets actually
so i'm not sure what the error is
 
user895378
3:06 AM
I think I found the problem -- just a sec :)
 
btw...you use strlen for your response length plugin which is correct, but that'll completely break if someone has mb function overloading on
since content-length is number of bytes, not characters
so you might want to do an ini check for that setting
and great, thanks
 
user895378
@Lusitanian good call
 
i'm putting it in your bootstrap file / will send a PR if you want
 
user895378
@Lusitanian You aren't adding the request body on a GET request are you?
 
no, it's a POST
 
user895378
3:11 AM
okay, just making sure.
 
user895378
This may take a few minutes, but I'm working on it ...
 
no problem, i'm [somewhat] patient
I sent a PR for the mbstring check, do with it what you will; not sure where it should be but just so the issue is listed
I'm going to get off the computer and go to bed, so I'll verify that everything works tomorrow evening
night
 
user895378
@Lusitanian Cool, yeah it's fixed but not pushed. I'm going to write some unit tests between now and then to avoid future issues.
 
sounds good
thanks much
 
user895378
3:29 AM
Ugh, why anyone would overload the string functions is completely beyond me. It's a terrible idea and I'm tempted not to subsidize it ... but I'm going to do so anyway.
 
user895378
3:51 AM
On second thought, you'll just have to get a big fat error message if you try ...
 

« first day (657 days earlier)      last day (4276 days later) »