Skip to content

Instantly share code, notes, and snippets.

View ILoveBacteria's full-sized avatar

Moein Arabi ILoveBacteria

View GitHub Profile
@ILoveBacteria
ILoveBacteria / dynamic_array.cpp
Created December 31, 2022 19:49
How to change the size of dynamic array in c++(like realloc in c)
#define MIN(a, b) a < b ? a : b
void changeSize(int* &arr, int &size, int newSize) {
// Allocate a new array
int* newArray = new int[newSize];
// Copy all elements to the new array
for(int i = 0; i < MIN(size, newSize); ++i) {
newArray[i] = arr[i];
}
// Free and assign the new Array
@ILoveBacteria
ILoveBacteria / string_generator.py
Created December 30, 2022 18:28
A simple Python function that can generate a random string
import random
import string
# whitespace – a string containing all ASCII whitespace
# ascii_lowercase – a string containing all ASCII lowercase letters
# ascii_uppercase – a string containing all ASCII uppercase letters
# ascii_letters – a string containing all ASCII letters
# digits – a string containing all ASCII decimal digits
# hexdigits – a string containing all ASCII hexadecimal digits