Skip to content

Instantly share code, notes, and snippets.

Simon Schick SimonSimCity

Block or report user

Report or block SimonSimCity

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
@SimonSimCity
SimonSimCity / bitshift.js
Created Mar 29, 2017
Takes an 8-bit string and encodes it to a 7-bit string (base64 compatible). Doesn't work with characters upover the 8th bit ...
View bitshift.js
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 Oct 13, 2016
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.
View mongodb-replace-UUID-BinData3-by-BinData4
// 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 Oct 13, 2016
Replaces a UUID that has been saved as BinData(0, "") as a UUID.
View mongodb-fix-uuid-0
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 Jun 14, 2019 — 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.
View brew-update-notifier.sh
#!/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 Jun 13, 2016
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
View guessTimeZone.php
<?php
$timezones = DateTimeZone::listIdentifiers();
$VTIMEZONE = array(
"TZID" => "Mitteleuropäische Zeit",
"DAYLIGHT" => array(
"RULE" => array(
"FREQ" => "YEARLY",
"BYDAY" => "-1SU",
View phpunit.xml.dist
<?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 Apr 5, 2013
Logrotate for php5-fpm ... first definition is for the log of the master-process, the second one is for every pool.
View php5-fpm
/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 Dec 15, 2015
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
View localhost
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 Oct 16, 2019
A gist for pagination in Twig, based on the total number of pages, the current page and some URL-settings.
View pagination.html.twig
{#
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
You can’t perform that action at this time.