Skip to content

Instantly share code, notes, and snippets.

View gerbenjacobs's full-sized avatar
:fishsticks:

Gerben Jacobs gerbenjacobs

:fishsticks:
View GitHub Profile
@gerbenjacobs
gerbenjacobs / getIPRangeByCIDR.php
Last active December 4, 2018 06:15
Get the start and end IP from an IP Range by a CIDR (Classless Inter-Domain Routing) notation, complete or incomplete. As discussed here: https://blog.gerbenjacobs.nl/get-ip-range-by-cidr-notation.html
<?php
function getIPRangeByCIDR($cidr) {
// Making sure IPs are valid
$ipdata = explode('/', ltrim($cidr, '0'));
$dotcount = substr_count($ipdata[0], '.');
if ($dotcount != 3) {
$ipdata[0] .= str_repeat('.0', (3-$dotcount));
}
$cidr_address = sprintf('%s/%s', $ipdata[0], $ipdata[1]);
@gerbenjacobs
gerbenjacobs / habbo_giffer.sh
Created July 11, 2018 10:23
cURL request for animating a Habbo
curl -X POST \
https://www.habbo.com/giffer/animate \
-H 'Cache-Control: no-cache' \
-H 'Content-Type: application/x-www-form-urlencoded' \
-d code=user%20%22koeientemmer%22%2C%20%22com%22%0Agesture%20%22none%22%0Awalk%206%2C%20%22southwest%22%0Astand%200.4%0Aturn%20%22south%22%0Await%200.3%0Agesture%20%22smile%22%0Await%200.4%0Awave%203%0Await%200.8%0Astand%200.4
@gerbenjacobs
gerbenjacobs / zeropad.js
Last active December 7, 2017 13:24
A javascript function to zeropad (or prefill a number with any character) and return a padded string.
function zeropad(number, amount) {
if (number >= Math.pow(10, amount)) {
return number;
}
return (Array(amount).join(0) + number).slice(-amount);
}
zeropad(2); // 2
zeropad(2, 1); // 2
@gerbenjacobs
gerbenjacobs / laravel-mysql-with-pma.sh
Last active December 7, 2017 13:07
Starts MySQL and PHPMyAdmin as containers, linked and executes `php artisan migrate --seed` when they're ready
#!/usr/bin/env bash
# WARNING: This is ephemeral storage
export MSYS_NO_PATHCONV=1 # Windows: prevents path expansion in 'git bash' for volume mounting
NAME=project
NAME_DB=${NAME}-database
NAME_PMA=${NAME}-pma
@gerbenjacobs
gerbenjacobs / timeout.go
Created April 18, 2016 10:31
Golang Timeout with channels
package main
import (
"fmt"
"time"
)
var (
ch chan bool
timeoutSecs uint = 3
@gerbenjacobs
gerbenjacobs / empty-stdclass.php
Created May 6, 2013 13:32
Create an empty StdClass object
<?php
$person = (object) array_fill_keys(array('firstname', 'lastname', 'email', 'photo'), '');
?>