Skip to content

Instantly share code, notes, and snippets.

Sebastian Klepper sklppr

Block or report user

Report or block sklppr

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View tree0.ts
module Tree0 {
type Tree<T> = Empty | Node<T>;
class Empty {
public toString(): string {
return "Empty";
}
}
@sklppr
sklppr / 0-refresher.md
Created Apr 5, 2017
Advanced application architecture
View 0-refresher.md

Refresher on anti-patterns and best practices

Most important basic philosophy “simple vs. easy”: Rails Conf 2012 Keynote: Simplicity Matters by Rich Hickey (Slides)

You probably know this already and in Ruby not all of it is done “explicitly” but it’s important to have these principles in mind when getting to know the following architecture concepts.

STUPID: Singleton, Tight Coupling, Untestability, Premature Optimization, Indescriptive Naming, Duplication
SOLID: Single Responsibility, Open/Closed, Liskov Substitution, Interface Segregation, Dependency Inversion

View r.sh
#!/bin/bash
# Install a custom R version, https://www.r-project.org/
#
# Add at least the following environment variables to your project configuration
# (otherwise the defaults below will be used).
# * R_VERSION
#
# Include in your builds via
# source /dev/stdin <<< "$(curl -sSL https://gist.githubusercontent.com/sklppr/cec1b80642e02a12d4e57bc51d803c2e/raw/089ca9b56d6b2364df29db4e78039c3404ce437f/r.sh)"
R_VERSION=${R_VERSION:="3.3.0"}
@sklppr
sklppr / 5_reflection.rb
Created Sep 2, 2016
Immutable domain model
View 5_reflection.rb
module SnakeCase
refine String do
def snake_case
self.gsub(/::/, '/')
.gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2')
.gsub(/([a-z\d])([A-Z])/,'\1_\2')
.tr("-", "_")
.downcase
end
end
@sklppr
sklppr / forwardable.rb
Last active May 16, 2019
Separating model from ActiveRecord with delegation/decorator pattern.
View forwardable.rb
require "forwardable"
module ActiveRecord
class Base
def save
puts "SAVED #{name}"
end
@sklppr
sklppr / compare-langs.md
Created Apr 21, 2014
Comparison of simple actions in different languages.
View compare-langs.md

Select all elements in a that are greater than 5 and multiply them by 2.

Ruby

a.select { |x| x > 5 }.map { |x| x * 2 }

a.find_all { |x| x > 5 }.collect { |x| x * 2 }

a.inject([]) { |b, x| x > 5 ? (b << x * 2) : b }
@sklppr
sklppr / coupon.rb
Created Jan 28, 2014
Coupon code generator with customizable number of parts, number of characters per part and separator.
View coupon.rb
def coupon(parts: 4, chars: 4, separator: "-")
SecureRandom.hex(parts*chars/2).upcase.scan(%r/.{#{chars}}/).join(separator)
end
@sklppr
sklppr / markdown2html.rb
Last active Dec 30, 2015 — forked from brentsimmons/generate_html.rb
Batch conversion of Markdown to HTML.
View markdown2html.rb
#!/usr/bin/env ruby
require "fileutils"
require "redcarpet"
OUTPUT_FOLDER = "html"
HTML_TEMPLATE = <<-HTML
<!DOCTYPE html>
<html>
View books-on-design.md

Books on Design

General

Design is a Job (Mike Monteiro)
The Design of Everyday Things (Don Norman)
Emotional Design (Don Norman)
Universal Principles of Design: A Cross-Disciplinary Reference (William Lidwell)
Designed for Use (Lukas Mathis)
The Shape of Design (Frank Chimero)

@sklppr
sklppr / twitter-friends.rb
Created Sep 13, 2012
Fetches info about the people you follow on Twitter and determines who you could/should unfollow.
View twitter-friends.rb
# encoding: utf-8
#####################################################################################
#
# Fetches info about the people you follow on Twitter
# and determines who you could/should unfollow based on:
# - activity: was their last update more than 3 months ago?
# - popularity: do they have less than 25 followers?
# - mass following: are they following more than 10000 people?
You can’t perform that action at this time.