Skip to content

Instantly share code, notes, and snippets.

View EbbeVang's full-sized avatar

Ebbe Vang EbbeVang

View GitHub Profile
@EbbeVang
EbbeVang / clean_code.md
Created September 9, 2021 19:45 — 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

import graph.Graph;
public class TestGraph {
public static void main(String[] args) {
// create graph
Graph<String> graph = new Graph<String>();
import javafx.scene.shape.Circle;
public class Citizen implements Comparable<Citizen> {
private String firstName;
private String lastName;
private long socialSecurityNumber;
public Citizen (String firstName, String lastName, long socialSecurityNumber)
{
@EbbeVang
EbbeVang / gist:5c123b67421c3d48f2a9dd97fc05fbbb
Created March 6, 2019 13:32
Exercise for EC2: implement the citizen class
//the main method
ArrayList<Citizen> citizens = new ArrayList<>();
citizens.add(new Citizen("Liv", "Vang", 2911071234L));
citizens.add(new Citizen("Liv", "Andersen", 1505011234L));
citizens.add(new Citizen("Ebbe", "Vang", 2312721234L));
citizens.add(new Citizen("Ebbe", "Vang", 2412721234L));
Collections.sort(citizens);
System.out.println(citizens);
BROADCAST_TO_PORT = 7000
import time
from socket import *
from datetime import datetime
s = socket(AF_INET, SOCK_DGRAM)
#s.bind(('', 14593)) # (ip, port)
# no explicit bind: will bind to default IP + random port
s.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
while True:
var canvas = document.getElementById("myCanvas");
var ctx = canvas.getContext("2d");
ctx.fillStyle = "#FF0000";
ctx.fillRect(0,0,150,75);
@EbbeVang
EbbeVang / gist:61d9e7229f34a761857d110a19634097
Created November 4, 2018 23:33
axios - get with headers
import axios, { AxiosRequestConfig, AxiosPromise } from 'axios';
axios.get("http://api.evang.dk/randomwords/", {
'headers':
{
'numberOfWords': 5,
'maxWordLength': 10,
'minWordLength': 8,
}
})
public interface Engine {
/**
* starts the engine
* @return true if it wasn't already started
*/
boolean start();
/**
* stops the engine
import javafx.scene.paint.Color;
public interface Car {
boolean isStarted();
/**
* This method tells you whether the car is started or not
* @return true if the car i sstarted
*/
boolean start();
import java.util.logging.Level;
import java.util.logging.Logger;
import org.newdawn.slick.*;
public class SimpleSlickGame extends BasicGame
{
Image img;
int x=100;
int y=100;