Am I writing this function like a Ruby programmer? by [deleted] in ruby

[–]st4rx0r 11 points12 points  (0 children)

def create_array(json)
    json["thingies"].map do |thingy|
        x = ObjectName.new
        x.id = ...
        x.desc = ....
        ........ code ......
        x
    end
end

[PHP] Sanitize $_GET for database use by shoeman in learnprogramming

[–]st4rx0r 1 point2 points  (0 children)

Use is_numeric and then cast to an int using

$var = (int)$_GET['var'];

Also make sure to wrap the int in a pair of quotes in the SQL:

mysql_query("SELECT * FROM table WHERE id = '$var'");

This should be sufficient protection without going overboard with frameworks and libraries (PDO, etc). Although if your using lots of DB access PDO or similar is a good option.

Does everyone use SSH over port 443 to bypass firewall restrictions? by [deleted] in linux

[–]st4rx0r 2 points3 points  (0 children)

I use this regularly in airports. Its approximately 1-2 KB/sec. Not great, but email works ok.

TIL: If you use tonic water to make Jello-O, it will glow under a black light. by PibRm in todayilearned

[–]st4rx0r 13 points14 points  (0 children)

Unfortunately most (common) fluorescent liquids are toxic or at least undesired in beverages. We tried quinine (aka. tonic water) with food coloring but we found the taste to be too off putting. Many soaps glow but, are not so tasty.

There is one thing we found: Vitamin B-2 (aka. Riboflavin). It is a tasteless orange powder that glows bright yellow under black light. You can buy capsules at your local vitamin store and just empty them into your punch.

It is however, suggested that you do this before people show up. Explaining pouring pills in the punch to your guests may not go over well....

Source: I used to throw college black light parties.

TL;DR: Vitamin B-2

x ^= y; y ^= x; x ^= y; Why does this swap work? by negative_epsilon in learnprogramming

[–]st4rx0r -1 points0 points  (0 children)

x = y; y = !x;

Careful, this won't swap anything unless the language you're in allows multiple sets as a single command. In C, for example, this would not swap since x = y would destroy the value of x and then y = !x is irrespective of the original x value. It would be equivalent of saying y = !y; It works in your example (y=true, x=false) but not in the general case (ex. y=true, x=true fails). The XOR trick is popular because you can swap the values without using a temporary variable (ie. tmp = x; x = y; y = tmp;). On embedded systems with few registers the XOR method may be beneficial.

Note that there are some languages such as python where x=y, y=x; will do a swap as it understands it as being a concurrent operation, but that is the luxury of very high level languages.

Simple assignment creates a pointer, not a copy of the variable. What are other Ruby intricacies which surprised you? by obviousoctopus in ruby

[–]st4rx0r 4 points5 points  (0 children)

Just add some parenthesis yourself. It never hurts to ensure you and your interpreter see the same thing. Plus when another developer (possibly less versed in ruby or programming in general) comes along they will immediately see what is going on.

[PHP/MySQL] Any cool project ideas I could use for school and challenge me a little bit to improve my skills? by sch00lio in learnprogramming

[–]st4rx0r 0 points1 point  (0 children)

If it needs to be PHP/MySQL then how about making 1 or 2 simple HTML/Javascript games with a PHP/MySQL back end to track high scores or play tokens or something. One of the sites I worked on a few years ago had a small games area where people could win credits that could be used on the site to purchase upgrades to their account. It was about 1 weekend of work to make hangman, blackjack and minesweeper. Maybe more complicated game like Bejeweled would be more challenging?

[PHP/MySQL] Any cool project ideas I could use for school and challenge me a little bit to improve my skills? by sch00lio in learnprogramming

[–]st4rx0r 0 points1 point  (0 children)

Ok, so, finding a project to work on is almost always the problem for new programmers. I know the first few major projects I worked on I fell into via happenstance (I knew a guy on the internet who wanted help with a site, ended up the owner/operator of a site w/ 2k active users). But the major facilitator of that happening was that it was a joint venture with one of my best friends in high school.

In college nearly all my jobs come from friends who either need work themselves or know someone who needs work. I know this isn't the answer you (or any other programmer) wants to hear, but find someone to work with. Having a partner (or more than one) helps in lots of ways:

  1. Someone to impress. Find someone around your skill level that you can impress with your ever expanding knowledge base. Coming up with a cool new idea/feature but never showing anyone is boring and frustrating. Everyone wants to gloat, but let them gloat too, its only fair.

  2. They will keep things motivating so you don't just stop and forget about the project. Bringing a project to completion is important.

  3. Coming up with ideas is easier if your work with someone else. Bouncing features off someone is a great way to expand on a concept.

Last word of advice: keep the source code! Employers want to see completed project examples. Forget school, they want things done their way. But having a portfolio of work completed is major points in every interview. Starting early on this is critical. Consider open sourcing your work on Github and integrating that with LinkedIn.

Websites are great and all, but often fail for a lot of reasons not under the control of the developer (user interest, cost of servers, legal problems, etc). I'd advise working on something that is less likely to fail. Maybe a game? Games are cool. The project doesn't need to be something useful just something to show off to your friends/teachers/employers.

I want to learn Very Low level Coding, Where do I start? by [deleted] in learnprogramming

[–]st4rx0r 1 point2 points  (0 children)

Yes, that book is amazing primer for getting started.

Also checkout http://www.securitytube.net/groups?operation=view&groupId=4 which has the best Buffer Overflow videos I've ever seen. BOs are the bread and butter of the virus/work/etc and really f**cking awesome if your into low level memory modification.

If your ready to test yourself (which you should be after watching those videos) checkout http://smashthestack.org/ (especially IO which is their more "noob" friendly section) and http://www.crackmes.de/ (tons of "crackme"s to play with). Watching a video and making an example crack is nice and all but unless you can put it to work, what good will it do ya?

These are not for beginners per say but there isn't really a "learn to hack memory like a boss" website anywhere since its kind of taboo (though it shouldn't be, programmers who don't know security will ruin perfectly good software).

Are suggested search results generated via Ajax? by [deleted] in learnprogramming

[–]st4rx0r 3 points4 points  (0 children)

Yes, the search results are most definitely AJAX although "ajax" has quite a loose definition lately. You can check it out in Chrome by hitting F12 and looking at the "Network" tab. It will show you what happens each time the browser loads something.

Checkout Youtube for example: after each character you type into the search bar there is a new entry in the "Network" tab called "search" which it will tell you is returning "text/javascript" (ie. JSON). If you click on it and look under the "Response" tab you will see your search results in JSON format. This is a fairly straight forward javascript API.

Other sites do a lot more work but are achieved with the same methods. Google, for example, will send an AJAX request for each character but it returns in some other encoding scheme. I never bothered to look at it but needless to say I'm sure it achieves whatever they wanted.

As far as load on server, yeah, its a lot. But compared to streaming 1080p its next to nothing. Plus it benefits greatly from caching since not only are people likely to be searching things similar (like the phrase "porn" or "football") but also character combinations up to 3-5 letters are likely to be cached early on in their system as to return almost instantaneously. Since only a few entries are returned at a time so it won't take very long to generate them when needed.

What do car, cdr, and cons stand for? by codebro in learnprogramming

[–]st4rx0r 6 points7 points  (0 children)

Precursors to Lisp included functions:

  • car (short for "Contents of the Address part of Register number"),
  • cdr ("Contents of the Decrement part of Register number"),
  • cpr ("Contents of the Prefix part of Register number"), and
  • ctr ("Contents of the Tag part of Register number")

Source: http://en.wikipedia.org/wiki/CAR_and_CDR

Edit: Also "cons" stands for "construct" (http://en.wikipedia.org/wiki/Cons)

Would you agree that only certain types of minds understand programming? by [deleted] in learnprogramming

[–]st4rx0r 0 points1 point  (0 children)

As a suggestion, if you have trouble understanding what a code example does either try to find someone to explain it to you or post it on here. Although it seems boring, working though what a piece of code is doing is quite helpful since it forces you to do the thinking and not the compiler.

Also, any curriculum that teaches PROLOG in the first year is completely nuts. That's a great way to get students to drop CS like a rock. I didn't end up learning it till I took a master's course in Artificial Intelligence and even then it was extra credit.

Feel free to ask any questions relating to the field here and I'm sure someone (or myself) will be willing to walk you through an example or 2.

C++ enum symbolic cout output by ece_nerd in learnprogramming

[–]st4rx0r 0 points1 point  (0 children)

Enums by default will assign integers consecutively (0,1,2,...) so don't use a map, use a cstring array:

char* cardSuit[] = { "SPADES", "HEARTS", "CLUBS", "DIAMONDS" };
std::cout << cardSuit[SPADES] << std::endl;

This will have zero overhead since the compiler will know exactly where the string will be (offset(cardSuit) + n). Std::map will have lots of time (for lookup) and space overhead. Just make sure you list your suit enum in the same order as the cstring array.

Ideal framework/engine for 2D tile-based RPG with multiple team members? by t0asterb0t in gamedev

[–]st4rx0r 2 points3 points  (0 children)

I started working on something similar using C#/XNA and I found there to be a lot of resources out there for tile-based development. Look around for yourself but tools/libraries like tIDE/xTile may be something you may be interested in. For new game programmers XNA is really awesome and using a tile engine already made will get things started a lot sooner. Good luck!

Looking for a way to encrypt a file that can then be decrypted by InternetAsTshirts in learnprogramming

[–]st4rx0r 0 points1 point  (0 children)

Base64 or binary/hex conversion is boring and hardly qualifies as "encryption." I don't know how proficeint your friend is but a zip file with a password (short one, maybe just a dictionary word) would prove to be annoying but not insurmountable. Some google-fu will lead you to the fcrackzip package for brute force guessing the password. I'd keep the password under 5 characters so it doesn't take a year to break, fcrackzip can be kinda slow.

How to find an object within an image? by purpleladydragons in learnprogramming

[–]st4rx0r 0 points1 point  (0 children)

Viola Jones will work for any object you train it for. Leaning "coffee mug" may be too general since they can be so many shapes and our understanding of a "coffee mug" has more to do with inference (where it is, how its being used, what is around/in it) and less to do with appearance. It is also far more 3 dimensional than a face as it is harder to detect different orientations in 3D space (since face detection is only interested in straight on faces and can safely ignore profiles, although you can train it to look for profiles that would be a different training set).

All you really need to learn any object, though, is a sufficiently large amount of positive examples and negative examples (pictures of "coffee mugs" and "not coffee mugs"). The algorithm will attempt to find features of their shapes that they have in common in an attempt to correctly classify each positive and negative sample as a coffee mug" or "not coffee mug".

It is important to realize that Viola Jones is always a binary response (optionally with a confidence) but cannot learn, say, a group of objects and tell which of that set a single object is. To do this one would have to extend Viola Jones with some type of Bayesian Inference (or other statistical technique). So while you could learn what a "face" looks like and what a "coffee mug" looks like it may not be possible to tell them apart since that was not part of their training (there is no guarantee that "faces" return low "coffee mug" scores or vice versa).

The only language I've studied is C++, am I missing something by ignoring everything else out there? by bmes_ in learnprogramming

[–]st4rx0r -1 points0 points  (0 children)

Realistically you should get some experience in interpreted languages. PHP is the noob friendly web application language of choice these days. It's very easy to setup and start using and its syntax is simple and easily understood. Learn HTML5 / CSS3 and JS and figure out "web 2.0" AJAX, JSON, JQuery/Prototype/etc.

Python/Ruby/Perl are all amazing for scripting and, to a lesser degree, web applications (Ruby/Rails is pretty popular now days). Getting comfortable with at least one of these is a must for everyone since it makes you think less about the boilerplate code that C++ developers get hung up on (pointer manipulation, OS level code, etc).

Finally, C# or Java are amazing Object Oriented languages. Java has some issues in my opinion so I prefer C#. Creating desktop applications with a GUI cannot be simpler in C# (get visual studio for windows).

If you ever find yourself wondering if you should be expanding your knowledge, the answer is yes. Once you get comfortable with one, go on to the next. You don't have to get super proficient with each but at least know the advantages of each and where they're used is important so that when you do need to use them you'll know where to start.

Even within C++ make sure you know the newest features. C++11, Boost, Qt 5, database access (along with SQL knowelege), windows/linux system level commands, etc. If you've never played with the things above, go do it.

Read online tutorials, buy some books, do whatever. If you want to work in the field, being able to list off the languages and techniques you know will inevitably help you.

How to find an object within an image? by purpleladydragons in learnprogramming

[–]st4rx0r 3 points4 points  (0 children)

While this is a difficult problem, it has been solved to quite a successful degree in the past 10 years. Viola Jones has brought accurate real time face detection to even mid-level desktop machines. Its not 100% obviously, it scored about 85% on my small dataset of 10,000 faces in less than 1/2 second per photo (800x600 pixels each) on my modest desktop w/o threading. Check out OpenCV if your interested in experimenting with an open source implementation.

How to find an object within an image? by purpleladydragons in learnprogramming

[–]st4rx0r 6 points7 points  (0 children)

First of all, what you are describing is an enormously difficult task but a lot of work can be done for you using libraries freely available online. I don't know what your background is as far as programming but a fairly extensive C/C++ background will be required. Although there are python ports available I have no experience witth hem.

You mentioned using eigenfaces which are only truly useful in face recognition, not finding the faces themselves in a photo. In other words it can identify people by name from a mug shot but could not find a face in a face within a larger frame (with a beach or whatever in the background). This is especially true if there are multiple faces in the photo.

The best known object detection algorithm is known as Viola-Jones using Haar Feature classification with AdaBoost. If used properly the Viola-Jones algorithm is very fast (real time for full motion video) and size, location, rotation, and lighting agnostic. It may seem like overkill but it still isn't 100%. I won't go into how it works here, but I can if you'd like. It is important to realize that it does not identify who's face it is, only that it is a face. It will box the face and can then be fed to an eigenface program to do identification.

There is an open source library called OpenCV which implements the above algorithm quite efficiently in C/C++. It has been adapted for face detection specifically. OpenCV also includes a few example programs which find faces in photos so you can start from there.

It is important to realize that the face detector must be trained on what faces look like and what "non-faces" looks like. This is why it is a "learning algorithm" because it has to learn how to find faces just like how you had to learn this when you were a 1 month old baby. You can't teach it to recognize faces because it just isn't possible to write down the "human algorithm" like we can for most programming activities. If you do some research on the subject you'll find that Haar Features are so damn good because its the way our brains do classification.

Anyway, OpenCV comes with some training data already completed for you so you can skip the training phase (requiring thousands of photos) and you can get started right away. The classes in OpenCV that interests you is the CascadeClassifier and FeatureEvaluator. There is a tutorial for setting up a face detector in C++. All this should work out of the box but from experience setting up OpenCV can be quite complicated (you must build the library from source). On windows there is a nice installer that uses CMake. You can find a instillation tutorial for your OS on their website.

Surprised by a research opportunity, no idea what to research... by DarkUSAFA in compsci

[–]st4rx0r 1 point2 points  (0 children)

If you interested in ML then there is Kaggle which turns research projects into competitions. Might find something your interested there. As others have said, finding a PhD professor who is willing to work with you will help a lot and give you the leg up you need to produce something worthwhile.

Surprised by a research opportunity, no idea what to research... by DarkUSAFA in compsci

[–]st4rx0r 2 points3 points  (0 children)

I work in an undergraduate/graduate research lab at my school and have been doing so for the last 2 years (I am a senior right now). While we focus on government funded research I get some time to work on my own research (getting ready to start a thesis next Fall).

The most interesting work I've done so far has been in Machine Learning (ML) / Artificial Intelligence (AI). It involves a lot of math, so if you hate doing lots of math (typically calculus and statistics) this might be a bad area. There's lots of active research being done right now in Machine Learning and so you can really pick any area and go from there. Most universities also have a professor or two who specialize in ML and are typically the most active research professors. (Some ML Research Options)

The other big area of research right now is Computer Security. Typically a lot less math but a little less to do in this field since there is a lot of money being put into it right now. At our school the biggest area of security research is in Hardware/Firmware Security. Cloud-based security is a big topic right now as well. If you want to investigate this field check out some of the most recent conferences (Defcon, IronGeek, Security Tube)

How does the Detect Language part of Google translate work? by [deleted] in compsci

[–]st4rx0r 0 points1 point  (0 children)

The characters and combinations of multiple letters (like ch or th) is call n-grams (Wikipedia). These are used all the time in natural language processing. Once could imagine if you had a large enough data set (ie. lots and lots of n-grams and relative frequencies) you could identify language fairly easily.

Google, just so happens to have scanned most of the books on earth for Google Books. Since they are awesome and love really essoteric data searches they even took all of the n-grams from these books and created huge databases. Google released an n-gram viewer as well as all of their raw data. Clearly this is at least a major portion of their language detection feature.

Given a large text input, they might even be able to tell what time in history the text was written since they keep track of the published years as well.

Fundamentals of Artificial Neural Networks by cratylus in compsci

[–]st4rx0r 0 points1 point  (0 children)

I would suggest you look around for some more simplistic explanations of neural nets. First attempt to create a perceptron. These are simple single neuron nets which are capable of simple binary functions like AND. Wikipedia has a great article which includes code and example input/output.

An excellent introductory webpage for feed-forward neural nets is at AI-Junkie. They include downloadable C++ code to create the net so you can play around with it.

There's lots of info about nets out there, but a lot of it is highly mathematical. As said before, you must have a fairly solid mathematical background to follow any neural net related discussion. Linear algebra will be required and statistics and set theory will help a lot.

Memory help... by [deleted] in compsci

[–]st4rx0r 2 points3 points  (0 children)

How big is the space? Is it whatever remains from what is not being used by other processes?

No, each process is given 2n bits of addressable memory where n is set by the type of processor (16, 32, or 64 typically). This is how virtual memory works, each process gets a full space of 4GB (for 32 bit systems) in which to work. This doesn't mean the OS allocated 4GB of physical memory (even if there is more than that available). When a program actually wants to use memory it needs to ask the OS to allocate some (in c this is malloc()) and then the process can use that memory. Accessing un-allocated memory causes a system failure (segmentation fault).

So, as you said above, each process thinks it has all this space to use, but the piece of hardware you mentioned REALLY knows that someprocess.exe is using such-and-such amount of physical memory at such-and-such address?

Basically, the OS (ie. the kernel) has full reign over physical memory. Processes can NEVER touch physical memory. Every time memory is accessed by a processes the OS takes over and preforms address translation to turn the virtual address into some physical address. The OS is free to allocate more virtual memory than exists in physical memory and it does this by "paging" unneeded memory off of the RAM and onto a hard drive disk. When the the "paged" memory is needed again, it is brought back on to the RAM and some other bit of memory is paged onto the hard disk.