Skip to content

Instantly share code, notes, and snippets.

View dahse89's full-sized avatar

Philipp Dahse dahse89

View GitHub Profile
@dahse89
dahse89 / TreeBuilder.php
Last active June 24, 2016 11:02 — forked from mistic100/TreeBuilder.php
[PHP] Recursive builder pattern
<?php
/**
* Recursive builder pattern
*
* Usage:
* $tree = \Tree\Builder::init()
* ->setName('parent')
* ->addChild()
@dahse89
dahse89 / salesForceIdChecksum.func.php
Last active October 26, 2016 12:16
salesforce 15 digit to 18 digit id. Function to calculate the checksum.
<?php
function salesForceIdChecksum($id)
{
$map = implode('',array_merge(range('A', 'Z'), range(0, 9)));
$checksum = '';
foreach (str_split($id, 5) as $chunk) {
$checksum .= substr($map, bindec( strrev(array_reduce(str_split($chunk, 1),function($carry, $item){
$carry .= (!is_numeric($item) && $item == strtoupper($item)) ? '1' : '0';
@dahse89
dahse89 / stringSimilarity.php
Last active December 14, 2016 16:08
hackerrank stringSimilarity solution php
<?php
function stringSimilarity( $a) {
$a = trim($a);
$cutPrefix = $sum = 0;
$length = strlen($a);
do{
$count = 0;
while($a[$count] === substr($a,$cutPrefix+($count++), 1)){}
$sum += $count -1;
@dahse89
dahse89 / GeoOffsetByDistance.php
Created January 30, 2017 12:14
Creating a geo point from another and a distance. Means adding distance to geo point
<?php
/**
* Class GeoOffsetByDistance
*/
class GeoOffsetByDistance
{
//Earth’s radius, sphere in meters
const R = 6378137;
/** @var float */
@dahse89
dahse89 / cleaner.sh
Created February 28, 2017 17:09
Checks all files and directories next to itself. If there "last modified date" is older then given days (file_live_time_in_days) it remove those data.
#!/usr/bin/env bash
# cleaner.sh by Philipp Dahse <ph.dahse@gmail.com>
# ------------------------------------------------
# checks all files and directories next to itself.
# If there "last modified date" is older then given days (file_live_time_in_days)
# it remove those data.
# I use this script in something like a personal tmp directory:
#
# /home/my/tmp/cleaner.sh
<?php
/**
* Trait EnumTrait
* @author Philipp Dahse <ph.dahse@gmail.com>
*/
trait EnumTrait
{
/**
* @return array
let M = 255;
let C = (x,y) => (M - Math.sqrt((Math.pow(M-x,2)+Math.pow(M-y,2))/2)).toFixed(0);
let mixColors = (x,y) => [C(x[0],y[0]),C(x[1],y[1]),C(x[2],y[2])];
mixColors([255,125,23],[0,255,0]) // ["75","163","11"]
@dahse89
dahse89 / snowjob.sh
Created November 16, 2018 22:22 — forked from sontek/snowjob.sh
Make your terminal snow
#!/bin/bash
LINES=$(tput lines)
COLUMNS=$(tput cols)
declare -A snowflakes
declare -A lastflakes
clear
{
"type": "https://tools.ietf.org/html/rfc2616#section-10",
"title": "An error occurred",
"detail": "Class rray<string,string> does not exist",
"trace": [
{
"namespace": "",
"short_class": "",
"class": "",
"type": "",
@dahse89
dahse89 / docker-deployment.sh
Created April 29, 2022 10:55
Simple docker deployment
#!/bin/bash
docker context create remote --docker "host=ssh://user@remotemachine"
docker-compose -f docker-compose.production.yml --context remote up -d --no-deps --build