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 / flickr-data-restore.go
Created January 25, 2020 19:43
Flickr data recovery script
package main
import (
"encoding/json"
"io/ioutil"
"log"
"os"
"path/filepath"
"strings"
"time"
@Dynom
Dynom / circle.yml
Created September 13, 2016 07:45
A Go CircleCI config file
checkout:
post:
# Remove a CircleCI directive that confuses our override, if it exists..
- git config --global --unset "url.git@github.com:.insteadof" ; if [ $? -eq 0 -o $? -eq 5 ]; then true; else false; fi; echo $?
- git config --global url."https://${GITHUB_TOKEN}:x-oauth-basic@github.com/".insteadOf "https://github.com/"
dependencies:
pre:
# Temporary, using Go 1.7
- curl -O https://storage.googleapis.com/golang/go1.7.linux-amd64.tar.gz && tar -xvf go1.7.linux-amd64.tar.gz && sudo bash -c 'rm -rf /usr/local/go && mv go /usr/local'
- go get -u github.com/alecthomas/gometalinter && gometalinter -ui
@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.
package Random
import (
"strings"
"testing"
)
func BenchmarkSplitOrSuffixMatching(b *testing.B) {
const path = "/baz"
@Dynom
Dynom / gist:a2cc7f0d4938133e8961d00eb22b943e
Created January 16, 2017 10:32
Reclaim Docker claimed disk space on macOS
You can reclaim your host's disk-space on macOS in the new Docker 1.13, reducing the file size of the `Docker.qcow2` file.
Steps:
1. du -sh ~/Library/Containers/com.docker.docker/Data (Check current disk usage)
2. docker run --rm -it --privileged --pid=host walkerlee/nsenter -t 1 -m -u -i -n fstrim /var
3. restart docker (starting it might take a while)
4. du -sh ~/Library/Containers/com.docker.docker/Data
Additional:
* Checkout: docker system prune --help
@Dynom
Dynom / change-raw-JSON.go
Created September 21, 2016 13:19
Instead of (Un)marshalling into a valid struct, when you only care only about one field (in perhaps a dynamic JSON document) you could do the following
package main
import "fmt"
import "encoding/json"
const data = `{"a": "A", "b": "B", "c": "C"}`
func main() {
var objmap map[string]*json.RawMessage
err := json.Unmarshal([]byte(data), &objmap)
import (
"github.com/go-kit/kit/endpoint"
"github.com/go-kit/kit/log"
"golang.org/x/net/context"
// ...
)
func MakeJSONRPCEndpoint(registry RPCMethodRegistry, logger log.Logger) endpoint.Endpoint {
return func(_ context.Context, request interface{}) (interface{}, error) {
typedRequest := request.(JSONRPCRequest)

Keybase proof

I hereby claim:

  • I am dynom on github.
  • I am dynom (https://keybase.io/dynom) on keybase.
  • I have a public key whose fingerprint is A121 FAEC 0A97 0D76 7478 DB9C C3DE 78B7 CDE2 A243

To claim this, I am signing this object:

@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 / 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);