Skip to content

Instantly share code, notes, and snippets.

View rheinardkorf's full-sized avatar

Rheinard Korf rheinardkorf

View GitHub Profile
@rheinardkorf
rheinardkorf / example_test.go
Last active December 18, 2017 12:02
A very rugged way to do some mock endpoints with routes.
package example
import (
"testing"
"net/http/httptest"
"net/http"
"fmt"
"io/ioutil"
)
@rheinardkorf
rheinardkorf / main.go
Created February 15, 2018 12:39
Go: BTCMarkets Authentication Example
package main
import (
"crypto/hmac"
"time"
"strconv"
"fmt"
"net/http"
"io/ioutil"
"crypto/sha512"
@rheinardkorf
rheinardkorf / Makefile
Created February 23, 2018 05:28
Makefile for building and bundling a Go app as MacOS Application.
TITLE=My Title
BUNDLE_ID=com.rheinardkorf
PROJECT=MyApp
EXEC=app
VERSION=0.1
define plist
<?xml version="1.0" encoding="UTF-8"?> \
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
@rheinardkorf
rheinardkorf / snakeymap.go
Created May 28, 2018 11:39
Convert `map[string]interface{}` into a new `map[string]interface{}` with all keys converted to snake_case.
package snakeymap
func SnakeKeyMap(data map[string]interface{}) map[string]interface{} {
converted := make(map[string]interface{})
for key, val := range data {
goodKey := snakeKey(key)
switch v := val.(type) {
case map[string]interface{}:
@rheinardkorf
rheinardkorf / Dockerfile
Created June 8, 2018 05:58
Add MongoDB PHP driver (with SSL) to Docker image
# Get and make mongodb PHP driver
RUN yes | apt-get install libssl-dev \
&& git clone https://github.com/mongodb/mongo-php-driver.git --recursive \
&& cd mongo-php-driver \
&& phpize \
&& ./configure --with-mongodb-ssl=openssl \
&& make all \
&& make install \
&& echo "extension=mongodb.so" > /opt/php${SHORT_VERSION}/lib/conf.d/ext-mongodb.ini \
&& cd .. \
@rheinardkorf
rheinardkorf / index.html
Created July 24, 2018 11:16
Cloudinary DAM Widget Example
<!DOCTYPE html>
<html lang="en" dir="ltr">
<head>
<meta charset="utf-8">
<title>Demo</title>
<script src="https://media-library.cloudinary.com/global/all.js"></script>
<script type="text/javascript">
const mloptions = {
cloud_name: '<CHANGE_THIS>',
api_key: '<CHANGE_THIS>',
@rheinardkorf
rheinardkorf / slack-verify.php
Last active August 4, 2018 06:46
Verifying Slack Requests
<?php
/**
* Validate Slack notification signature.
*
* @see https://api.slack.com/docs/verifying-requests-from-slack
*
* @param array $headers POST headers.
* @param string $response_body JSON string of body.
* @param string $signing_secret Slack secret.
@rheinardkorf
rheinardkorf / docker-manager.php
Created March 23, 2017 22:29
Example spinning up containers from containers using Docker Engine API and PHP.
<?php
class DockerManager {
/**
* This is where the magic happens.
* The Docker Engine socket needs to be mounted in docker-compose.yml.
*
* volumes:
* - /var/run/docker.sock:/var/run/docker.sock
@rheinardkorf
rheinardkorf / brew-instructions.sh
Created March 9, 2019 10:32 — forked from petemcw/brew-instructions.sh
Setup dnsmasq on Mac OS X
# Install `dnsmasq` and configure for *.dev domains
$ brew install dnsmasq
$ vim /usr/local/etc/dnsmasq.conf
# Reload configuration and clear cache
$ sudo launchctl unload /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
$ sudo launchctl load /Library/LaunchDaemons/homebrew.mxcl.dnsmasq.plist
$ dscacheutil -flushcache
@rheinardkorf
rheinardkorf / with-theme-path.js
Created April 22, 2019 04:46
For posterity. Manually trying to implement component shadowing with Gatsby. So glad this is backed in by default.  😅
exports.withThemePath = (relativePath, root = __dirname) => {
const qualifiedPath = relativePath.replace('./src', `${root}/src`);
let qualifiedResolvedPath = path.resolve(qualifiedPath);
let finalPath = qualifiedResolvedPath;
const theme = path.basename(root);
const themedPath = relativePath.replace('./src', `./src/${theme}`);
let themedResolvedPath = path.resolve(themedPath);
try {