Skip to content

Instantly share code, notes, and snippets.

View test.snippet
// Länder sollen Vertikal von A-Z anstatt Horizontal sortiert werden
function sort_market_verticaly($markets, $marketColumns = 5) {
$countMarkets = count($markets);
$numMarketsPerBlock = intval($countMarkets / $marketColumns);
$leftOver = $countMarkets % $marketColumns;
$newSortMarkets = array();
for ($i = 0, $marketCount = 0; $i < $marketColumns && $marketCount < $countMarkets; $i++) {
for ($j = 0; $j < $numMarketsPerBlock; $j++) {
$newSortMarkets[$i][] = $markets[$marketCount];
@Norcoen
Norcoen / flatArray.php
Created Nov 27, 2015
php function that Recursively converts nested array into a flat one with preserved keys connected with connector.
View flatArray.php
<?php
/**
* Recursively converts nested array into a flat one with keys preserving.
* @param array $result Resulting array
* @param array $array Source array
* @param string $prefix Key's prefix
* @param string $connector Levels connector
*/
function flatArray(array &$result, array $array, $prefix = null, $connector = '.') {
foreach ($array as $key => $value) {
@Norcoen
Norcoen / PHPExcel_Basics.md
Created Jan 5, 2016 — forked from r-sal/PHPExcel_Basics.md
PHPExcel Notes and code snippets
View PHPExcel_Basics.md

Basics

Creating a new PHPExcel Object.

    $this->PHPExcel = new PHPExcel();

Working with sheets

Creating a new sheet:

@Norcoen
Norcoen / iptables.sh
Created Feb 10, 2016 — forked from thomasfr/iptables.sh
iptable rules to allow outgoing DNS lookups, outgoing icmp (ping) requests, outgoing connections to configured package servers, outgoing connections to all ips on port 22, all incoming connections to port 22, 80 and 443 and everything on localhost
View iptables.sh
#!/bin/bash
IPT="/sbin/iptables"
# Server IP
SERVER_IP="$(ip addr show eth0 | grep 'inet ' | cut -f2 | awk '{ print $2}')"
# Your DNS servers you use: cat /etc/resolv.conf
DNS_SERVER="8.8.4.4 8.8.8.8"
# Allow connections to this package servers
View recursive_array_walk_recursive.php
<?php
class A
{
private $ab = 5;
public $ac = 6;
}
/**
* WARNING: This https://bugs.php.net/bug.php?id=45937 seems not yet solved
@Norcoen
Norcoen / vm-resize-hard-disk.md
Created Mar 1, 2016 — forked from christopher-hopper/vm-resize-hard-disk.md
Resize a Hard Disk for a Virtual Machine provisioned using Vagrant from a Linux base box to run using VirutalBox.
View vm-resize-hard-disk.md

Resize a Hard Disk for a Virtual Machine

Our Virtual Machines are provisioned using Vagrant from a Linux base box to run using VirutalBox. If the Hard Disk space runs out and you cannot remove files to free-up space, you can resize the Hard Disk using some VirtualBox and Linux commands.

Some assumptions

The following steps assume you've got a set-up like mine, where:

@Norcoen
Norcoen / code.md
Created May 2, 2016 — forked from weakish/code.md
The Six Most Common Species Of #Code #java #fun
View code.md
View reset_iptables.sh
# IPv6
##
## set default policies to let everything in
ip6tables --policy INPUT ACCEPT;
ip6tables --policy OUTPUT ACCEPT;
ip6tables --policy FORWARD ACCEPT;
##
## start fresh
@Norcoen
Norcoen / Documentation.md
Created Jun 20, 2016 — forked from KartikTalwar/Documentation.md
Rsync over SSH - (40MB/s over 1GB NICs)
View Documentation.md

The fastest remote directory rsync over ssh archival I can muster (40MB/s over 1gb NICs)

This creates an archive that does the following:

rsync (Everyone seems to like -z, but it is much slower for me)

  • a: archive mode - rescursive, preserves owner, preserves permissions, preserves modification times, preserves group, copies symlinks as symlinks, preserves device files.
  • H: preserves hard-links
  • A: preserves ACLs
@Norcoen
Norcoen / hexdump.php
Created Jul 8, 2016
Dump PHP String as HEX
View hexdump.php
<?php
/* Found at http://stackoverflow.com/questions/1057572/how-can-i-get-a-hex-dump-of-a-string-in-php */
function hex_dump($data, $newline="\n")
{
static $from = '';
static $to = '';
static $width = 16; # number of bytes per line