Skip to content

Instantly share code, notes, and snippets.

View kimhogeling's full-sized avatar

Kim Hogeling kimhogeling

  • interpersonal GmbH
  • Hamburg
View GitHub Profile
@kimhogeling
kimhogeling / javascript_inheritance.md
Last active August 29, 2015 14:20
JavaScript Inheritance

TL;DR. Take me to the example!

Prototype chaining

JavaScript inheritance is all about prototype chaining. To create one, simply set the prototype of an instance of a subtype equal to the one of an instance of the supertype. I use Object.create() for that. There is one problem though: how to inherite the supertype's properties?. This is where constructor stealing comes in.

Constructor stealing

The subtype can inherit supertypes properties, by calling the constructor of the supertype. I use call() for that. The combination of prototype chaining and constructor stealing is called pseudo classical inheritance, because it is not exactly like in class based languages, but does behave the same.

@kimhogeling
kimhogeling / sortArrayContainingArraysByKey.md
Last active August 29, 2015 14:23
sort an array containing arrays with help of a given key

This function can be used to sort arrays which contain arrays. It does this with help of a given key. This key represents which of the inner arrays item should be used for the sorting.

/**
 * Sort an array which is filled with arrays.
 * The given key of the array items indicates how to sort.
 * 0 stands for the first item of each array, 1 stands for the second item of each array, etc.
 * @param Number arrKey The key of the array items which indicate how to sort.
@kimhogeling
kimhogeling / undoredo.js
Created November 3, 2015 19:05
Undo/Redo with command pattern in javascript
/**
* The command supertype, which is inherited by subtype commands.
* @constructor
* @param {type} normalAction The normal action.
* @param {type} undoAction The opposite of the normal action.
* @param {type} actionValue The value, which will get passed to the action.
* @returns {Command}
*/
function Command(normalAction, undoAction, actionValue) {
this.execute = normalAction;
@kimhogeling
kimhogeling / min_max_s24_productbox_width.js
Last active January 14, 2016 09:20
min/max width of product boxes shopping24
// Code zum Messen, einfach in die Console ausführen und Fenster groß/klein ziehen
var min = 9999, max = 1, product = $('.product');
window.onresize = function () {
var w = product.getBoundingClientRect().width;
if (w < min) {
min = w;
}
if (w > max) {
max = w;
}
window.s24.modules.pushnotificationslp = (function (s24js) {
'use strict';
var subscribtionState = {
'men': 'false',
'sale': 'false',
'women': 'false'
};
@kimhogeling
kimhogeling / google_predictions.js
Last active February 11, 2016 08:31
Search Google Predictions with help of a given array and print them with tabs to copy paste into spreadsheets
/**
* Created in Chrome. Uses `fetch` API and the high order functions `map` and `forEach`.
* Module `googlePredictions` reveals two functions `fetchAndPrint` and `formattedPrint`.
* method `fetchAndPrint` needs an {Array} argument containing {string} search words.
* example: `googlePredictions.fetchAndPrint(['adidas', 'puma', 'nike', 'apple']);`
* method `formattedPrint` assumes `fetchAndPrint` was already called and needs no arguments.
* Example `googlePredictions.formattedPrint();`
* This is helpful in case one or more rows could not be fetched,
* and the automatic print at `fetchAndPrint` was not called.
*/
@kimhogeling
kimhogeling / shopping24PromiseSuggestor.js
Created March 11, 2016 17:58
Fun with promises using the suggestor of shopping24.de
/**
* Let's have some fun with promises using the suggestor of shopping24.de
* The coolness is at the bottom of this file!
* Caution: This code only works in the console of shopping24.de because we don't allow cross domain calls
*/
/**
* This is where the magic happens
* The AJAX is wrapped by a shiny Promise
*/
@kimhogeling
kimhogeling / .profile
Created April 7, 2016 08:06
my .profile
# git branch
# ==========
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/🍃 \1/'
}
export PS1="\`if [ \$? != 0 ]; then echo 🙈 🙉 🙊; fi\`\n⏰ \e[31m\]\t 👾 \[\e[34m\]\w\[\033[32m\] \$(parse_git_branch)\[\e[00m\]\n🎸 "
# colors
# ======
export CLICOLOR=1
@kimhogeling
kimhogeling / sandwich_fp.js
Created July 11, 2016 08:06
The sandwich functional programming image into code
/**
* Work in progress.. does not work yet
*/
var recipe = [
{ name: 'bread', slices: 2 },
{ name: 'cucumber', slices: 6 },
{ name: 'paprika', slices: 8 },
{ name: 'tomato', slices: 5 },
{ name: 'salad', slices: 15 },
@kimhogeling
kimhogeling / serviceworker_wk.js
Created July 28, 2016 13:05
Service Worker of the shopping24 hacking days wohnklamotte prototype
/**
* KH: Warning! This is part of a prototype made during our early 2016 hacking days and is not suitable for production!
*/
const VERSION = 's24-wokl-social-v6'
const CACHE_FILES = [
'/',
'/index.html',
'/public/css/card.css',