Skip to content

Instantly share code, notes, and snippets.

View gerlacdt's full-sized avatar

Daniel Gerlach gerlacdt

View GitHub Profile
class Bar {
constructor() {
this.foo = "foo from Bar";
}
fooFunc() {
return this.foo;
}
}
class Foo {
@gerlacdt
gerlacdt / gracefulShutdown.js
Created October 25, 2016 07:33
Graceful shutdown of a nodejs server
'use strict';
/*
* Usage:
*
* const gracefulShutdown = require('./app/utils/gracefulShutdown');
*
* const server = app.listen(port, callback)
*
* gracefulShutdown.init(server, logger);
function getNickname(fullname) {
return fullname
.split(/\s+/)
.map(n => n.substring(0,3))
.join('');
}
const result = getNickname('Daniel Gerlach');
console.log(result); // => DanGer
@gerlacdt
gerlacdt / clock.py
Last active January 22, 2019 21:10
"""Simple clock implementation which supports basic functions like
addition and subtracting minutes. Time overflows are supported.
"""
# number of minutes of a day
day_minutes = 24 * 60
class Clock():
def __init__(self, hours, minutes):
// from Clean Code chapter 10
// listing 10-8
package literatePrimes;
import java.util.ArrayList;
public class PrimeGenerator {
private static int[] primes;
private static ArrayList<Integer> multiplesOfPrimeFactors;
@gerlacdt
gerlacdt / duplicate_zeros.py
Last active July 25, 2021 20:07
Duplicate Zeros (Leetcode)
""""Given a fixed length array arr of integers, duplicate each occurrence
of zero, shifting the remaining elements to the right.
Note that elements beyond the length of the original array are not
written.
Do the above modifications to the input array in place, do not return
anything from your function.
# Program collects all primes less than or equal n.
# It uses the Sieve of Eratosthenes algorithm, see
# https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes
def primes(n):
# Initializes start array with n-entries, all numbers are primes initially
prime = [True for i in range(n + 1)]
# 0 and 1 are no primes