Welcome to Celestialcoding!

A simple rule

1. Be polite and professional

All code posted here, unless otherwise specified, is licensed under a BSD 2 Clause license. The only note is that these snippets do not have the BSD copyright notice - so you are exempt from including them.


Hello, Guest
Please login or register.


Did you miss your activation email?
March 18, 2015

March 5, 2015

February 18, 2015

Re: Interesting Look into the ALU
Posted by: mustafolins in Misc on May 02, 2015, 02:07:43 PM

haha i was gonna say this reminds me of Code by Charles Petzold and then they showed that book at the end.  It is a really good book to read if wanting to learn more about switches, adders, etc.
Interesting Look into the ALU
Posted by: Celestialkey in Misc on April 28, 2015, 01:10:51 PM

I found a very good video explaining how computers use the basic transistor component to do multiplication. I'm currently working on a project for college that requires something along these lines. Figured I'd share it since it was such a good video.

Re: My First Program
Posted by: Nathan in Tutorial Support on March 16, 2015, 09:13:00 PM

system(anything) uses more resources then just getting it done more pure

Sure - but also keep in mind system("pause") won't work on Mac OS and Linux.

Code: [Select]
@mysql01:~$ pause
bash: pause: command not found
Re: My First Program
Posted by: Jake in Tutorial Support on March 15, 2015, 03:37:24 AM

I took in a few of these suggestions, and did a little reading. From what I've seen people are saying that using system(anything) uses more resources then just getting it done more pure, so I took a while to find some ways to replace using my system functions, along with adding a remove user function and came up with this.

Code: C++
  1. #include <iostream>
  2. #include <vector>
  3. #include <stdio.h>
  4. #include <string>
  5. using namespace std;
  7. string getinput()
  8. {
  9.     string dataline;
  11.     string name;
  12.     cout << "Enter Name: ";
  13.     getline(cin, name);
  15.     string number;
  16.     cout << "Enter Number: ";

Re: A PHP Solution
Posted by: Celestialkey in Tutorial Support on March 05, 2015, 09:04:41 PM

Next up is how to use php to execute a batch file on my system. I wrote a small batch that essentially executes another program for FastDL sync (as gmod caps DL at 20kb/s) but this program can take a while to complete compressing and copying files. Does something like system("C:\program.bat") work? This particular program requires me to press enter when it is finished, is there a way I could get a program to do this for me? And would the program have to hold up the entire PHP while it takes its 10+ minutes to complete? Any ways around this if it is the case? I feel like all the things I'm trying to do have horri

Re: A PHP Solution
Posted by: Jake in Tutorial Support on March 01, 2015, 03:52:49 PM

I'm not using HTTP authentication, but I already have a openid/steam authentication in place before people can access this page. It's part of a larger project. The main thing I wanted was to make sure it would be impossible for anyone to send malicious POST data to transverse the directory tree to somewhere I didn't want them to, even though in theory only authorized users would have access to this resource to start with.

So I could take the realpath substring length of the POSTed directory, and make sure that it is C:\sg\darkrp\garrysmod\addons? And + is the correct concatenation operator? I was using . or something I think... I was also confused why they named the function unlin

Re: A PHP Solution
Posted by: Nathan in Tutorial Support on March 01, 2015, 08:47:26 AM


This is a topic that is always argued but first off I would recommend using htaccess/IIS to have a basic auth prompt - if it's not using SSL it will be in clear text but it will prevent random people from accessing it.

The options have no value so this as is wouldn't work. And if you are thinking what I think you are thinking - you should set the value options to the subdirectory and do a rrmdir on C:\sg\darkrp\garrysmod\\ + $_POST['file']. Also to check to make sure they aren't trying to traverse through the filesystem you could use http://php.net/manual/en/function.realpath.php to check if $_POST["file"] == realpath($_POST['file']). If it's not equal then you

A PHP Solution
Posted by: Jake in Tutorial Support on February 28, 2015, 12:45:07 AM

After a client whined a little while from FTP taking too long to remove his enormous mistakes, I decided to take a shot at writing a php program to quickly remove files from the addons directory of his garrysmod server. My main goal in this is to prevent any bugs, and any possibility to remove files outside of the addons directory using things like ".." I thought I'd post to see if there was any flaws or security exploits that should be fixed.

Here's the first file that you start at
Code: PHP
  1. <form action="fileman.php" method="post">
  2.         <?php
  3.                 $arr = scandir(&#39;C:\sg\darkrp\garrysmod\addons&#39;);
  4.                 echo &#39;<select name=\&#39;file\&#39;>&#39;;
  5.                 echo &#39;<option>Select a fi

Re: My First Program
Posted by: Celestialkey in Tutorial Support on February 19, 2015, 09:55:11 PM

The code looks good. It is pretty solid. The only suggestions I can make that Nate didn't already cover are pretty much opinionated, so here are some of my opinions.

Lets start here...
Code: C++
  2. void printall()
  3. {
  4.     for( vector<string>::const_iterator i = data.begin(); i != data.end(); i++)
  5.     {
  6.         cout << *i << &#39; &#39;;
  7.         cout << "\n";
  8.     }
  9. }

While this works and accomplishes what you want, it is not very readable. Having to dereference a pointer in order to get it's contents is something you should avoid while being a novice IMHO. It causes uneeded congestion and there are simpler w

Re: My First Program
Posted by: Nathan in Tutorial Support on February 18, 2015, 10:31:08 PM

I think we should have a support section - but I'll let Justin (Celestialkey) figure that out.

A couple of things:

- Many people argue global variables are bad form ie:

Code: C++
  1. vector<string> data;

- Shelling out to a system command with system is usually frowned upon because it's platform dependent (arguably there are a lot worse C++ code that you will probably write that will be platform dependent) ie

Code: C++
  1. system("PAUSE");

Check out these links for alternatives:


You can also replace

  •  Total Members: 85
  •  Total Posts: 11156
  •  Total Topics: 1696
  •  Total Categories: 4
  •  Total Boards: 75
  • users Users: 0
  • guests Guests: 16
  • hidden Hidden: 0
  • spiders Spiders: 0