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.
Info
Info

 Shoutbox

Hello, Guest
Please login or register.

 
 
 

Did you miss your activation email?
Jake
February 18, 2015

jonyatta
February 13, 2015

prince
February 3, 2015

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('C:\sg\darkrp\garrysmod\addons');
  4.                 echo '<select name=\'file\'>';
  5.                 echo '<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++
  1.  
  2. void printall()
  3. {
  4.     for( vector<string>::const_iterator i = data.begin(); i != data.end(); i++)
  5.     {
  6.         cout << *i << ' ';
  7.         cout << "\n";
  8.     }
  9. }
  10.  
  11.  


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:

http://www.cplusplus.com/forum/beginner/106769/
http://www.cplusplus.com/forum/beginner/105772/

You can also replace

My First Program
Posted by: Jake in Tutorial Support on February 18, 2015, 10:13:23 pm

First, does this forum have a help and support section, or is this all for tutorials? I've got my program all finished and it appears to function as I want it to, I just thought I'd post it so that you guys could chime in and maybe tell me what's bad and what there is to change.

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

C++ Basic RLE Compression
Posted by: Celestialkey in Tutorials on January 11, 2015, 07:48:31 pm

Code: C++
  1. #include <iostream>// std::cout
  2. #include <fstream> // std::fstream
  3. #include <sstream> // std::ostringstream
  4. #include <random>
  5. /*
  6.         Run Length Encoding - RLE Example to Compression
  7.         Http://Www.CelestialCoding.com
  8.  
  9.         You can go lower level then this tutorial. I will
  10.         only be looking at each byte and checking for duplicates.
  11.         You can do something similar at the macro
  12.         level (look for repeating collections of binary datasets) or even at the lowest
  13.         binary level (look for repeating binary datasets)
  14. */
  15.  
  16. // Used to generate a ~50 meg file for compression
  17. void GenerateRandomFile(){
  18.        
  19.         std::fstream


  •  Total Members: 83
  •  Total Posts: 11149
  •  Total Topics: 1695
  •  Total Categories: 4
  •  Total Boards: 75
  • users Users: 0
  • guests Guests: 12
  • hidden Hidden: 0
  • spiders Spiders: 0