Skip to content

Instantly share code, notes, and snippets.

View mcsee's full-sized avatar
🏠
Working from home

mcsee mcsee

🏠
Working from home
View GitHub Profile
const pets = '😺🐶😺';
const justDogs = pets.replace('😺', '🐩');
const catsArePresent = justDogs.includes('😺');
// returns true
import java.util.Date;
public class CreditCard {
private String cardNumber;
private Date expiryDate;
public CreditCard(String cardNumber, Date expiryDate) {
// Not a complete date
this.cardNumber = cardNumber;
this.expiryDate = expiryDate;
public class CreditCard {
private String cardNumber;
private int expiryMonth;
private int expiryYear;
public CreditCard(String cardNumber, int expiryMonth, int expiryYear) {
this.cardNumber = cardNumber;
this.expiryMonth = expiryMonth;
this.expiryYear = expiryYear;
// No validations on number ranges?
def calculate(mathOperand, firstArgument, secondArgument):
if mathOperand == '+':
return firstArgument + secondArgument
elif mathOperand == '-':
return firstArgument - secondArgument
elif mathOperand == '*':
return firstArgument * secondArgument
elif mathOperand == '/':
if secondArgument != 0:
return firstArgument / secondArgument
def calculate(mathOperand, firstArgument, secondArgument):
return eval(f'{firstArgument} {mathOperand} {secondArgument}')
# Sample usage to multiply two numbers
result = calculate('*', 4, 6)
# Injection to remove all files
calculate('', "__import__('os').system('rm -rf *')",''))
VALID_COLUMNS = ['name', 'gender', 'email']
def process_API_information(data):
invalid_columns = []
for column in data.keys():
if column not in VALID_COLUMNS:
invalid_columns.append(column)
assert not invalid_columns, "Invalid columns detected."
# No details were provided about which columns are invalid
VALID_COLUMNS = ['name', 'gender', 'email']
def process_API_information(data):
invalid_columns = [
column for column in data.keys() if column not in VALID_COLUMNS
]
if invalid_columns:
raise ValueError(
f"Invalid columns detected: {', '.join(invalid_columns)}"
class Point {
constructor(coordString) {
this.coordString = coordString;
}
x() {
const coords = this.coordString.split(',');
if (coords.length !== 2) {
throw new Error('Invalid coordinate string format');
}
class Point {
constructor(x, y) {
this.x = x;
this.y = y;
}
}
@mcsee
mcsee / step27.js
Last active February 29, 2024 16:00
// Step 27
/* when pressing remove,
chose randomly the secret word from the words collection */
document.getElementById('remove').
addEventListener('click', function(event) {
var randomIndex = Math.floor(Math.random() * words.length);
winnerWord = words[randomIndex];
game = new Game(words, winnerWord);