Skip to content

Instantly share code, notes, and snippets.

View SimonSimCity's full-sized avatar

Simon Schick SimonSimCity

View GitHub Profile
@SimonSimCity
SimonSimCity / bitshift.js
Created March 29, 2017 07:56
Takes an 8-bit string and encodes it to a 7-bit string (base64 compatible). Doesn't work with characters upover the 8th bit ...
const id = Random.id();
const bitEncode = (s) => {
let binString = '';
for (let i = 0; i < s.length; i++) {
const bin = (s.charCodeAt(i) - 20).toString(2);
const binSubString = (`0000000000${bin}`).slice(-7);
binString += binSubString;
}
@SimonSimCity
SimonSimCity / mongodb-replace-UUID-BinData3-by-BinData4
Created October 13, 2016 07:56
Rewrite all your UUIDs, that accidentially have been saved as BinData(3, "") as BinData(4, ""). But be careful! This script only takes one implementation of the three (Python, Java, C#) and treats all BinData(3, "") datasets like that. This can damage your data if you don't know what you're doing.
// Load this script: https://github.com/mongodb/mongo-csharp-driver/blob/master/uuidhelpers.js
// Start your mongo-shell with this script: mongo --shell uuidhelpers.js
// Find out what type of UUID it was. In my case it was PYUUID(). But it could (in your case) also be CSUUID() or JUUID().
db.tests.find(function() { return this.orderId.subtype() == 3 }).snapshot().forEach(function(elem) {
db.tests.update(
{
_id: elem._id
},
@SimonSimCity
SimonSimCity / mongodb-fix-uuid-0
Created October 13, 2016 07:51
Replaces a UUID that has been saved as BinData(0, "") as a UUID.
function decode_base64(s) {
var e={},i,k,v=[],r='',w=String.fromCharCode;
var n=[[65,91],[97,123],[48,58],[43,44],[47,48]];
for(z in n){for(i=n[z][0];i<n[z][1];i++){v.push(w(i));}}
for(i=0;i<64;i++){e[v[i]]=i;}
for(i=0;i<s.length;i+=72){
var b=0,c,x,l=0,o=s.substring(i,i+72);
for(x=0;x<o.length;x++){
@SimonSimCity
SimonSimCity / brew-update-notifier.sh
Last active November 5, 2023 09:30 — forked from stephennancekivell/brew-update-notifier.sh
Extended the script, written by @streeter to exclude the pinned formulae in the list of formulas to update.
#!/bin/bash
#
# Notify of Homebrew updates via Notification Center on Mac OS X
#
# Author: Chris Streeter http://www.chrisstreeter.com
# Requires: terminal-notifier. Install with:
# brew install terminal-notifier
TERM_APP='/Applications/Terminal.app'
BREW_EXEC='/usr/local/bin/brew'
@SimonSimCity
SimonSimCity / guessTimeZone.php
Last active June 13, 2016 07:00
A script to guess the timezone based on data provided in a VTIMEZONE object in an iCal file. The name is a non-olson-name. Those with olson-names are easy. Originally written for https://github.com/fruux/sabre-vobject/issues/44
<?php
$timezones = DateTimeZone::listIdentifiers();
$VTIMEZONE = array(
"TZID" => "Mitteleuropäische Zeit",
"DAYLIGHT" => array(
"RULE" => array(
"FREQ" => "YEARLY",
"BYDAY" => "-1SU",
<?xml version="1.0" encoding="UTF-8"?>
<!-- http://www.phpunit.de/manual/current/en/appendixes.configuration.html -->
<phpunit
backupGlobals = "false"
backupStaticAttributes = "false"
colors = "true"
convertErrorsToExceptions = "true"
convertNoticesToExceptions = "true"
convertWarningsToExceptions = "true"
@SimonSimCity
SimonSimCity / php5-fpm
Created April 5, 2013 09:39
Logrotate for php5-fpm ... first definition is for the log of the master-process, the second one is for every pool.
/var/log/php5-fpm.log {
daily
rotate 21
missingok
notifempty
sharedscripts
postrotate
kill -USR1 `cat /opt/php/logs/nginx.pid`
endscript
}
@SimonSimCity
SimonSimCity / localhost
Last active December 15, 2015 19:18
You can use php_inkl_pathinfo for websites that want to support pathinfo - otherwise you can use php and just drop the pathinfo stuff ;) The php-configuration is
server {
server_name localhost linos;
root /srv/http/$host/www;
index index.php index.html index.htm;
access_log /srv/http/$host/log/nginx.access.log;
error_log /srv/http/localhost/log/nginx.error.log;
location / {
@SimonSimCity
SimonSimCity / pagination.html.twig
Last active September 30, 2023 17:29
A gist for pagination in Twig, based on the total number of pages, the current page and some URL-settings.
{#
Source: http://dev.dbl-a.com/symfony-2-0/symfony2-and-twig-pagination/
Updated by: Simon Schick <simonsimcity@gmail.com>
Parameters:
* currentFilters (array) : associative array that contains the current route-arguments
* currentPage (int) : the current page you are in
* paginationPath (string) : the route name to use for links
* showAlwaysFirstAndLast (bool) : Always show first and last link (just disabled)
* lastPage (int) : represents the total number of existing pages