r/CritiqueMyCode • • Sep 27 '14

/r/CritiqueMyCode is a trending SubReddit

59 Upvotes

I'm new here and this is actually how I found you guys, but I'm looking forward to posting in here.

Screenshot: http://imgur.com/elD9mTi


r/CritiqueMyCode • • Sep 30 '14

[Javascript] Garbage code in an incomplete project

3 Upvotes

Steam-Chat-Chrome

For background, this is a project I started (with the chrome panel api, although it will work without it), since I wanted an alternative to opening a steam tab and chatting in it, because it requires me to change tabs just to talk to people. It's for my chromebook, so I can't just use steam itself, either.

The code is the worst, and I know I need to clean it up massively before I continue, but I've never actually taken any sort of real classes, so I have no real concept of code cleanliness. Could CritiqueMyCode help? I certainly hope so, because I need it.


r/CritiqueMyCode • • Apr 21 '19

Fibonacci number printer

3 Upvotes
#include <cstdio>
int main(){unsigned long n[]{0,1};for(bool i=0;n[i]<0x68A3DD8E61ECCFBE;i=!i,n[i]+=n[!i])printf("%lu ",n[i]);}

The program iteratively prints all 64-bit (assuming it's run on a modern desktop PC) Fibonacci numbers. How can I improve it?


r/CritiqueMyCode • • Nov 19 '14

[Java] Sortarithms: Inspired by that website Reddit crashed yesterday, I decided to write my first Java program. Sorting Algorithms!

Thumbnail
github.com
3 Upvotes

r/CritiqueMyCode • • May 10 '21

[Java] Patternish - Random Pattern Generator

3 Upvotes

Hello !

I'm learning Java and I'm looking for any feedback concerning this app I made :

https://github.com/itsmaximelau/patternish

I'd especially like to have some feedback concerning the code structure/quality and about the look of the GUI. I also made a Youtube video about the app. You can find the link on GitHub.

Thank you !


r/CritiqueMyCode • • Jul 06 '19

simple calculatro in c++,I'm a beginner programmer, I want to share with you my first program in c++

4 Upvotes

r/CritiqueMyCode • • Oct 09 '14

[Python] How to Draw a Histogram in Python Using Matplotlib

Thumbnail
prolificprogrammer.com
4 Upvotes

r/CritiqueMyCode • • Oct 01 '22

I am new to JavaScript. How am I doing?

4 Upvotes
if (userName === '')
  {console.log('Hello!')}
  else 
    {console.log(Hello, ${userName}!)}

r/CritiqueMyCode • • Apr 10 '20

🚀I made a video calling website to connect with my friends during the pandemic!

Thumbnail
zipcall.io
5 Upvotes

r/CritiqueMyCode • • Sep 28 '14

[Python] A script to handle adding livestreams to a reddit sidebar.

Thumbnail
github.com
5 Upvotes

r/CritiqueMyCode • • Oct 02 '14

[Python] Simple genetic algorithm utility (< 300 lines)

Thumbnail
github.com
5 Upvotes

r/CritiqueMyCode • • Apr 19 '15

[Python] first >50 lines program(~450 but at least 75 are what i believe to be clear comments); please tell me how many times i've reinvented the wheel and how many times i've completely missed the point (haha) in my .srt scrubber and vocabulary-practice worksheet generator :)

Thumbnail
gist.github.com
6 Upvotes

r/CritiqueMyCode • • Jun 06 '15

My GitHub, would like people to see my code

Thumbnail
github.com
8 Upvotes

r/CritiqueMyCode • • Jul 26 '16

[Python]Inventory Management

1 Upvotes

I made this project just to mess around with OOP. Let me know if you see anything I can improve.

https://github.com/Snifferdog/Inventory-Management


r/CritiqueMyCode • • Jun 18 '15

[c++] OOP TicTacToe

3 Upvotes

Hey, I'm an amateur programmer looking for critique on my object oriented style c++ tictactoe program. If you guys could look through this program and lend me some tips and advice, Id be very thankful. Thanks pastebin: http://pastebin.com/v6vC0wy2


r/CritiqueMyCode • • Jun 12 '15

[Python] RSS Feed Notifier Script for OSX

6 Upvotes

Hey guys,

I've just started dabbling in some Python, and I made this little script that runs continuously, pulls new posts from an RSS feed (url of feed supplied via command line), and pushes an OSX notification when a new post is detected. The user can click on the notification, and it'll bring them right to the url pointed to by the new RSS object.

I tailored it to a specific website which hosts videos of cycling races, but I suppose with some modification it could be generalized.

Packages/Utilities I used:

FeedParser for Python

Terminal-Notifier by Alloy

I haven't done much OOP, nor have I done too much garbage collection so I'm looking for some advice in those areas.

Mah Code.

e.g. does my del curFeed line make sense where it is? Could I have structured my class and its methods better?

Edits for clarity


r/CritiqueMyCode • • Jan 23 '16

[Java] resp-server, REdis Serialization Protocol implementation.

1 Upvotes

Hi! I've just published this in github. It would be nice if you take a look.

Regards!


r/CritiqueMyCode • • Dec 15 '15

[Python] Backup and Restore Environment Variables script

2 Upvotes

Please tell me what I can improve, be it the function of the program or code itself. Thank you.

'''
Backup and Restore Environment Variables
Based on this "http://superuser.com/a/348489" stackoverflow answer.
December 2015; solaceinsleep

'''

import argparse
import subprocess


def set_up_arg_parse():

    '''
    Sets up the arguments for the script using argparse.

    '''

    parser = argparse.ArgumentParser(description="Backup and Restore Environment Variables")

    group = parser.add_mutually_exclusive_group()
    group.add_argument("-r", "--restore", action="store_true",
                       help="If included will perform a restore operation")
    group.add_argument("-b", "--backup", action="store_true",
                       help="If included will perform a backup operation")

    # parser.add_argument("-i", "--input", help="Folder location of backedup hiv files")

    return parser, parser.parse_args()


def perform_backup():

    '''
    Performs a backup of the environment variables.

    '''

    print('Starting backup operation...\n')

    # Save system environment
    print('Saving system environment: ', end='', flush=True)
    subprocess.call(['reg',
                     'save',
                     r'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
                     'env_sys_backup.hiv',
                     '/y'])

    # Save user environment
    print('Saving user environment: ', end='', flush=True)
    subprocess.call(['reg',
                     'save',
                     r'HKCU\Environment',
                     'env_usr_backup.hiv',
                     '/y'])

    print('...done.\n')


def perform_restoration():

    '''
    Performs a restoration of the environment variables.

    '''

    print('Starting restore operation...\n')

    # Restore system environment
    print('Restoring system environment: ', end='', flush=True)
    subprocess.call(['reg',
                     'restore',
                     r'HKLM\SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
                     'env_sys_backup.hiv'])

    # Restore user environment
    print('Restoring user environment: ', end='', flush=True)
    subprocess.call(['reg',
                     'restore',
                     r'HKCU\Environment',
                     'env_usr_backup.hiv'])

    print('...done.\n')


def main():

    '''
    Processes user inputs, and calls the correct functions.

    '''

    parser, args = set_up_arg_parse()

    if args.backup:
        perform_backup()

    elif args.restore:
        perform_restoration()

    else:
        parser.print_help()


main()

r/CritiqueMyCode • • Dec 23 '15

[c++/windows/Opengl]

3 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/CritiqueMyCode • • Jan 11 '20

Beginner Quiz game (True or False)

4 Upvotes

This time I made a Quiz game in which the player is asked questions and receives points for each question answered correctly. Some people told me I should learn about classes, so this is what I came up with :). https://github.com/Tlomoloko/Quiz_T-F


r/CritiqueMyCode • • Oct 20 '18

[golang] Web server learning project and sample page

3 Upvotes

Hi!

My first time posting here. To prepare for a new job and to generally understand better how things work I started to write a web server in golang. The features so far include:

  • Serve HTTP GET requests

  • handling of log files through my own logging package, which can in theory write different events to different logs (not used in my code yet)

  • concurrent handling of connections via go routines

  • HTTPS capability using the golang crypto/tls package

  • parsing of config files

  • rudimentary CGI implementation The project is VERY rough around the edges, basically a barely running prototype. Also I'm in the process of cleaning up the code. For lot of functions I could have used (arguably better) premade functions/packages, but I decided to write those things myself for the learning experience (except for the tls implementations for obvious reasons).

Any input/comments/suggestions welcome

github repo: https://github.com/karlyan17/nurgling

example site: https://karlyan.ddns.net:8888/index.html


r/CritiqueMyCode • • Oct 16 '18

Music Player written in Python

2 Upvotes

I've created a music player for my computer just to see if that's possible. However, there is an issue with the shuffle function. It doesn't shuffle the playlist.

import os

from random import shuffle

from tkinter.filedialog import askdirectory

import pygame

from mutagen.id3 import ID3

from tkinter import *

root = Tk()

root.minsize(300, 300)

listofsongs = []

realnames = []

v = StringVar()

songlabel = Label(root, textvariable=v, width=35)

index = 0

def directorychooser():

'''Ask what folder the music files are stored'''

directory = askdirectory()

os.chdir(directory)

for files in os.listdir(directory):

if files.endswith(".mp3"):

realdir = os.path.realpath(files)

audio = ID3(realdir)

realnames.append(audio['TIT2'].text[0])

listofsongs.append(files)

pygame.mixer.init()

pygame.mixer.music.load(listofsongs[0])

# pygame.mixer.music.play()

directorychooser()

def updatelabel():

'''Updates Song label at the bottom of the app'''

global index

global songname

v.set(realnames[index])

# return songname

def nextsong(event):

'''Plays next song'''

global index

index += 1

pygame.mixer.music.load(listofsongs[index])

pygame.mixer.music.play()

updatelabel()

def prevsong(event):

'''Skips to previous song'''

global index

index -= 1

pygame.mixer.music.load(listofsongs[index])

pygame.mixer.music.play()

updatelabel()

def stopsong(event):

'''Stops the song currently playing'''

pygame.mixer.music.stop()

v.set("")

# return songname

def shufflesong(event):

'''Randomizes the play list'''

global index

shuffle(listofsongs[index])

pygame.mixer.music.load(listofsongs[index])

pygame.mixer.music.play()

v.set("")

updatelabel()

def rewindsong(event):

'''Restarts the song currently playing'''

pygame.mixer.music.rewind()

v.set("")

label = Label(root, text='Music Player')

label.pack()

scrollbar = Scrollbar(root, orient=VERTICAL)

listbox = Listbox(root, yscrollcommand=scrollbar.set)

scrollbar.config(command=listbox.yview)

scrollbar.pack(side=RIGHT, fill=Y)

listbox.pack()

# listofsongs.reverse()

realnames.reverse()

for items in realnames:

listbox.insert(0, items)

realnames.reverse()

# listofsongs.reverse()

rewindbutton = Button(root, text='Rewind Song')

rewindbutton.pack()

nextbutton = Button(root, text='Next Song')

nextbutton.pack()

previousbutton = Button(root, text='Previous Song')

previousbutton.pack()

stopbutton = Button(root, text='Stop Music')

stopbutton.pack()

# shufflebutton = Button(root, text='Shuffle')

# shufflebutton.pack()

nextbutton.bind("<Button-1>", nextsong)

previousbutton.bind("<Button-1>", prevsong)

stopbutton.bind("<Button-1>", stopsong)

# shufflebutton.bind("<Button-1>", shufflesong)

rewindbutton.bind("<Button-1>", rewindsong)

songlabel.pack()

root.mainloop()


r/CritiqueMyCode • • Jan 16 '20

Beginner 'resta um' game

1 Upvotes

This time I wanted to make a board game that is very popular in Brazil, it's called 'resta um', it means 'there's only one left'. The idea of the game is that there are holes in which there are pieces inside, the player has to pick pieces and 'jump' one another until there is only one left on the board. For a move to be allowed, the selected piece must be one tile away from where it will 'jump' and the hole in which it will go has to be empty. It's kind of hard to explain it since I believe this game doesn't exist outside Brazil.

Download it here: https://github.com/Tlomoloko/Resta-Um/tree/master


r/CritiqueMyCode • • Oct 18 '20

First attempt at writing Clojure

3 Upvotes

Hi y'all.

As my first attempt to write something in Clojure, I tried my hand at a simple HackerRank challenge that involves finding the ratios of negatives, positives and zeroes in an integer array. The function must print out three lines to stdout formatted with 6 decimals instead of returning the new array (go figure).

It seems I got the answer right but it would be great if someone with Clojure experience could suggest better idioms, formatting, or anything you think I should be mindful of going forward.

Thanks a lot!

(defn plusMinus [arr]
  (def totals
    (reduce
      (fn [[pos neg zer tot] i]
        (vector
         (+ pos (if (> i 0) 1 0))
         (+ neg (if (< i 0) 1 0))
         (+ zer (if (= i 0) 1 0))
         (+ tot 1)
        ))
   [0 0 0 0] arr))
  (def ratios
    (let [[pos neg zer tot] totals]
        (vector
          (/ pos tot)
          (/ neg tot)
          (/ zer tot))))
  (println
   (clojure.string/join
    "\n"
    (map
     (fn [ratio] (format "%.6f" (float ratio)))
     ratios)))

r/CritiqueMyCode • • Oct 10 '20

Adding noise for organic movement not working

1 Upvotes

I have this code that makes bubbles move from right to left with pictures in them. I tried to add noise to create organic movement, but it isn't working. Do you guys have any tips?

<!DOCTYPE html>

<html> <head> <style>

        .bubble-wrap {
            overflow: hidden;
            height: 600px;
        }

        .bubbles {
            position: relative;
            background: salmon;
        }

        .bubble {
            position: absolute;
            width: 152px;
            height: 152px;
            border-radius: 50%;
            box-shadow: 
                0 15px 35px rgba(0, 0, 0, 0.1),
                0 3px 10px rgba(0, 0, 0, 0.1);
            background-image: url(https://www.mupload.nl/img/vy4gqqgo1276.png);
            background-size: 1076px 1076px;
        }

        .logo1 { background-position:   0      0; }
        .logo2 { background-position:  -154px  0; }
        .logo3 { background-position:  -308px  0; }
        .logo4 { background-position:  -462px  0; }
        .logo5 { background-position:  -616px  0; }
        .logo6 { background-position:  -770px  0; }
        .logo7 { background-position:  -924px  0; }
        .logo8 { background-position:   0     -154px; }
        .logo9 { background-position:  -154px -154px; }
        .logo10 { background-position: -308px -154px; }
        .logo11 { background-position: -462px -154px; }
        .logo12 { background-position: -616px -154px; }
        .logo13 { background-position: -770px -154px; }
        .logo14 { background-position: -924px -154px; }
        .logo15 { background-position:  0     -308px; }
        .logo16 { background-position: -154px -308px; }
        .logo17 { background-position: -308px -308px; }
        .logo18 { background-position: -462px -308px; }
        .logo19 { background-position: -616px -308px; }
        .logo20 { background-position: -770px -308px; }
        .logo21 { background-position: -924px -308px; }
        .logo22 { background-position:  0     -462px; }
        .logo23 { background-position: -154px -462px; }
        .logo24 { background-position: -308px -462px; }
        .logo25 { background-position: -462px -462px; }
        .logo26 { background-position: -616px -462px; }
        .logo27 { background-position: -770px -462px; }
        .logo28 { background-position: -924px -462px; }
        .logo29 { background-position:  0     -616px; }
        .logo30 { background-position: -154px -616px; }
        .logo31 { background-position: -308px -616px; }
        .logo32 { background-position: -462px -616px; }
        .logo33 { background-position: -616px -616px; }

        body {
            background: #E6EEF7;
        }
       
    </style>
</head>
<body>
   
    <div class="bubble-wrap">
        <div class="bubbles"></div>
    </div>
    
    <script>
        const SCROLL_SPEED = 0.3;
        const NOISE_SPEED = 0.004;
        const NOISE_AMOUNT = 5;
        const CANVAS_WIDTH = 2800;

        const bubblesEl = document.querySelector('.bubbles');
        const bubbleSpecs = [
            { s: .6, x: 1134, y: 45  },
            { s: .6, x: 1620, y: 271 }, 
            { s: .6, x: 1761, y: 372 },
            { s: .6, x: 2499, y: 79  },
            { s: .6, x: 2704, y: 334 },
            { s: .6, x: 2271, y: 356 },
            { s: .6, x: 795,  y: 226 },
            { s: .6, x: 276,  y: 256 },
            { s: .6, x: 1210, y: 365 },
            { s: .6, x: 444,  y: 193 },
            { s: .6, x: 2545, y: 387 },
            { s: .8, x: 1303, y: 193 },
            { s: .8, x: 907,  y: 88  },
            { s: .8, x: 633,  y: 320 },
            { s: .8, x: 323,  y: 60  },
            { s: .8, x: 129,  y: 357 },
            { s: .8, x: 1440, y: 342 },
            { s: .8, x: 1929, y: 293 },
            { s: .8, x: 2135, y: 198 },
            { s: .8, x: 2276, y: 82  },
            { s: .8, x: 2654, y: 182 },
            { s: .8, x: 2783, y: 60  },
            {        x: 1519, y: 118 },
            {        x: 1071, y: 233 },
            {        x: 1773, y: 148 },
            {        x: 2098, y: 385 },
            {        x: 2423, y: 244 },
            {        x: 901,  y: 385 },
            {        x: 624,  y: 111 },
            {        x: 75,   y: 103 },
            {        x: 413,  y: 367 },
            {        x: 2895, y: 271 },
            {        x: 1990, y: 75  }
        ];

        class Bubbles {
            constructor(specs) {
                this.bubbles = [];
                
                specs.forEach((spec, index) => {
                    this.bubbles.push(new Bubble(index, spec));
                })

                requestAnimationFrame(this.update.bind(this));
            }

            update() {
                this.bubbles.forEach(bubble => bubble.update());
                this.raf = requestAnimationFrame(this.update.bind(this))
            }  
        }


        class Bubble {
            constructor(index, {x, y, s = 1}) {
                this.index = index;
                this.x = x;
                this.y = y;
                this.scale = s;

                this.noiseSeedX = Math.floor(Math.random() * 64000);
                this.noiseSeedY = Math.floor(Math.random() * 64000);

                this.el = document.createElement("div");
                this.el.className = `bubble logo${this.index + 1}`;
                bubblesEl.appendChild(this.el);
            }

            update() {
                this.noiseSeedX += NOISE_SPEED;
                this.noiseSeedY += NOISE_SPEED;
                let randomX = noise.simplex2(this.noiseSeedX, 0);
                let randomY = noise.simplex2(this.noiseSeedY, 0);
                
                this.x -= SCROLL_SPEED;
                this.xWithNoise = this.x + (randomX * NOISE_AMOUNT);
                this.yWithNoise = this.y + (randomY * NOISE_AMOUNT)

                if (this.x <  -200) {
                    this.x = CANVAS_WIDTH;
                }

                this.el.style.transform = `translate(${this.xWithNoise}px, ${this.yWithNoise}px) scale(${this.scale})`;
            }
        }

        // For perlin noise
        noise.seed(Math.floor(Math.random() * 64000));
        
        const bubbles = new Bubbles(bubbleSpecs);
    </script>

</body>

</html>