Skip to content

Instantly share code, notes, and snippets.

View nitschmann's full-sized avatar

Florian Nitschmann nitschmann

  • solarisBank AG
  • Germany
View GitHub Profile
@nitschmann
nitschmann / README.md
Last active August 7, 2024 17:17
Elevator Simulator

Challenge overview

The goal is the implementation a basic elevator simulation. The elevator stops at each requested floor. There are not such things as parallel calls for this challange, everything is rather sequential for this challenge.

Conditions and requirements

  1. The simulator runs everything within the main() function for now
  2. the elevator range is between a base floor (0) and maximum floor (6), these are statically defined as constants in the script
  3. The elevator should accept floor requests (which can simulate persons standing in a specific floor and requesting the lift) and process the requested floors in the order they have been received
@nitschmann
nitschmann / ssl_key_pairs.rb
Created August 17, 2017 13:25
Ruby script to generate OpenSSL Key-Pairs
require "openssl"
# could also be different
key_length = 4096
new_key = OpenSSL::PKey::RSA.generate(key_length)
public_key = new_key.public_key
public_key_string = public_key.to_s
@nitschmann
nitschmann / uuid_as_primary_key.rb
Created August 13, 2017 12:34
uuid as primary key
module UuidAsPrimaryKey
extend ActiveSupport::Concern
included do
before_create :assign_uuid
end
protected
def assign_uuid

Keybase proof

I hereby claim:

  • I am fnitschmann on github.
  • I am fnitschmann (https://keybase.io/fnitschmann) on keybase.
  • I have a public key whose fingerprint is F6F8 4EB1 FD20 30EA EF23 EF93 FC33 7F44 5276 D063

To claim this, I am signing this object:

@nitschmann
nitschmann / rmagick_2-12-2_mavericks.sh
Created July 23, 2014 10:06
Shell script to install Ruby rmagick -v '2.12.2' Gem with Homebrew under Mac OS X Mavericks
# This is a quick and dirty script for Max OS X Mavericks to install
# the Ruby rmagick Gem (Version 2.12.2) correct with Homebrew and ImageMagick
# Uninstall current ImageMagick (if installed)
if brew list -1 | grep -q "imagemagick"; then
brew uninstall imagemagick --force
fi
# Get all versions of ImageMagick via Homebrew
brew versions imagemagick
@nitschmann
nitschmann / ajax.js
Created July 21, 2014 10:33
Basic ajax handler function in JavaScript without jQuery
function ajax(url, method, data, async) {
method = typeof method !== 'undefined' ? method : 'GET';
async = typeof async !== 'undefined' ? async : false;
if (window.XMLHttpRequest) {
var xhReq = new XMLHttpRequest();
}
else {
var xhReq = new ActiveXObject('Microsoft.XMLHTTP');
}
@nitschmann
nitschmann / date_in.java
Created May 7, 2014 19:06
Java functions to get the date in N days
import java.util.Calendar;
import java.util.Date;
public Date dateIn(int days) {
Date date = new Date();
Calendar cal = Calendar.getInstance();
cal.setTime(date);
cal.add(Calendar.DATE, days);
cal.set(Calendar.MINUTE, 0);
@nitschmann
nitschmann / easter_day.rb
Last active March 15, 2016 13:45
Ruby implementation to find out the easter day date for a specific year (based on Anonymous Gregorian algorithm)
require "date"
# anonymous gregorian algorithm (http://en.wikipedia.org/wiki/Computus#Anonymous_Gregorian_algorithm)
def easter_day(year)
if year.is_a?(Integer)
y = year
# calculation
a = y % 19
b = y / 100
c = y % 100
@nitschmann
nitschmann / uninstall_homebrew.sh
Created December 10, 2013 09:17
Uninstaller for HomeBrew
#!/bin/sh
# This script uninstalls HomeBrew from your Mac completly
# Just copy and paste the lines below (all at once, it won't work line by line!)
function abort {
echo "$1"
exit 1
}
set -e
@nitschmann
nitschmann / green_console_matrix.rb
Created October 17, 2013 09:19
This is a sample for an endless matrix output in green for your console in Ruby
class String
# Print a String in a specfic color
def colorize(text, color_code)
"#{color_code}#{text}\e[0m"
end
# Green String
def green
colorize(self, "\e[1m\e[32m")
end
end