Skip to content

Instantly share code, notes, and snippets.

View Dynom's full-sized avatar
👋
Hi, how are you today!

Mark van der Velden Dynom

👋
Hi, how are you today!
View GitHub Profile
@Dynom
Dynom / gist:9618999
Created March 18, 2014 12:19
Redis unexpected behaviour when enabling AOF after the fact.
Steps to reproduce:
# Make sure that in your redis.conf:
appendonly no
# Also make sure that, in your redis.conf:
dbfilename FOO-dump.rdb
save "900 1"
save "300 10"
save "60 10000"
<?php
$scheduler = new Scheduler();
$batch = new Batch(new BatchContext(/* ... */), new ThrottleBatchStrategy());
// Add jobs
$batch->addJob(new FooJob( new JobContext() ));
@Dynom
Dynom / 0_reuse_code.js
Created January 22, 2014 07:54
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@Dynom
Dynom / gist:5866837
Last active December 5, 2017 14:05
Creating ISO 8601-extended in PHP, using DateTime. This includes milliseconds (and if you want, microseconds). Based on the work mentioned here: http://stackoverflow.com/a/4414060/1061927
<?php
// Our input
$time = microtime(true);
// Determining the microsecond fraction
$microSeconds = sprintf("%06d", ($time - floor($time)) * 1000000);
// Creating our DT object
$tz = new DateTimeZone("Etc/UTC"); // NOT using a TZ yields the same result, and is actually quite a bit faster. This serves just as an example.
@Dynom
Dynom / file-bucket-strategy.php
Created April 10, 2013 07:50
Calculating a uniform distribution with respect to file-system limitation's (files/sub-directories per directory)
<?php
$networkEID = '0b3fe...a';
$fileEID = 'af4e0...f'
// e.g.: 19c679c10770acc216c26045cc5406c8155
$largeNumber = hash("sha1", $fileEID);
// Converting from base-16 to base-13
$hash = gmp_strval(gmp_init($largeNumber, 16), 13);
@Dynom
Dynom / PRNG-test.php
Created March 31, 2013 12:44
Result of a run from the POC-PRNG-test/PRNG-test.php script, using openssl_random_pseudo_bytes(32). Goal of the test is to measure entropy exhaustion.
<?php
/**
* This script will generate a bunch of random data to test the exhaustion of kernel entropy.
*
* @author Mark van der Velden <mark@dynom.nl>
*
*
* Entropy can be checked at: /proc/sys/kernel/random/entropy_avail
*
* Tools like RND-tools can help keep the entropy above acceptable ranges. While this doesn`t (necessarily) improve
@Dynom
Dynom / curie-example.hal.json
Last active December 14, 2015 22:39
Dealing with root-level curies in the HAL specification. This example is a modified version of the one mentioned on: http://stateless.co/hal_specification.html This example introduces a root-level _links definition with CURIE definitions. These definitions must be available in nested attributes, with the option to override a CURIE definition, wi…
{
"_links": {
"api-root:self": { "href": "orders" },
"api-root:next": { "href": "orders?page=2" },
"api-root:find": { "href": "orders{?id}", "templated": true },
"api-root:admin": [
{ "href": "admins/2", "title": "Fred" },
{ "href": "admins/5", "title": "Kate" }
],
"_curies" : [
@Dynom
Dynom / gist:5003750
Last active December 14, 2015 01:09
Obtaining various fractions of time, using the microtime() function
<?php
$time = microtime(true);
$seconds = (int) $time;
$milliseconds = (int) ($time * 1000);
$microseconds = (int) ($time * 1000000);
$nanoseconds = (int) ($time * 1000000000);
echo "seconds : $seconds\n"
@Dynom
Dynom / shiftin.php
Last active December 12, 2015 09:49
<?php
/**
* @author Mark van der Velden <mark@dynom.nl>
*/
/*
* Given, the following specification:
* - part 1, 40 bits wide -- a number between 0 - 1099511627775
* - part 2, 5 bits wide -- a number between 0 - 31
* - part 3, 9 bits wide -- a number between 0 - 511
@Dynom
Dynom / runMigration.sh
Created January 2, 2013 16:12
This current Doctrine2 migrations shell wrapper fails, with the following message: "The specified connection file is a valid file", when run like this: ./bin/runMigrations.sh migrations:status The message is a typo, the actual message is about the connection file being NOT valid. When I paste the result (from the debug feedback, at the bottom of…
#!/usr/bin/env bash
# The arguments
ARGS="$@";
PHP_EXEC="$( which php )"
# TRYING to obtain the path we're located in.
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
EXECUTABLE="$DIR/../tools/migrations/doctrine-migrations.phar"