|
Thread Rules 1. This is not a "do my homework for me" thread. If you have specific questions, ask, but don't post an assignment or homework problem and expect an exact solution. 2. No recruiting for your cockamamie projects (you won't replace facebook with 3 dudes you found on the internet and $20) 3. If you can't articulate why a language is bad, don't start slinging shit about it. Just remember that nothing is worse than making CSS IE6 compatible. 4. Use [code] tags to format code blocks. |
On July 20 2014 06:10 berated- wrote:Show nested quote +On July 20 2014 04:48 Manit0u wrote:On July 20 2014 00:45 berated- wrote:On July 19 2014 23:39 Manit0u wrote:On July 16 2014 05:46 sob3k wrote:I' trying to make a MEGA basic contact form that mails an address with the info from a form. I've been using PHP. Here is the form. Is this ok? Anything I need or don't need here? <form action="jmailscript.php" method="post"> Name:<br /> <input type="text" placeholder="Name" name="name"><br> Email:<br /> <input type="text" placeholder="Email" name="email"><br> Phone:<br /> <input type="text" placeholder="Phone" name="phone"><br> Property Address:<br /> <input type="text" placeholder="Property Address" name="address"><br> Property City:<br /> <input type="text" placeholder="Property City" name="city"><br> Property State:<br /> <input type="text" placeholder="Property State" name="state"><br> Property Zip:<br /> <input type="text" placeholder="Property Zip" name="zip"><br><br> <button type="submit" name="submit" value="Submit" class="button" data-type="text" id="submit-btn">Submit</button> </form> How would I make a super unsafe simple PHP script to mail an address this info when submit is pressed? I've tried several copy pastes with various levels of complexity and I can't get it to work. I understand very basic PHP syntax and the functions used but I'm clearly not understanding the scripts fully. Also I just learned that apparently you just cannot test mail() on a local server such as Xampp (this could explain some of my failures)? If I just upload it to my domain will that work? I just want someone to ask a few pointed questions about what certain things are doing. EDIT: OMFG I did it. very simple when I figured it out this is my script: <?php $name = $_POST['name']; $email = $_POST['email']; $phone = $_POST['phone']; $address = $_POST['address']; $city = $_POST['city']; $state = $_POST['state']; $zip = $_POST['zip']; $from = 'From: My Site'; $to = 'myemail@gmail.com'; $subject = 'Property Information';
$body = "From: $name\n E-Mail: $email\n Phone: $phone\n Address: $address\n City: $city\n State: $state\n ZIP: $zip";
if ($_POST['submit'] { mail($to, $subject, $body, $from); echo "Submission Accepted!"; }
?> Follow up, how would I adjust things to include the script on the form page you it doesn't take you away from the form? Why are you doing this in pure PHP? If you want pretty bare-bones PHP then go with PHP MVC microframework. Select the advanced version which will give you access to awesome Twig templating engine and Sass for easier styling. And do your forms this way, much easier and you can simply put your script in the controller: http://symfony.com/doc/current/book/forms.html Generally we need to walk before we run. I'm thinking someone that just figured out a mailto might be a tad overwhelmed with phpmvc and sass. HTML and CSS you can grasp on a basic level in an hour. PHP MVC you can get the gist of in about 30 minutes (the entire "tutorial" for it consists of just 5 images and explains pretty much everything you should know). It's much better to get into MVC environment early on, as well as more advanced CSS wrappers (like sass or less) and templating engines. It not only prepares you for more advanced stuff (like jumping to a full-stack framework, regardless of programming language) but also makes it way more enjoyable in the beginning since it turns some of the boring stuff that requires a lot of simple code into more managable and easier to write/read/understand parts. With PHP I think that you don't get much out of learning pure-PHP. I'm now working as a PHP programmer and I can tell you that practically no one ever uses pure PHP or even PHP code in the views. That's why I suggested php-mvc to him, it's easy to get into since there isn't much of the overhead and it'll let you learn the basic principles behind pretty much every single web project and framework. Sure, I could suggest something like Laravel, where you can have a full app running in 15 minutes and 3 lines of code, but that would be detrimental for someone just learning the ropes. The sooner you start learning the proper way of doing things the better and if you can actually use tools that provide an additional layer of abstraction it's even better because it lets you think more on "what I want" rather than "how do I need to do it". Expressiveness is very important. Yeah -- I probably should have just left it alone. We all learn at different rates. I often find that the people I have worked with have jumped too quickly into a web framework and then miss the base understanding of how request/response/sessions work. They understand the framework but then when they need to modify something about how it might work then there is no idea of even where to start. How long did it take you to get to the point where you no longer use base php?
About 2 months or so. I can hardly imagine working on a web project without ORM and all the other cool things. It's just way more convenient when you get an extra abstraction layers and tools that speed things up and make it more human-readable.
The hardest thing to grasp in PHP right now is how much it has changed recently. Most online tutorials usually don't have the newest stuff in them. The inclusion of namespaces, traits and lambda expressions was the biggest thing, but there were a lot of other novelties added. Most frameworks also don't incorporate all the changes. That's where plain PHP has an advantage, you get to learn and use the newest toys (although frameworks are slowly catching up).
|
Hyrule18904 Posts
Most web hosts don't have the newest version at release though. I couldn't play with lambdas on my host for a few months (but having your own servers helps in that regard). Raw PHP is also used a lot when working with legacy code. Being dependent on a framework can hurt you. And I think people should learn how to do all that silly tedious stuff before they jump to something that does it for them so that they know what's going on under the hood.
|
On July 20 2014 22:42 tofucake wrote: Most web hosts don't have the newest version at release though. I couldn't play with lambdas on my host for a few months (but having your own servers helps in that regard). Raw PHP is also used a lot when working with legacy code. Being dependent on a framework can hurt you. And I think people should learn how to do all that silly tedious stuff before they jump to something that does it for them so that they know what's going on under the hood.
I mentioned that. That's also why I suggested php-mvc. It's raw PHP just using the MVC pattern, which you want to learn anyway regardless of what language or framework you plan on working with. The advanced version adds only Twig and Sass to the mix so you're still doing your entire backend in plain PHP but get extra tools for your views which is nice. Especially that both Twig and Sass aren't that separated from what they wrap around (PHP and CSS), you still get to do the exact same thing but with more expressiveness allowing you to save a lot of time.
Example:
PHP
<?php echo $var ?> <?php echo htmlspecialchars($var, ENT_QUOTES, 'UTF-8') ?>
Twig
{{ var }} {{ var|escape }}
and it also let's you do amazing stuff with loops
{% for user in users %} {% if loop.revindex == 2 %} Almost there! {{ user.name }} {% elseif loop.last %} Last listed user: {{ user.name|upper }} {% else %} {{ loop.index }}&emdash;{{ user.name }} {% endif %} {% else %} No users have been found. {% endfor %}
And for the styling:
CSS
#main { width: 97%; }
#main p, #main div { font-size: 2em; }
#main p a, #main div a { font-weight: bold; }
#main pre { font-size: 3em; }
SASS
#main { width: 97%;
p, div { font-size: 2em;
a { font-weight: bold; } }
pre { font-size: 3em; } }
I can't speak for others, but for me discovering such tools was a life-changing experience.
|
Is there any way (at least in C#) to create an interface that with implemented methods (that may or may not provide virtual-like? that can be called from the "interface")?
if it isnt clear, this is kinda what i mean
http://stackoverflow.com/questions/20279843/interface-implementation-and-common-function
you can have an abstract class implement the interface and implement the concrete class, but the problem is then i want my concrete to derive from another abstract/concrete class (like delegates in obj-c?)
|
What is the most the most efficient way in R to get values from a table. By which I mean I have a list of ID's, I have a table in which there is one column with each ID exactly once, and one column with the number that belongs to the ID. So now I want in my big list, with multiple occurences of the ID's, I want to add after each occurence the number from the table.
I use now lapply on the ID's and a function that indexes on the ID and returns the number, but I have the feeling this lapply function is not so efficient, it takes a long time to compute. Does somebody know a more efficient method?
dummy data: ID 1 1 2 1 2 3 ...
table ID Number 1 384835 2 435393 3 239493 ...
|
|
time to read documentation
CURSES. I HAVE TO LEARN.
was hoping there was something that existed that i just couldnt recall
i actually hate microsoft documentation after i've been spoiled by android docs. so jelly.
|
Wait what, were you not trying to do multiple inheritance? Which would not really be possible in C#, but chances are you could use composition (put the common method into a class that is not part of the inheritance hierarchy, but used by both classes).
|
So lately I'm having this idea of wanting to make a simple 2D jump & run game, but no clue where to start. Could someone please point me in the right direction? What's the best practice if you want to approach something like this?
I'm an application developer for 11 years now and have very good knowledge about a lot of programming languages (mostly C and C++ though), but I don't have the slightest clue about things like OpenGL or if there are any (free?) good 2D engines out there already.
A while ago I played around with the XNA framework, but that's about it. Pretty much lost on choosing the best way to start.
|
On July 21 2014 16:18 Blisse wrote:Is there any way (at least in C#) to create an interface that with implemented methods (that may or may not provide virtual-like? that can be called from the "interface")? if it isnt clear, this is kinda what i mean http://stackoverflow.com/questions/20279843/interface-implementation-and-common-functionyou can have an abstract class implement the interface and implement the concrete class, but the problem is then i want my concrete to derive from another abstract/concrete class (like delegates in obj-c?) Either you give up on inheritance in one of those cases and instead use composition, or you can possibly have extension method over the interface, but only if many special conditions about the nature of that "common functionality" are satisfied. But in general the answer is no. Sometimes it would be useful, but most such cases can be solved by going different route and introducing only slight "ugliness". If you have more details about the exact requirements it might be possible to make this general answer somewhat more specific.
|
On July 23 2014 04:40 PandaCore wrote: So lately I'm having this idea of wanting to make a simple 2D jump & run game, but no clue where to start. Could someone please point me in the right direction? What's the best practice if you want to approach something like this?
I'm an application developer for 11 years now and have very good knowledge about a lot of programming languages (mostly C and C++ though), but I don't have the slightest clue about things like OpenGL or if there are any (free?) good 2D engines out there already.
A while ago I played around with the XNA framework, but that's about it. Pretty much lost on choosing the best way to start.
http://www.libsdl.org/
|
|
On July 21 2014 19:14 MelChizm wrote: What is the most the most efficient way in R to get values from a table. By which I mean I have a list of ID's, I have a table in which there is one column with each ID exactly once, and one column with the number that belongs to the ID. So now I want in my big list, with multiple occurences of the ID's, I want to add after each occurence the number from the table.
I use now lapply on the ID's and a function that indexes on the ID and returns the number, but I have the feeling this lapply function is not so efficient, it takes a long time to compute. Does somebody know a more efficient method?
dummy data: ID 1 1 2 1 2 3 ...
table ID Number 1 384835 2 435393 3 239493 ... Can you clarify what the goal is? I think from what you've said, and using that sample data, that the output would be:
ID Number 1 384835 1 384835 2 435393 1 384835 2 435393 3 239493
Is that correct?
|
On July 22 2014 02:08 spinesheath wrote: Wait what, were you not trying to do multiple inheritance? Which would not really be possible in C#, but chances are you could use composition (put the common method into a class that is not part of the inheritance hierarchy, but used by both classes).
I don't believe composition is the idea I want here because it doesn't make sense in terms of modelling the system. I'll explain below.
On July 23 2014 04:48 mcc wrote:Show nested quote +On July 21 2014 16:18 Blisse wrote:Is there any way (at least in C#) to create an interface that with implemented methods (that may or may not provide virtual-like? that can be called from the "interface")? if it isnt clear, this is kinda what i mean http://stackoverflow.com/questions/20279843/interface-implementation-and-common-functionyou can have an abstract class implement the interface and implement the concrete class, but the problem is then i want my concrete to derive from another abstract/concrete class (like delegates in obj-c?) Either you give up on inheritance in one of those cases and instead use composition, or you can possibly have extension method over the interface, but only if many special conditions about the nature of that "common functionality" are satisfied. But in general the answer is no. Sometimes it would be useful, but most such cases can be solved by going different route and introducing only slight "ugliness". If you have more details about the exact requirements it might be possible to make this general answer somewhat more specific.
The extension method seems to work, but that's a bit unclean in my eyes.
What I want to build is a generic logging extension for classes, so that other classes can subscribe to the output of the logs. The problem I have then is that I want the functionality of the logging extension to the encapsulated in the logging class, but interfaces don't allow me to do that. In my derived class, I want to call methods on the logging extension, so the subscribing classes receive output.
If I did it via composition, it would look like this, create an ILogger interface with a GetLogger property to get a logger class. To subscribe to the event I cast the derived type to the ILogger, then subscribe to a handler from the GetLogger, and to raise a log I call a method from GetLogger.
My main problem with this method that all my derived classes have to have a Logger member object that is never used, whereas I just want to be able to call the inherited ILogger class. Is that clean? Because I feel like there's another way of approaching the problem.
At this point in time I'm more interested in cleanliness than getting it done.
|
On July 23 2014 08:32 Manit0u wrote:+ Show Spoiler +On July 23 2014 04:40 PandaCore wrote: So lately I'm having this idea of wanting to make a simple 2D jump & run game, but no clue where to start. Could someone please point me in the right direction? What's the best practice if you want to approach something like this?
I'm an application developer for 11 years now and have very good knowledge about a lot of programming languages (mostly C and C++ though), but I don't have the slightest clue about things like OpenGL or if there are any (free?) good 2D engines out there already.
A while ago I played around with the XNA framework, but that's about it. Pretty much lost on choosing the best way to start. http://www.libsdl.org/
On July 23 2014 10:10 Nesserev wrote:You could also go for SFML (http://www.sfml-dev.org/), and get a copy of this book (through any means necessary) to guide you through the process of writing a 2D game: SFML Game DevelopmentActually, the game that's 'developed' in this book, is a 2D vertical scroller airplane game, so it handles everything that you need to know to make a solid 2D jump & run game. Thanks, both suggestions look quite promising. I'll check them out in detail when I get home.
|
|
On July 23 2014 12:01 Blisse wrote: What I want to build is a generic logging extension for classes, so that other classes can subscribe to the output of the logs. The problem I have then is that I want the functionality of the logging extension to the encapsulated in the logging class, but interfaces don't allow me to do that. In my derived class, I want to call methods on the logging extension, so the subscribing classes receive output.
If I did it via composition, it would look like this, create an ILogger interface with a GetLogger property to get a logger class. To subscribe to the event I cast the derived type to the ILogger, then subscribe to a handler from the GetLogger, and to raise a log I call a method from GetLogger.
My main problem with this method that all my derived classes have to have a Logger member object that is never used, whereas I just want to be able to call the inherited ILogger class. Is that clean? Because I feel like there's another way of approaching the problem.
At this point in time I'm more interested in cleanliness than getting it done.
As far as getting your logger class to the objects that need it, I think it boils down to either passing the logger around (probably as an argument to a constructor), or using a global variable (i.e. some sort of singleton / service provider).
I'm not sure inheritance is useful here. Do you need various different kinds of log for some reason?
|
On July 23 2014 10:22 bakesale wrote:Show nested quote +On July 21 2014 19:14 MelChizm wrote: What is the most the most efficient way in R to get values from a table. By which I mean I have a list of ID's, I have a table in which there is one column with each ID exactly once, and one column with the number that belongs to the ID. So now I want in my big list, with multiple occurences of the ID's, I want to add after each occurence the number from the table.
I use now lapply on the ID's and a function that indexes on the ID and returns the number, but I have the feeling this lapply function is not so efficient, it takes a long time to compute. Does somebody know a more efficient method?
dummy data: ID 1 1 2 1 2 3 ...
table ID Number 1 384835 2 435393 3 239493 ... Can you clarify what the goal is? I think from what you've said, and using that sample data, that the output would be: ID Number 1 384835 1 384835 2 435393 1 384835 2 435393 3 239493 Is that correct?
Yes Exactly, that is the result I am looking for.
|
On July 23 2014 12:01 Blisse wrote: What I want to build is a generic logging extension for classes, so that other classes can subscribe to the output of the logs. The problem I have then is that I want the functionality of the logging extension to the encapsulated in the logging class, but interfaces don't allow me to do that. In my derived class, I want to call methods on the logging extension, so the subscribing classes receive output.
If I did it via composition, it would look like this, create an ILogger interface with a GetLogger property to get a logger class. To subscribe to the event I cast the derived type to the ILogger, then subscribe to a handler from the GetLogger, and to raise a log I call a method from GetLogger.
My main problem with this method that all my derived classes have to have a Logger member object that is never used, whereas I just want to be able to call the inherited ILogger class. Is that clean? Because I feel like there's another way of approaching the problem.
At this point in time I'm more interested in cleanliness than getting it done. I think you need to split up the functionality: classes for receiving (and processing) the logging information, and classes that use the logging for writing.
Then you can maybe use something like custom attributes. Mark the classes/methods that need to receive the logging with a custom attribute, and have your logger class use reflection to find those classes/methods.
|
Wouldn't it be better to simply create a logging interface and implement it where necessary?
|
|
|
|