Skip to content

Need some code for your project? We've got you covered. Choose your language. Choose how many lines. BÄM! You got code.

License

Notifications You must be signed in to change notification settings

rawwwrs/randomcodegenerator.lol

 
 

Repository files navigation

Welcome to the randomcodegenerator.lol

A screenshot from the first Twitch stream on this project

All Contributors

Need some code for your project? We've got you covered.

Choose your language. Choose how many lines.

BÄM! You got code.

Getting Started

First, install dependencies and run the development server:

npm i
npm run dev

Open http://localhost:3000 with your browser to see the result.

Adding a new language

The following instructions will guide you through how to add a new language to the generator.

  1. Add a new file in tools/utils named {language}.js
  2. There are some helper functions available in tools/utils/helpers.js so the first step in your new file is to import those functions:
import {
  getRandomEntry,
  getRandomInt,
  getRandomNounUpperCase,
  getRandomVerbUpperCase,
  getRandomLogLine,
} from "./helpers";

It is worth looking at helpers.js in case any of the other functions are applicable to your language, or in case some are in fact not needed at all and don't need to be imported in your file.

  1. In your new, create a new JavaScript class with the name of your language
export default class <insert language name here> {

}
  1. If your language uses functions with access modifers or return types, create a static function for this that returns a string wrapped in ``to define this. Seestatic getRandomMethodName() in csharp.js for an example
  2. Create a static function called getRandomFunctionName or getRandomMethodName depending on your language as required which builds up the name using functions from helper.js
  3. Create a static function called getRandomVariableDeclation, define the common keywords from your language, that returns a random variable declaration using functions from helper.js such as getRandomEntry(keywords). See javascript.js for an example
  4. Create a function that will return some random log lines from the helper file. Name this after how your language words output. For example csharp.js has getRandomDebugWriteLine and javascript.js has getRandomConsoleLog
  5. Inside this function, paste the following
const options = getLogLines();
return getRandomEntry(options);
  1. We now want to create some silly filler lines so create the following function in your file and update it reflect your language syntax and file name
static getRandomFillerLine() {
  const options = [
    `console.log(${JavaScript.getRandomConsoleLog()});`,
    JavaScript.getRandomVariableDeclaration(),
    `${JavaScript.getRandomFunctionName()}();`,
  ];
  return getRandomEntry(options);
}
  1. Save your file as it is now time to use it
  2. Open tools/RandomCodeGenerator.js
  3. Import the reference to your language file, following the pattern of the existing code
  4. Add your language to the list of languages. The name cannot have special characters but the value as a string is how the language will appear on the buttons so straight text will work such as the existing C++
  5. After the last case statement but before default, add the word case followed by your language name in quotes and followed by a colon (: symbol)
  6. Assign a string surrounded by ``tofirstLine that reflects how a method or function is declared in your language
  7. Paste the following after your firstLine assignment, updating to reflect your language syntax and file name, for example:
for (let i = 1; i <= fillerLineQty; i++) {
  fillerLines.push(`    ${CPlusPlus.getRandomFillerLine()}`);
}

lastLine = "${addNewLine()}}";

return firstLine + fillerLines.join(addNewLine()) + lastLine;
  1. Open languages.js and add your language to the Languages object
  2. Open contributors.js and add your GitHub username to the Contributors object at the top of the file
  3. Make sure everything is saved, then take a look at your changes on http://localhost:3000
  npm run dev
  1. Check the page is displaying correctly and enjoy your hard work :)
  2. If it all runs and displays your language correctly, submit a PR to the original repo and celebrate 🎉

Contributors ✨

Thanks goes to these wonderful people (emoji key):


Isabella Brookes

💻

Cody Merritt Anhorn

💻

jwalter

💻

ticketron

💻

Luce Carter

💻 📖

Luke Oliff

💻

Rick van den Bosch

💻

Paul Perry

💻

Matthew Peck-Deloughry

💻

negue

💻

Rhys Powell

💻

Sociable Steve

💻

Denver F

💻

mrange

💻

matthewbrandt

💻

Justin Horner

💻

Thomas Boccinfuso

💻

michaud

💻

Mike Elsmore

💻

Refik Refik Tefik

💻

Mark Phillipson

💻

This project follows the all-contributors specification. Contributions of any kind welcome!

This is a Next.js project bootstrapped with create-next-app.

Learn More

To learn more about Next.js, take a look at the following resources:

You can check out the Next.js GitHub repository - your feedback and contributions are welcome!

Deploy on Vercel

The easiest way to deploy your Next.js app is to use the Vercel Platform from the creators of Next.js.

Check out our Next.js deployment documentation for more details.

About

Need some code for your project? We've got you covered. Choose your language. Choose how many lines. BÄM! You got code.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 91.2%
  • CSS 8.8%