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 / safe.rs
Last active November 29, 2025 21:10
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
fn load_and_validate(max: usize) -> Result<Vec<Feature>, String> {
let raw: Vec<Result<Feature, Error>> = load_features_from_db();
if raw.len() > max {
return Err(format!(
"too many features: {} > {}",
raw.len(), max
));
}
@mcsee
mcsee / unsafe.rs
Last active November 29, 2025 21:15
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
let features: Vec<Feature> = load_features_from_db();
let max = 200;
assert!(features.len() <= max);
# This magic number assumption
# is actually wrong
for f in features {
proxy.add_bot_feature(f.unwrap());
# You also call unwrap() on every feature.
# If the database returns an invalid entry
@mcsee
mcsee / QueryBuilderTexts.java
Last active November 17, 2025 13:45
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public class QueryBuilder {
public String buildEmployeeQuery() {
// 1. Identify multi-line string concatenations or strings
// with excessive escape sequences
// 2. Replace opening quote and concatenation operators
// with triple quotes (""")
// 3. Remove escape sequences for quotes and newlines
// 4. Adjust indentation to match your code style
// 5. Add .strip() for single-line regex patterns or
// when trailing newlines cause issues
@mcsee
mcsee / QueryBuilderStrings.java
Last active November 15, 2025 22:44
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
public class QueryBuilder {
public String buildEmployeeQuery() {
String sql = "SELECT emp.employee_id, " +
"emp.first_name, emp.last_name, " +
" dept.department_name, " +
"emp.salary " +
"FROM employees emp " +
"JOIN departments dept ON " +
"emp.department_id = " +
"dept.department_id " +
@mcsee
mcsee / warnIfNotAllowed.js
Created November 12, 2025 16:21
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
movie.rate.warnIfNotAllowed(this.age);
@mcsee
mcsee / testFalse.js
Created November 12, 2025 14:37
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
function testFalse()
{
Assert(1==2)
}
@mcsee
mcsee / forRecipients.st
Last active November 12, 2025 13:42
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
forRecipients: recipients
recipients do: [:eachAddress |
eachAddress isString
ifFalse: [
self error: (eachAddress , ' is not a valid recipient')] ].
(recipients asSet size = recipients size)
ifFalse: [
self error: 'Duplicates'].
@mcsee
mcsee / test07SimpleScenarios.st
Last active November 12, 2025 13:29
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
test07SimpleScenarios
self assert:
(EmailMessage forRecipients:
(Array with: '[email protected]')) plain = 'to: [email protected]'
@mcsee
mcsee / forRecipients.st
Created November 12, 2025 12:15
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
forRecipients: recipients
self assertAllAddressesAreValid: recipients.
self assertThereAreNoDuplicates: recipients.
^self new initializeForRecipients: recipients
@mcsee
mcsee / test06ExceptionalBehavior.st
Last active November 12, 2025 13:42
This gist belongs to Clean Code Cookbook http://cleancodecookbook.com By Maximiliano Contieri http://maximilianocontieri.com
test06ExceptionalBehavior
self
should:
[EmailMessage
forRecipients:
(Array with: '[email protected]' with: '[email protected]')]
raise: Exception