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
@mcsee
mcsee / idor.php
Last active May 17, 2025 23:33
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
<?php
class Invoice {
public int $id;
// The external identifier is never an essential
// responsibilty for an object
public string $customerName;
public array $items;
@mcsee
mcsee / safe.json
Last active May 17, 2025 23:33
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
// package.json
{
"name": "my-app",
"dependencies": {
"react": "18.2.0",
"lodash": "4.17.21", // Correct spelling with exact version
"@company-scope/internal-logger": "2.1.0" // Scoped package
},
"resolutions": {
"lodash": "4.17.21"
@mcsee
mcsee / poisoned.json
Created May 11, 2025 17:04
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
// package.json
{
"name": "my-app",
"dependencies": {
"react": "^18.2.0",
"lodahs": "1.0.0", // Typosquatting attack
"internal-logger": "2.1.0"
// Vulnerable to dependency confusion
}
}
@mcsee
mcsee / SplitTest.java
Last active May 9, 2025 03:43
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public class TVSeriesTest {
// No shared setup
@Test
public void testRecommendation() {
// Create only what's needed for this specific test
// And move this test with the behavior
TVSeries theEternaut = createTheEternautSeries();
User homer = createUserWithPreferences();
addReviewsForUser(theEternaut, homer);
@mcsee
mcsee / TVSeriesTest.java
Last active May 10, 2025 21:48
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public class TVSeriesTest {
private MovieSeries theEternaut;
private List<Character> characters;
private List<Episode> episodes;
private User user;
private UserPreferences preferences;
private RatingSystem ratingSystem;
private StreamingService streamingService;
private List<Review> reviews;
@mcsee
mcsee / allcases.cs
Last active May 2, 2025 23:45
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public static class WallpaperInitializer
{
private static bool wallpaperWasDefined = false;
public static void InitializeWallpaper()
{
if (wallpaperWasDefined)
{
LoadWallpaperBitmap();
}
@mcsee
mcsee / missingcase.cs
Last active May 3, 2025 01:21
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public static class WallpaperInitializer
{
private static bool wallpaperWasDefined = false;
public static void InitializeWallpaper()
{
if (wallpaperWasDefined)
// Assume this was defined previously
// and PLEASE DON'T use NULLs in case you hadn't
{
@mcsee
mcsee / lessnoise.js
Created April 27, 2025 15:50
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
function isNotNull(x) {
return x !== null && x !== undefined
// Another code smell here
}
function mapToValueAndMeta(y) {
const meta = y.meta ? y.meta : { default: true }
return { val: y.value, meta }
}
@mcsee
mcsee / noise.js
Created April 27, 2025 15:48
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
const result = arr.filter(x => x !== null && x !== undefined)
.map((y) => ({ val: y.value, meta:
y.meta ? y.meta : {default: true}}))
.reduce((acc, {val, meta}) =>
meta.default ? acc : [...acc,
{processed: val * 2, origin: meta}], [])
.some(({processed}) => processed > 10 && processed < 50);
@mcsee
mcsee / lamda.cpp
Last active April 27, 2025 23:31
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
[](){}
/* This valid lambda function:
Captures no variables.
Takes no arguments.
Performs no actions.
[]: This is the capture clause.
It specifies which variables from the surrounding scope