Skip to content

Instantly share code, notes, and snippets.

@bastiankoetsier
bastiankoetsier / Makefile
Last active October 13, 2017 10:18 — forked from mcastilho/Makefile
Standard makefile for go
.PHONY: all tags clean test build install generate image release
REGISTRY_REPO = <..redacted..>
OK_COLOR=\033[32;01m
NO_COLOR=\033[0m
ERROR_COLOR=\033[31;01m
WARN_COLOR=\033[33;01m
# Build Flags
@bastiankoetsier
bastiankoetsier / MacroProvider.php
Last active December 25, 2015 11:36
String Nth-position Laravel
Str::macro('nth_position',function($str, $letter, $n, $offset = 0){
$str_arr = str_split($str);
$letter_size = array_count_values(str_split(substr($str, $offset)));
if( !isset($letter_size[$letter])){
return false;
} else if($letter_size[$letter] < $n) {
return false;
}
for($i = $offset, $x = 0, $count = (count($str_arr) - $offset); $i < $count, $x != $n; $i++){
if($str_arr[$i] == $letter){
@bastiankoetsier
bastiankoetsier / eloquent-join.php
Created July 6, 2015 11:23
Forces eloquent to join tables instead of eager-loading. useful for filtering & orderin
/**
* @param $query
* @param $relation_name
* @param string $operator
* @param string $type
* @param bool $where
* @return mixed
*/
public function scopeModelJoin($query, $relation_name, $operator = '=', $type = 'left', $where = false)
{
@bastiankoetsier
bastiankoetsier / copy-table
Created November 24, 2014 08:52
If you want to copy a table from one Database to another database
CREATE TABLE db2.table LIKE db1.table;
INSERT INTO db2.table SELECT * FROM db1.table;
@bastiankoetsier
bastiankoetsier / ssh-config
Created November 7, 2014 07:50
SSH via jumphost in ssh-config
Host jumphost
Hostname JUMPHOST_IP
(User USERNAME_JUMPHOST)
Host target
Hostname TARGET_IP
(User USERNAME_TARGET)
ProxyCommand ssh -q -A -x jumphost -W %h:%p
@bastiankoetsier
bastiankoetsier / php-gunzip
Last active September 14, 2020 11:13
Uncompress .gz-files with php
//This input should be from somewhere else, hard-coded in this example
$file_name = '2013-07-16.dump.gz';
// Raising this value may increase performance
$buffer_size = 4096; // read 4kb at a time
$out_file_name = str_replace('.gz', '', $file_name);
// Open our files (in binary mode)
$file = gzopen($file_name, 'rb');
$out_file = fopen($out_file_name, 'wb');
// Keep repeating until the end of the input file
while(!gzeof($file)) {
@bastiankoetsier
bastiankoetsier / provision.sh
Created August 27, 2014 12:59
Basic provisioning 4 vagrant
#!/usr/bin/env bash
# Install Some PPAs
apt-get install -y software-properties-common
apt-add-repository ppa:nginx/stable -y
apt-add-repository ppa:ondrej/php5 -y
# Update Package Lists
apt-get update
# Register All Of The Configured Shared Folders
settings["folders"].each do |folder|
#config.vm.synced_folder folder["map"], folder["to"], type: folder["type"] ||= nil
config.vm.synced_folder folder["map"], folder["to"],
id: folder["map"],
:nfs => true,
:mount_options => ['nolock,vers=3,udp,noatime']
end
@bastiankoetsier
bastiankoetsier / gist:10233766
Last active August 29, 2015 13:58
Remove BOM
<?php
$string = str_replace("\xEF\xBB\xBF",'',$string);