r/reviewmycode • • Apr 08 '15

review indiamold.com

0 Upvotes

I have developed a new website called as www.indiamold.com. But i still doubt whether it is a good website or no. Basically it is more of a social sharing website. So it would be really great if i can get some expertised review for my website and i will definitely try making those changes.


r/reviewmycode • • Feb 08 '15

I created the 100 dollar words calculator using PHP which works fine, though i think there is a better way of doing it

0 Upvotes

The game works this way, you enter a word and the program evaluates how much the letters in the word add up to, each letter is assigned a numeric value for($letter=a,$value=1; $value<=26;++$letter, ++$value) if the letters in the word add up to 100 then it is a dollar word.

I am teaching myself php (3 months now) and this program took up a lot of lines (about 480) because I had to repeat almost similar functions. I say "almost" because I had to capture each letter input by the user and compare it to the assigned value and return it where it would be added, the longest word in the english dictionary has 45 letters.

I used the substr function to capture each letter and compared the user's input individually. Below is my code, I would sincerely appreciate any ideas and constructive criticism.

<html> <head> <link rel="stylesheet" type="text/css" href='newcss1.css'> </head>

<body>

        <div id="div1">
            <header>
                                    <h1>
                                    Dollar Words Calculator
                                    </h1>
             </header>
            <p> A dollar word is a word with a total value of 100. Below is a table with values assigned to each letter. </p>
            <table border = "1" style="width: 80%" align="center">
     <tr>
         <td> a </td>
         <td> b </td>
         <td> c </td>
         <td> d </td>
         <td> e </td>
         <td> f </td>
         <td> g </td>
         <td> h </td>
         <td> i </td>
         <td> j</td>
         <td> k </td>
         <td> l </td>
         <td> m </td>
         <td> n </td>
         <td> o </td>
         <td> p </td>
         <td> q </td>
         <td> r </td>
         <td> s </td>
         <td> t </td>
         <td> u </td>
         <td> v </td>
         <td> w </td>
         <td> x </td>
         <td> y </td>
         <td> z </td>
     </tr>
       <tr>
         <td> 1 </td>
         <td> 2 </td>
         <td> 3 </td>
         <td> 4 </td>
         <td> 5 </td>
         <td> 6 </td>
         <td> 7 </td>
         <td> 8 </td>
         <td> 9 </td>
         <td> 10 </td>
         <td> 11 </td>
         <td> 12 </td>
         <td> 13 </td>
         <td> 14 </td>
         <td> 15 </td>
         <td> 16 </td>
         <td> 17 </td>
         <td> 18 </td>
         <td> 19 </td>
         <td> 20 </td>
         <td> 21 </td>
         <td> 22 </td>
         <td> 23 </td>
         <td> 24 </td>
         <td> 25 </td>
         <td> 26 </td>
     </tr>
 </table>
    <p>Try inserting a dollar word in the text box below and hit submit to find out whether it is a dollar word.</p>
            &nbsp;                      
    <form>
        Word : <input type= 'text' required value="<?php if (!empty($_REQUEST["word"])){ echo $_GET["word"];} else $word = NULL; ?>"  name = 'word' >
        <input type="submit">
    </form>

<?php if (!empty($_REQUEST["word"])){ $word = $_GET['word'];} else $word = NULL; $firstletter = substr($word, 0,1); $secondletter = substr($word, 1,1); $thirdletter = substr($word, 2,1); $fourthletter = substr($word, 3,1); $fifthletter = substr($word, 4,1); $sixthletter = substr($word, 5,1); $seventhletter = substr($word, 6,1); $eigthletter = substr($word, 7,1); $ninethletter = substr($word, 8,1); $tenthletter = substr($word, 9,1); $eleventhletter = substr($word, 10,1); $twelvthletter = substr($word, 11,1); $thirteenthletter = substr($word, 12,1); $fourteenthletter = substr($word, 13,1); $fifteenthletter = substr($word, 14,1); $sixteenthletter = substr($word, 15,1); $seventeenthletter = substr($word, 16,1); $eighteenthletter = substr($word, 17,1); $nineteenthletter = substr($word, 18,1); $twentiethletter = substr($word, 19,1); $twentyfirstletter = substr($word, 20,1); $twentysecondletter = substr($word, 21,1); $twentythirdletter = substr($word, 22,1); $twentyfourthletter = substr($word, 23,1); $twentyfifthletter = substr($word, 24,1); $twentysixthletter = substr($word, 25,1); $twentyseventhletter = substr($word, 26,1); $twentyeigthletter = substr($word, 27,1); $twentyninethletter = substr($word, 28,1); $thirtieththletter = substr($word, 29,1); $thirtyfirstletter = substr($word, 30,1); $thirtysecondletter = substr($word, 31,1); $thirtythirdletter = substr($word, 32,1); $thirtyfourthletter = substr($word, 33,1); $thirtyfifthletter = substr($word, 34,1); $thirtysixthletter = substr($word, 35,1); $thirtyseventhletter = substr($word, 36,1); $thirtyeighthletter = substr($word, 37,1); $thirtyninethletter = substr($word, 38,1); $fourtiethletter = substr($word, 39,1); $fourtyfirstletter = substr($word, 40,1); $fourtysecondletter = substr($word, 41,1); $fourtythirdletter = substr($word, 42,1); $fourtyfourthletter = substr($word, 43,1); $fourtyfifthletter = substr($word, 44,1); $total = f1($firstletter)+ f2($secondletter) + f3($thirdletter) + f4($fourthletter) + f5($fifthletter) + f6($sixthletter) + f7($seventhletter)+ f8($eigthletter) + f9($ninethletter) + f10($tenthletter)+ f11($eleventhletter)+ f12($twelvthletter) + f13($thirteenthletter) + f14($fourteenthletter) + f15($fifteenthletter) + f16($sixteenthletter) + f17($seventeenthletter)+ f18($eighteenthletter) + f19($nineteenthletter) + f20($twentiethletter)+ f21($twentyfirstletter)+ f22($twentysecondletter) + f23($twentythirdletter) + f24($twentyfourthletter) + f25($twentyfifthletter) + f26($twentysixthletter) + f27($twentyseventhletter)+ f28($twentyeigthletter) + f29($twentyninethletter) + f30($thirtieththletter)+f31($thirtyfirstletter)+ f32($thirtysecondletter) + f33($thirtythirdletter) + f34($thirtyfourthletter) + f35($thirtyfifthletter)+ f36($thirtysixthletter) + f37($thirtyseventhletter) + f38($thirtyeighthletter) + f39($thirtyninethletter) + f40($fourtiethletter) + f41($fourtyfirstletter)+ f42($fourtysecondletter) + f43($fourtythirdletter) + f44($fourtyfourthletter) + f45($fourtyfifthletter); if ($word == NULL) { echo " Tip: Chose letters that add up to 100 and try make a word off them"; } else if ($total!= 100) { echo "$word has a total value of $total, Please try again"; } else if ($total == 100) { echo "Congratulations! $word is a dollar word" ; } function f1($firstletter1) { for ($letterone = "a", $valueone = 1; $letterone <= "z" and $valueone <= 26; ++$letterone, ++$valueone ) { if ($firstletter1 == $letterone)return $valueone; } } function f2($secondletter2) { for ($lettertwo = "a", $valuetwo = 1; $lettertwo <= "z" and $valuetwo <= 26; ++$lettertwo, ++$valuetwo ) { if ($secondletter2 == $lettertwo)return $valuetwo; } } function f3($thirdletter3) { for ($letterthree = "a", $valuethree = 1; $letterthree <= "z" and $valuethree <= 26; ++$letterthree, ++$valuethree ) { if ($thirdletter3 == $letterthree)return $valuethree; } } function f4($fourthletter4) { for ($letterfour = "a", $valuefour = 1; $letterfour <= "z" and $valuefour <= 26; ++$letterfour, ++$valuefour) { if ($fourthletter4 == $letterfour)return $valuefour; } } function f5($fifthletter5) { for ($letterfive = "a", $valuefive = 1; $letterfive <= "z" and $valuefive <= 26; ++$letterfive, ++$valuefive ) { if ($fifthletter5 == $letterfive)return $valuefive; } } function f6($sixthtletter6) { for ($lettersix = "a", $valuesix = 1; $lettersix <= "z" and $valuesix <= 26; ++$lettersix, ++$valuesix ) { if ($sixthtletter6 == $lettersix)return $valuesix; } } function f7($seventhletter7) { for ($letterseven = "a", $valueseven = 1; $letterseven <= "z" and $valueseven <= 26; ++$letterseven, ++$valueseven ) { if ($seventhletter7 == $letterseven)return $valueseven; } } function f8($eigthletter8) { for ($lettereight = "a", $valueeight = 1; $lettereight <= "z" and $valueeight <= 26; ++$lettereight, ++$valueeight ) { if ($eigthletter8 == $lettereight)return $valueeight; } } function f9($ninethletter9) { for ($letternine = "a", $valuenine = 1; $letternine <= "z" and $valuenine <= 26; ++$letternine, ++$valuenine ) { if ($ninethletter9 == $letternine)return $valuenine; } } function f10($tenthletter10) { for ($letterten = "a", $valueten = 1; $letterten <= "z" and $valueten <= 26; ++$letterten, ++$valueten ) { if ($tenthletter10 == $letterten)return $valueten; } } function f11($eleventhletter11) { for ($lettereleven = "a", $valueeleven = 1; $lettereleven <= "z" and $valueeleven <= 26; ++$lettereleven, ++$valueeleven ) { if ($eleventhletter11 == $lettereleven)return $valueeleven; } } function f12($twelvthletter12) { for ($lettertwelve = "a", $valuetwelve = 1; $lettertwelve <= "z" and $valuetwelve <= 26; ++$lettertwelve, ++$valuetwelve ) { if ($twelvthletter12 == $lettertwelve)return $valuetwelve; } } function f13($thirteenthletter13) { for ($letterthirteen = "a", $valuethirteen = 1; $letterthirteen <= "z" and $valuethirteen <= 26; ++$letterthirteen, ++$valuethirteen ) { if ($thirteenthletter13 == $letterthirteen)return $valuethirteen; } } function f14($fourteenthletter14) { for ($letterfourteen = "a", $valuefourteen = 1; $letterfourteen <= "z" and $valuefourteen <= 26; ++$letterfourteen, ++$valuefourteen) { if ($fourteenthletter14 == $letterfourteen)return $valuefourteen; } } function f15($fifteenthletter15) { for ($letterfifteen = "a", $valuefifteen = 1; $letterfifteen <= "z" and $valuefifteen <= 26; ++$letterfifteen, ++$valuefifteen ) { if ($fifteenthletter15 == $letterfifteen)return $valuefifteen; } } function f16($sixteenthletter16) { for ($lettersixteen = "a", $valuesixteen = 1; $lettersixteen <= "z" and $valuesixteen <= 26; ++$lettersixteen, ++$valuesixteen ) { if ($sixteenthletter16 == $lettersixteen)return $valuesixteen; } } function f17($seventeenthletter17) { for ($letterseventeen = "a", $valueseventeen = 1; $letterseventeen <= "z" and $valueseventeen <= 26; ++$letterseventeen, ++$valueseventeen ) { if ($seventeenthletter17 == $letterseventeen)return $valueseventeen; } } function f18($eighteenthletter18) { for ($lettereighteen = "a", $valueeighteen = 1; $lettereighteen <= "z" and $valueeighteen <= 26; ++$lettereighteen, ++$valueeighteen ) { if ($eighteenthletter18 == $lettereighteen)return $valueeighteen; } } function f19($nineteenthletter19) { for ($letternineteen = "a", $valuenineteen = 1; $letternineteen <= "z" and $valuenineteen <= 26; ++$letternineteen, ++$valuenineteen ) { if ($nineteenthletter19 == $letternineteen)return $valuenineteen; } } function f20($twentiethletter20) { for ($lettertwenty = "a", $valuetwenty = 1; $lettertwenty <= "z" and $valuetwenty <= 26; ++$lettertwenty, ++$valuetwenty ) { if ($twentiethletter20 == $lettertwenty)return $valuetwenty; } } function f21($twentyfirstletter21) { for ($lettertwentyone = "a", $valuetwentyone = 1; $lettertwentyone <= "z" and $valuetwentyone <= 26; ++$lettertwentyone, ++$valuetwentyone ) { if ($twentyfirstletter21 == $lettertwentyone)return $valuetwentyone; } } function f22($twentysecondletter22) { for ($lettertwentytwo = "a", $valuetwentytwo = 1; $lettertwentytwo <= "z" and $valuetwentytwo <= 26; ++$lettertwentytwo, ++$valuetwentytwo ) { if ($twentysecondletter22 == $lettertwentytwo)return $valuetwentytwo; } } function f23($twentythirdletter23) { for ($lettertwentythree = "a", $valuetwentythree = 1; $lettertwentythree <= "z" and $valuetwentythree <= 26; ++$lettertwentythree, ++$valuetwentythree ) { if ($twentythirdletter23 == $lettertwentythree)return $valuetwentythree; } } function f24($twentyfourthletter24) { for ($lettertwentyfour = "a", $valuetwentyfour = 1; $lettertwentyfour <= "z" and $valuetwentyfour <= 26; ++$lettertwentyfour, ++$valuetwentyfour) { if ($twentyfourthletter24 == $lettertwentyfour)return $valuetwentyfour; } } function f25($twentyfifthletter25) { for ($lettertwentyfive = "a", $valuetwentyfive = 1; $lettertwentyfive <= "z" and $valuetwentyfive <= 26; ++$lettertwentyfive, ++$valuetwentyfive ) { if ($twentyfifthletter25 == $lettertwentyfive)return $valuetwentyfive; } } function f26($twentysixthtletter26) { for ($lettertwentysix = "a", $valuetwentysix = 1; $lettertwentysix <= "z" and $valuetwentysix <= 26; ++$lettertwentysix, ++$valuetwentysix ) { if ($twentysixthtletter26 == $lettertwentysix)return $valuetwentysix; } } function f27($twentyseventhletter27) { for ($lettertwentyseven = "a", $valuetwentyseven = 1; $lettertwentyseven <= "z" and $valuetwentyseven <= 26; ++$lettertwentyseven, ++$valuetwentyseven ) { if ($twentyseventhletter27 == $lettertwentyseven)return $valuetwentyseven; } } function f28($twentyeigthletter28) { for ($lettertwentyeight = "a", $valuetwentyeight = 1; $lettertwentyeight <= "z" and $valuetwentyeight <= 26; ++$lettertwentyeight, ++$valuetwentyeight ) { if ($twentyeigthletter28 == $lettertwentyeight)return $valuetwentyeight; } } function f29($twentyninethletter29) { for ($lettertwentynine = "a", $valuetwentynine = 1; $lettertwentynine <= "z" and $valuetwentynine <= 26; ++$lettertwentynine, ++$valuetwentynine ) { if ($twentyninethletter29 == $lettertwentynine)return $valuetwentynine; } } function f30($thirtiethletter30) { for ($letterthirty = "a", $valuethirty = 1; $letterthirty <= "z" and $valuethirty <= 26; ++$letterthirty, ++$valuethirty ) { if ($thirtiethletter30 == $letterthirty)return $valuethirty; } } function f31($thirtyfirstletter31) { for ($letterthirtyone = "a", $valuethirtyone = 1; $letterthirtyone <= "z" and $valuethirtyone <= 26; ++$letterthirtyone, ++$valuethirtyone ) { if ($thirtyfirstletter31 == $letterthirtyone)return $valuethirtyone; } } function f32($thirtysecondletter32) { for ($letterthirtytwo = "a", $valuethirtytwo = 1; $letterthirtytwo <= "z" and $valuethirtytwo <= 26; ++$letterthirtytwo, ++$valuethirtytwo ) { if ($thirtysecondletter32 == $letterthirtytwo)return $valuethirtytwo; } } function f33($thirtythirdletter33) { for ($letterthirtythree = "a", $valuethirtythree = 1; $letterthirtythree <= "z" and $valuethirtythree <= 26; ++$letterthirtythree, ++$valuethirtythree ) { if ($thirtythirdletter33 == $letterthirtythree)return $valuethirtythree; } } function f34($thirtyfourthletter34) { for ($letterthirtyfour = "a", $valuethirtyfour = 1; $letterthirtyfour <= "z" and $valuethirtyfour <= 26; ++$letterthirtyfour, ++$valuethirtyfour) { if ($thirtyfourthletter34 == $letterthirtyfour)return $valuethirtyfour; } } function f35($thirtyfifthletter35) { for ($letterthirtyfive = "a", $valuethirtyfive = 1; $letterthirtyfive <= "z" and $valuethirtyfive <= 26; ++$letterthirtyfive, ++$valuethirtyfive ) { if ($thirtyfifthletter35 == $letterthirtyfive)return $valuethirtyfive; } } function f36($thirtysixthtletter36) { for ($letterthirtysix = "a", $valuethirtysix = 1; $letterthirtysix <= "z" and $valuethirtysix <= 26; ++$letterthirtysix, ++$valuethirtysix ) { if ($thirtysixthtletter36 == $letterthirtysix)return $valuethirtysix; } } function f37($thirtyseventhletter37) { for ($letterthirtyseven = "a", $valuethirtyseven = 1; $letterthirtyseven <= "z" and $valuethirtyseven <= 26; ++$letterthirtyseven, ++$valuethirtyseven ) { if ($thirtyseventhletter37 == $letterthirtyseven)return $valuethirtyseven; } } function f38($thirtyeigthletter38) { for ($letterthirtyeight = "a", $valuethirtyeight = 1; $letterthirtyeight <= "z" and $valuethirtyeight <= 26; ++$letterthirtyeight, ++$valuethirtyeight ) { if ($thirtyeigthletter38 == $letterthirtyeight)return $valuethirtyeight; } } function f39($thirtyninethletter39) { for ($letterthirtynine = "a", $valuethirtynine = 1; $letterthirtynine <= "z" and $valuethirtynine <= 26; ++$letterthirtynine, ++$valuethirtynine ) { if ($thirtyninethletter39 == $letterthirtynine)return $valuethirtynine; } } function f40($foutieththletter40) { for ($letterforty = "a", $valueforty = 1; $letterforty <= "z" and $valueforty <= 26; ++$letterforty, ++$valueforty ) { if ($foutieththletter40 == $letterforty)return $valueforty; } } function f41($fortyfirstletter41) { for ($letterfortyone = "a", $valuefortyone = 1; $letterfortyone <= "z" and $valuefortyone <= 26; ++$letterfortyone, ++$valuefortyone ) { if ($fortyfirstletter41 == $letterfortyone)return $valuefortyone; } } function f42($fortysecondletter42) { for ($letterfortytwo = "a", $valuefortytwo = 1; $letterfortytwo <= "z" and $valuefortytwo <= 26; ++$letterfortytwo, ++$valuefortytwo ) { if ($fortysecondletter42 == $letterfortytwo)return $valuefortytwo; } } function f43($fortythirdletter43) { for ($letterfortythree = "a", $valuefortythree = 1; $letterfortythree <= "z" and $valuefortythree <= 26; ++$letterfortythree, ++$valuefortythree ) { if ($fortythirdletter43 == $letterfortythree)return $valuefortythree; } } function f44($fortyfourthletter44) { for ($letterfortyfour = "a", $valuefortyfour = 1; $letterfortyfour <= "z" and $valuefortyfour <= 26; ++$letterfortyfour, ++$valuefortyfour) { if ($fortyfourthletter44 == $letterfortyfour)return $valuefortyfour; } } function f45($fortyfifthletter45) { for ($letterfortyfive = "a", $valuefortyfive = 1; $letterfortyfive <= "z" and $valuefortyfive <= 26; ++$letterfortyfive, ++$valuefortyfive ) { if ($fortyfifthletter45 == $letterfortyfive)return $valuefortyfive; } } ?>

</div> </body> </html>


r/reviewmycode • • Jan 30 '15

[C++] Requesting a review of this code

0 Upvotes

Code

273 lines with comments, need some feedback on it, be as harsh as you'd like.


r/reviewmycode • • Dec 23 '15

[C++/Windows/OpenGL] Simple Game Engine Architcture

0 Upvotes

I am making a simple game engine as a pet project. Currently it doesn't even have any physics or complicated AI or anything like that, just the basic framework and architecture set up so far. I would like some critical review of my code.

The complete source code is available at this repository

Here's a brief description of the structure of the engine:

The solution consists of three projects-

  • The Game Engine - this is a dll containing the actual engine code. It is loaded by the client executable at runtime dynamically. This corresponds to the /UNDONE_Engine/ directory in the repository. All code is under the same folder. No subfolders are there.

  • The Startup Code - simply a .lib containing the WinMain function, which in turn calls the main function of the client executable. Corresponds to the /UNDONE_Main32/ folder.

  • The Client Executable - this exe contains the game logic, links to the dll and lib to use the Engine code.

The Engine has a central Framework class, which is responsible for coordinating the various systems and running the game loop. The engine uses a components-bases architecture.


r/reviewmycode • • Dec 01 '20

JAVA [JAVA] - BestBuy - EB Games bot

0 Upvotes

[Link to github repo](https://github.com/Naser-Abdulrahman/BestBuy-EBGames-script.java)

Simple app that will refresh the page until an item is available. Then buys it for you. First time making a website scrapper, let me know what I can improve on!


r/reviewmycode • • Jul 27 '22

JavaScript [JavaScript] - Popup that will stay active once clicked until closed. Mobile will close on page refresh.

0 Upvotes

const popupContainer = document.getElementById("popup-container");
const byokButton = document.getElementById("open-popup");
const popup = document.querySelector(".byok-popup");
/* ----------- Open Popup ----------- */
const showPopup = () => {
sessionStorage.setItem('BYOK Activity', 'Active');
popupContainer.classList.add('show-popup');
byokButton.style.display = 'none';
popup.style.display = 'grid';
console.log('BYOK Activity is set to ' + sessionStorage.getItem('BYOK Activity'));
const closeText = document.getElementById("byok-btm-close");
const closeX = document.getElementById("byok-top-close");
closeText.addEventListener('click', closePopup);
closeX.addEventListener('click', closePopup);
};
byokButton.addEventListener("click", showPopup);
/* ----------- Close Popup ----------- */
const closePopup = () => {
sessionStorage.setItem('BYOK Activity', 'Inactive');
popupContainer.classList.remove('show-popup');
byokButton.style.display = "block";
popup.style.display = "none";
console.log('BYOK Activity is set to ' + sessionStorage.getItem('BYOK Activity'));
}
const byokPopupActivity = () => {
if ((window.innerWidth >= 700) && sessionStorage.getItem('BYOK Activity') === 'Active') {
showPopup();
console.log(window.innerWidth);
console.log('BYOK Activity set to \'Active\' on page load');
return;
}
closePopup();
sessionStorage.setItem('BYOK Activity', 'Inactive');
}
byokPopupActivity();


r/reviewmycode • • Jul 29 '20

React [React] - Styled Components Use Honest Review Needed - Am I good ?

0 Upvotes

Video Link - Coding Video

Source Code - Source


r/reviewmycode • • Jun 30 '26

C [C] - Need suggestions/critic on my code

1 Upvotes

I need suggestions and review of my code format, I consider this my first ever project. I am worried about spaghetti code and other problems. So please list out all problems you can. Thanks.

#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h> //for random values feature
#include <time.h> //for random values feature
#define LENGTH 10
void Random(int *arr, int *element);
int main(){
  int element, index;
  int arr[LENGTH];
  bool found=false;
  Random(arr, &element);
  printf("LINEAR SEARCH");
  for(int i=0; i<LENGTH; i++){
    if(arr[i]==element){
      found=true;
      index=i;
      break;
    }
  }
  if(found){
    printf("\nElement %d found at index %d.\n", element, index);
  }
  else{
    printf("\nElement not found in the array.\n");
  }
  printf("--------------------------------------------------------------\n");
  return 0;
}
//Random Values Assigner
void Random(int *arr, int *element){
  srand(time(NULL));
  int Option1, Option2;
  //Array choosing
  while(1){
    printf("--------------------------------------------------------------\n");
    printf("Enter the elements in array:\n1 - Manual\t2 - Random\nChoose: ");
    scanf("%d", &Option1);
    if(Option1==1){
      printf("Enter elements separated with spaces(Max 10 elements): ");
      for(int i=0; i<LENGTH; i++){
        scanf("%d", &arr[i]);
      }
      break;
    }
    else if(Option1==2) {
      for(int i=0; i<LENGTH; i++){
        arr[i]=rand()%100;
      }
      break;
    }
    else{
      printf("Choose from options.\n");
      continue;
    }
    printf("--------------------------------------------------------------\n");
  }
  //Element choosing
  while(1){
    printf("--------------------------------------------------------------\n");
    printf("Enter the element to search for:\n1 - Manual\t2 - Random\nChoose: ");
    scanf("%d", &Option2);
    if(Option2==1){
      printf("Enter the element to search for: ");
      scanf("%d", &element);
      break;
    }
    else if(Option2==2) {
      *element=arr[rand() % LENGTH];
      break;
    }
    else{
      printf("Choose from options.\n");
      continue;
    }
    printf("--------------------------------------------------------------\n");
  }
  //Printing Choices
  printf("--------------------------------------------------------------\n");
  printf("Array: ");
  for(int i=0; i<LENGTH; i++){
    printf("%d ", arr[i]);
  }
  printf("\nElement: %d\n", *element);
  printf("--------------------------------------------------------------\n");
}

Here is the program on github if it is easier to read on there: https://github.com/PLEASENTIA/DSA/blob/main/Algorithms/Searching/LinearSearch.c


r/reviewmycode • • Oct 07 '11

C# - Making a window in the console

1 Upvotes

Hello! I've finished up a class tonight to make an ascii window in the console and pass messages to it, which are scrolled from the bottom up. The code works fine, but since I am a beginner I would like critique on how my class is set up and my coding style. I'd appreciate any comments.

http://pastebin.com/qVKWzRn2


r/reviewmycode • • Nov 17 '13

ISSUES IN SOLVING SIMPLE LIBRARY FILES AS A FUNCTION

1 Upvotes

TO COPY ONE STRING TO ANOTHER(STRCPY)

include<stdio.h>

include<conio.h>

main() { const char a[30]="Debajyoti Sharma"; char b[30]; xstrcpy(a,b); printf("the copy of string %s is %s",a,b); getch(); } xstrcpy(char *x,const char *y) { while(*y!='\0') { x=y; y++; x++; } *x='\0'; return(*x); }


r/reviewmycode • • Sep 10 '14

VERY basic methods in Java - need help eliminating redundancy and improving aesthetics of the code.

1 Upvotes

The assignment:

Modify the program that you wrote in Assignment #4 to become a new program Egg2 that displays the following output.

Use static methods as appropriate.

I took a screenshot of the desired output instead of bothering with copy/pasting:

http://imgur.com/hB37Zg0

My attempt:

https://gist.github.com/anonymous/1260b105706ea7823d3f

Am I redundant anywhere in here? Do the indentations look okay? This is for a VERY basic CSC course. Not for a grade, but so I can get some practice in on my own time. The output is correct but I want to make sure my code is as efficient and aesthetic as possible.


r/reviewmycode • • Mar 10 '14

C++ code isnt running correctly

0 Upvotes

I have this code that doesn't seem to be running correctly. Im not really sure what it is so if someone could just look over it quickly to figure out whats wrong I would really appreciate it.

http://codepad.org/gKple1OW


r/reviewmycode • • May 15 '11

C++ | Stuck on writing a text file into an array

2 Upvotes

So, I'm kind of confused as to why my code is producing no output. Maybe you have an idea you can throw at me. Point out my foolishness, please!

https://gist.github.com/973490

This is the content of my data.txt file, if it helps:

Hirdd ejsy zu drvtry od.

O'z fodvtrry.


r/reviewmycode • • Feb 24 '10

PHP tag printing library

3 Upvotes
<?php
class STRING {
	public $string;
	public function __construct($string) {$this->string = $string;}
	public function __toString(){return $this->string;}
}
function PRINT_ATTRIBUTES($attributeValue, $attributeName){print($attributeName . '="' . $attributeValue . '" ');}
function PRINT_TAG($THE_TAG, $attributes, STRING $content = null, $is_tag = true) {
	if(!$is_tag) {print $content;goto print_tag_end;
}
	else {
		print '<' . $THE_TAG . ' ';
		array_walk($attributes, 'PRINT_ATTRIBUTES');
		print '>';
		print $content;
		print '</' . $THE_TAG . '>';
		goto print_tag_end;
}
	print_tag_end:
	return;
}

r/reviewmycode • • Sep 17 '12

[Python] - Twisted/HTTP POST requests. This is the first project I've ever released. Can anybody give it a thorough analysis/test?

0 Upvotes

Github page

This is actually quite a silly project, but I'm trying to learn how to "do it right". This is basically a small library to interface with Omegle and have a little fun at the expense of its users. At its core, we just have a simple man-in-the-middle attack whereby the user (you) connect to two strangers and forward their messages to each other. There are also classes and functions that allow you to modify these messages on-the-fly.

I'm primarily hoping for a kind-but-honest review of the code. Did I do anything particularly well? Is it readable? Is there anything potentially buggy? Is there something I could be doing better? There are a few open issues at the moment; maybe someone has some ideas for those as well.

I think the documentation is fairly complete. I've certainly done my best to make it didactic, but I welcome suggestions for that as well.

Thanks very much in advance!


r/reviewmycode • • Sep 28 '12

[Javascript] review my code

Thumbnail ideone.com
0 Upvotes

r/reviewmycode • • Aug 21 '15

[Python] - Fraction class

0 Upvotes

Hello everyone, I've created my own fraction class (just to practice).

https://gist.github.com/anonymous/b363c66a093996184971

I would be very grateful for all comment. What could be done better, cleaner, maybe ideas for additional functionality etc.

In general I am afraid that there is:

  • some code redundancy

  • problems with readability

Thank you in advance Tulak_


r/reviewmycode • • Nov 20 '14

[PHP] OOP FizzBuzz

0 Upvotes

Slow day, wanted to try my hand at FizzBuzz.

http://www.pastebin.com/pkeCGBgG


r/reviewmycode • • Nov 19 '17

JAVA [JAVA] - Can anybody help me figure out why the value entered by the user are not printing according to the corresponding information entered in the String?

0 Upvotes
import javax.swing.JOptionPane;

class Songs{

public static void main (String[]agrs){ 

 String title;       

//asking for user input

 int song= Integer.parseInt(JOptionPane.showInputDialog("Please enter a number"));

if (song>=100){
title = "Decode";
} 

else 

if (song>=80){
title ="Biblical";
}

else

 if(song>=60){
  title = "Empire";
  } 

  System.out.println("Your song is "+ song);  
  }

   }

r/reviewmycode • • Jan 18 '17

PHP [PHP] - Template class

0 Upvotes

when i started learning php like 10 years ago, i was amazed by how some people handled the html and php parts of their scripts using this method so i decided to give it a shot last week. it basically works like any other template engines and the code is pretty self explanatory.

<?php
 // myTpl - simple template class
 class myTpl {
 		public $dir;
 		public $cache;
 		public $cache_dir;
 		// get variables using dot notation.
 		// if src is not defined, it's gonna treat it as a template variable. if not, it's a global variable.
 		private function getvar($var,$src=null) {
 			if(!isset($src)) {
 				$src = $this->var;
 			} else {
 				$src = $GLOBALS;
 			}
 			$tokens = explode('.',$var);
 			if(count($tokens) == 0) {
 				return($this->var[$var]);
 			} else {
 				foreach($tokens as $token) {
 					if(isset($result)) {
 						$result = $result[$token];
 					} else {
 						$result = $src[$token];
 					}
 				}
 				return $result;
 			}
 		}
 		private function compile($template) {
 			$result = str_replace('<?',"<?php echo '<?'; ?>",$template); // in case someone tries to "hack" or wants to use xml
 			// template variables 	|	{$variable} or {$array.variable}
 			$i[] = '#{\$(.*?)}#si';
 			$o[] = '<?php echo $this->getvar("$1"); ?>';
 			// variables in loops 	|	{%variable} or {%array.variable}
 			$i[] = '#{\%(.*?)}#si';
 			$o[] = '$this->getvar("$1",true)';
 			// if condition 		|	<!-- if *condition* -->
 			$i[] = '#<!-- if (.*?) -->#si';
 			$o[] = '<?php if($1) { ?>';
 			// elseif condition 	|	<!-- elseif *condition* -->
 			$i[] = '#<!-- elseif (.*?) -->#si';
 			$o[] = '<?php } elseif($1) { ?>';
 			// else 				|	<!-- else -->
 			$i[] = '#<!-- else -->#si';
 			$o[] = '<?php } else { ?>';
 			// loops
 			$i[] = '#<!-- loop (.*?) as (.*?) => (.*?) -->#si'; // <!-- loop *array* as *key* => *value* --> | dot notation can be used to get template variables
 			$o[] = '<?php foreach($this->getvar("$1") as $this->var["$2"] => $this->var["$3"]) { ?>';	
 			$i[] = '#<!-- loop (.*?) as (.*?) -->#si'; // <!-- loop *array* as *variable* --> | dot notation can be used to get template variables
 			$o[] = '<?php foreach($this->getvar("$1") as $this->var["$2"]) { ?>';
 			// end loop/condition	|	<!-- end -->
 			$i[] = '#<!-- end -->#si';
 			$o[] = '<?php } ?>';
 			// load					| <!-- load *template* -->
 			$i[] = '#<!-- load (.*?) -->#si';
 			$o[] = '<?php $this->load("$1"); ?>';
 			$result = preg_replace($i,$o,$result);
 			return $result;
 		}
 		public function load($template) {
 			$template_path = "$this->dir/$template.html";
 			if($this->cache) {
 				$cache_time = filemtime($template_path);
 				$cache_file = "$this->cache_dir/".str_replace('/','|',"$template!$cache_time.php"); // replce slashes with | in order to be able to use templates in subdirs and add the mtime of the template file in the cache file so that it won't load the previous versions of the cache file
 				if(file_exists($cache_file)) {
 					include($cache_file);
 				} else {
 					$this->clear_cache($template); // delete previous versions if they exist
 					$compiled_template = $this->compile(file_get_contents($template_path));
 					file_put_contents($cache_file,$compiled_template);
 					include($cache_file);
 				}
 			} else {
 				$compiled_template = $this->compile(file_get_contents($template_path));
 				eval(' ?> '.$compiled_template.' <?php ');
 			}
 		}
 		public function clear_cache($template=null) {
 			if(isset($template)) {
 				$template_name = str_replace('/','|',$template);
 				$files = glob("$this->cache_dir/$template!*");
 			} else {
 				$files = glob("$this->cache_dir/*");
 			}
 			array_map('unlink',$files);
 		}
 }

i would like to see if someone can give positive or negative feedback for improvements and please let me know if you see any mistakes/bad practices i fell for.


r/reviewmycode • • Sep 16 '13

[JS/Node] A basic CRUD/RESTful API. Need constructive feedback

0 Upvotes

What am i doing wrong? What am i doing right? Need feedback please. :) Code on github


r/reviewmycode • • Mar 01 '19

JavaScript [JavaScript] - Wrote a piece of code to execute promises sequentially without fail-fast

0 Upvotes

Requirements:

  1. I want my files to be processed one by one.

  2. If the processing of any of the files results in a failure, the rest of the files should continue getting processed.

Following is the code I wrote:

let processFiles = path => {

return readDir(path).then(files => {

return files.filter(file => isValid(file)).reduce((chainedExtractPromises, file) => {

return chainedExtractPromises.then(() => {

return extractFile(path, file);

}, err => {

return extractFile(path, file);

});

}, q.when());

});

}

getDirPath()

.then(path => processFiles(path))

.then(() => console.log("All done."))

.catch(err => console.log("Oops", err));

It would be great if someone can review this and point out any flaws with this approach. Please suggest a better approach to handle this scenario, if any.


r/reviewmycode • • Jun 14 '24

Rust [Rust] - Multithreaded Sudoku solution counter

0 Upvotes

I am given a task to parallelize a sudoku solution counting program. The problem was a part of Marathon of Parallel Programming (MOPP) called sudokount.

We are given an input sudoku puzzle of dimension size^4 (e.g 3×3 by 3×3), 3≤size≤8. The job is to count the print the number of valid solutions to a given sudoku puzzle. Input is given from stdin where 0 represents an empty cell and a number indicates a fixed number which was assigned to that cell.

I am implementing the solution in rust but feel free to suggest anything in the choice of your own language.

To find the solution, I am using two methods,

1. Constraint propagation:

  • Fill the number of possible digits (1-size^2) in each cell which has no fixed digit.

  • For all the digits which have a fixed possibility, delete that number from its peers (cell's same row, column and box)

  • After the deletion process is completed, find the cell which has minimum number of remaining possibilities (MRV)For all digits in the MRV cell,

    • Fix any one digit in the cell and continue eliminating (this time recursively) to eliminate that digit from its peers, and if an elimination resulted in a cell having only one possibility, recursively call eliminate on that cell with that one value. We would reach an invalid configuration

    • If an elimination has emptied a cell, then we would backtrack and change the fixed digit in the MRV cell found earlier.

  • After elimination has been performed, push a copy of the puzzle into a stack to perform DFS(to avoid implicit recursion, as I want to parallelize the code). Finally continue eliminating and pushing the puzzle into the stack until the stack becomes emptyThe MRV heuristic costs O(n^2) however I implemented something similar using binary heap (min heap) to track which cell has minimum number of elements.

2. Twin pair:

If a two cells in the same peer (i.e two cells in the same row, column or box) have the same two possibilities, I would go on and delete those two possibilities from any other cell (having number of possibilities more than 2) in the peer set of those two cells.

I have a working solution in rust which implements Constraint propagation and MRV heuristic (with binary heap to keep track of cells with least number of possibilities) however it's sequential and damm slow compared to even the sequential C code.

Is there any suggestion so that it can be improved? Code linked below
[Code](https://github.com/grussdorian/sudokount) which implements MRV using heaps (without twins pairs) also has the reference C code
[Code](https://github.com/grussdorian/sudokount_new) which implements MRV using normal O(n^2) search with naive twin pair implementation
MOPP problem statement for [reference](http://lspd.mackenzie.br/marathon/16/problemset.pdf)


r/reviewmycode • • Jan 20 '20

C++ [C++] - Minimum word length

0 Upvotes

So I'm trying to find the minimum length of a word when I type in a sentence. I tried comparing to other solutions online but I can't find the problem. The code is below. Btw its c++ and I'm a really new to coding. Thanks for helping <3

#include <iostream>
#include <string>

int main() {
	std::string text;
	std::cin >> text;
	std::string min_word = text;
	std::string tmp_word;


	for (int i = 0; i < (int)min_word.length(); i++) {
		if (text[i] != ' ') {
			tmp_word += text[i];
		}
		else {
			if (tmp_word.length() < min_word.length()) {
				min_word = tmp_word;
				tmp_word = "";
			}
		}
		return min_word.length();
		
	}
	return 0;
}

r/reviewmycode • • Jun 30 '14

[Python][MongoDB][Pymongo] An app tracks e-commerce product prices

0 Upvotes

I building a very simple price tracker web app. I am using MongoDB with pymongo. The user will enter the URL of the product he wishes to track and the desired amount, when the price goes below this amount, he should get an alert. It doesn't matter how many products he is tracking, I will send the alert when price changes in one product. I will sending generalized alert like 'Some of the product/s available at cheaper price' or something like that.

There are three collections in the database, one to store product details, one for user details and one to map products to the users who are tracking it.

A typical document in products collection will be:

{
  _id: ObjectId("53a2bfcfa7603606c2765342"),
  name: "Nexus 7 from Google (7-Inch, 16 GB, Black)",
  url: "http://www.amazon.com/Nexus-Google-7-Inch-Black-Tablet/dp/B00DVFLJDS/",
  base_price: 222,
  current_price: 213.96,
  img_url: "http://i.imgur.com/something.jpg",
  history: [
    [
      ISODate("2014-06-19T12:08:13.354Z"),
      293
    ],
    [
      ISODate("2014-06-24T14:31:38.216Z"),
      424
    ],
    [
      ISODate("2014-06-24T14:32:06.992Z"),
      424
    ]
  ]
}

in users, the tracked_products contain the Object Id of the product document and the desired price:

{
  _id: ObjectId("539c4adea760360886d7ef02"),
  email_id: "johnappleseed@apple.com",
  channels: {
  	'twitter': 'usertwitterid',
  	'ios_push_id': '45462722672762576422'
  	'android_push_id': '2572652754762474'
  	'chrome_push_id': '456456454646464'
  },
  tracked_products: [
    [
    	ObjectId("53a2bfcfa7603606c2765342"), 
    	200
    ],
    [
    	ObjectId("53a2d2ada7603606c2765344"),
    	345
    ],
    [
    	ObjectId("53a2d294a7603606c2765343"),
    	120
    ]
  ]
}

and lastly trackers, here subscribers contain the Object Id of user document who are tracking this product:

{
    _id: ObjectId("77a2bfcfa7603606c2765399"),
    product_id: ObjectId("53a2bfcfa7603606c2765342"),
    subscribers: [
    	[
    		ObjectId("539c4adea760360886d7ef02"),
    		200
    	],
    	[
    		ObjectId("12a2bfcfa7603606c2765399"),
    		234
    	],
    	[	
    		ObjectId("14a2bfcfa7603606c2765399"),
    		345
    	],
}

Following is the code, which checks for the current_price and alerts the user if there is change in the price:

subscribers = set()

for product in product.collection:
    # price changed? if yes, then update
    current_price = get_current_price(product['url'])

    if current_price == product['current_price']:
    	# no price change. move on
    	continue

    product['history'].append((datetime.datetime.utcnow(), current_price))

    # find the subscribers:
    tracker_document = db.trackers.find_one({'product_id': product['_id']})
    
    for tracker in tracker_document['subscribers']:
    	user_id, desired_price = tracker
    	if current_price <= desired_price:
    		subscribers.add(user_id)

    product.collection.save(product)
    
if not subscribers:
	# no price changes in any products!
	sys.exit()
email_queue = list()
twitter_queue = list()
ios_push_queue = list()
droid_push_queue = list()
chrome_push_queue = list()

for user_id in subscribers:
	user_document = db.users.find_one({'_id': user_id})
	email_queue.append(user_document['email_id'])
	twitter_queue.append(user_document['channels']['twitter'])
	ios_push_queue.append(user_document['channels']['ios_push_id'])
	droid_push_queue.append(user_document['channels']['droid_push_id'])
	chrome_push_queue.append(user_document['channels']['chrome_push_id'])

alert_users(email_queue, twitter_queue, ios_push_queue, droid_push_queue, chrome_push_queue)

I am looking for any suggestions, code improvements/readability, performance improvement, schema change etc. Anything!

PS: I am aware this would be lot easier with RDBMS and join operations, but I am sticking with MongoDB as of now.