Skip to content

Instantly share code, notes, and snippets.

View sgruetter's full-sized avatar

René Bernhardsgrütter sgruetter

View GitHub Profile
@sgruetter
sgruetter / clean_code.md
Created November 18, 2019 05:54 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@sgruetter
sgruetter / incrementFilename.js
Created May 16, 2019 05:59
incrementFilename increments filenames - check before if the file name already exists.
function incrementFilename(name) {
if (!name) {
return '';
}
var matches = /^((.*) \()(-?[0-9]+)(\)(\.[a-zA-Z_0-9]+)?)$/ig.exec(name);
if (matches && matches.length === 6) {
// The file name already has an incremented number in the name (e.g. 'file (1).png' or 'file (1)')
return matches[1] + (parseInt(matches[3]) + 1) + matches[4];