Skip to content

Instantly share code, notes, and snippets.

View Stoffo's full-sized avatar

Stefan Lange Stoffo

  • Hamburg, Germany
  • 06:55 (UTC +02:00)
View GitHub Profile
@Stoffo
Stoffo / docker-compose.yml
Created December 14, 2023 15:14
MongoDb ReplicaSet with Docker
version: '3.8'
services:
mongo1:
image: mongo:latest
container_name: mongo1
networks:
- mongo-net
ports:
- "27017:27017"
@Stoffo
Stoffo / remove_documents_mongodb.js
Created October 29, 2015 12:29
Remove Documents older than x days in MongoDB
var date = new Date();
var daysToDeletion = 120;
var deletionDate = new Date(date.setDate(date.getDate() - daysToDeletion));
printjson(deletionDate);
var db = db.getSiblingDB('db')
db.getMongo().setSlaveOk();
printjson(db.messages.find({insertDate : {$lt : deletionDate}}).count());
@Stoffo
Stoffo / prepare-commit-msg
Created October 26, 2022 12:27
Prepend Ticket Number to Commit Message Hook
#!/bin/bash
COMMIT_FILE=$1
COMMIT_MSG=$(cat $1)
JIRA_URL="≤JIRA_BASE_URL>/browse/"
if [ -z "$BRANCHES_TO_SKIP" ]; then
BRANCHES_TO_SKIP=(master develop)
fi
@Stoffo
Stoffo / twig_file_date_extension.php
Last active May 24, 2020 07:47
Twig Function to get the file mtime in template for HTTP Caching
<?php
$function_filedate = new Twig_SimpleFunction(
'fileDate',
/**
* @param $file_path
* This function generates a new file path with the last date of filechange
* to support better better client caching via Expires header:
* i.e:
@Stoffo
Stoffo / github_pull_request_check.sh
Last active May 8, 2019 16:17
Checks The GitHub API for Pull Requests to Review and changes the color of Anybar
#!/usr/bin/env bash
GITHUB_USERNAME=
GITHUB_AUTH_TOKEN=
GITHUB_SEARCH_QUERY="is:open%20is:pr%20review-requested:Stoffo%20archived:false"
change_anybar_color () {
echo -n $1 | nc -4u -w0 localhost 1738
}
var defaultTitle = document.title;
// subscribe to visibility change events
document.addEventListener('visibilitychange', function () {
// fires when user switches tabs, apps, goes to homescreen, etc.
if (document.visibilityState === 'hidden') {
document.title = 'Baby, Come Back!'
}
// fires when app transitions from prerender, user returns to the app / tab.
if (document.visibilityState === 'visible') {
@Stoffo
Stoffo / http_statuscodes.php
Last active October 26, 2017 11:24
PHP Array with alle HTTP Status Codes
<?
$http_codes = array(
100 => 'Continue',
101 => 'Switching Protocols',
102 => 'Processing',
200 => 'OK',
201 => 'Created',
202 => 'Accepted',
203 => 'Non-Authoritative Information',
@Stoffo
Stoffo / palindrome.js
Last active December 10, 2015 12:52
Checks if String is a palindrome.
function palindrome(str) {
// Convert to lower case and replace everything what's not a letter or a number.
var x = str.toLowerCase().replace(/[^a-z0-9]/g, '');
//convert string to array, turn it around and put it back together an match it against filtered string:
return x.split('').reverse().join('') === x;
}
palindrome("eye");
@Stoffo
Stoffo / EcmaScript6_Examples.js
Created December 7, 2015 16:43
A few simple Examples in EcmaScript6 to play around with.
const PI = 3.1415926535;
function foo(a = 123, b = '') {
return PI
}
function bar(a, b, c, ...x) {
return x.length;
@Stoffo
Stoffo / counter_increment.html
Created November 23, 2015 16:34
A simple example how CSS Counters work
<style>
ul {
counter-reset: foo;
}
li:before {
counter-increment: foo;
content: 'Count: ' counter(foo);
}
</style>