Skip to content

Instantly share code, notes, and snippets.

@byrnedo
byrnedo / ComputeHmac256.go
Created September 12, 2016 07:32
Compute a hmac for a message in golang
func ComputeHmac256(message string, secret string) string {
key := []byte(secret)
h := hmac.New(sha256.New, key)
h.Write([]byte(message))
return base64.StdEncoding.EncodeToString(h.Sum(nil))
}
@byrnedo
byrnedo / compose-merge.pl
Last active March 7, 2018 07:56
Stand in to merge docker compose file merging (docker stack deploy doesn't do the magic yet), does the 'extends' replacement and the env var replacement.
#!/usr/bin/perl
#
#====================================================
#
# Stand in for docker-compose 'extends' and env replacement
# ( currently not implemented for `docker stack deploy -f` )
#
#====================================================
use strict;
@byrnedo
byrnedo / AppServiceProvider.php
Last active May 20, 2017 15:55
Add Nullable If validator in laravel 5.4
<?php
...
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
@byrnedo
byrnedo / .BuildDockerfile
Last active January 27, 2024 17:25
Go project Makefile with build done in docker
FROM golang:1.9-alpine
# vi: ft=dockerfile
RUN apk update && apk add curl \
git \
protobuf \
bash \
make \
openssh-client && \
rm -rf /var/cache/apk/*
@byrnedo
byrnedo / http-health-slack.sh
Created May 15, 2018 08:56
Check urls for 200s or send slack message
#!/bin/bash
WORK_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
set -ueo pipefail
checkTimeout=6
SEND_ERROR_MAIL=1
cd "$WORK_DIR"
function send_to_slack {
local status=$1
@byrnedo
byrnedo / RequestLogMiddleware.cs
Last active August 10, 2018 13:27
Access log middleware for aspnetcore. Add it as your first middleware.
namespace Foobar
{
public class RequestLogMiddleware
{
public class LogData {
public IPAddress RemoteAddr {get;set;}
public string User {get;set;}
public int ResponseStatus {get;set;}
@byrnedo
byrnedo / Startup.vb
Created January 11, 2019 12:23
VB Dotnet Owin Auth0 Startup
Imports Microsoft.Owin
Imports Microsoft.Owin.Security.OpenIdConnect
Imports Owin
Imports Microsoft.Owin.Security
Imports Microsoft.Owin.Security.Notifications
Imports Microsoft.Owin.Security.Cookies
Imports Microsoft.IdentityModel.Protocols.OpenIdConnect
Imports Microsoft.IdentityModel.Tokens
Imports System.Threading.Tasks
@byrnedo
byrnedo / aspnet-des-cookie-maker.js
Last active July 16, 2020 09:20
Javascript module to encrypt, decrtypt, serialize and deserialize a DES encrypted cookie from a Dotnet Aspnet application
@byrnedo
byrnedo / tutils.go
Created January 29, 2020 10:09
Small assertion helper for testing in go
package tutils
import (
"path"
"reflect"
"runtime"
"testing"
)
func AssertNotNil(t *testing.T, obj interface{}) {
@byrnedo
byrnedo / useCheckbox.ts
Created April 24, 2020 13:26
Hook for checkbox functionality
import React, {useCallback, useMemo} from 'react';
export const useCheckbox = (allValues: string[], selected: string[], onChange: (newSelection: string[]) => void) => {
const selectedStatesObj = useMemo(() => (selected || []).reduce((p, c) => ({
...p,
[c]: true
}), {} as {[id: string]: boolean}), [selected]);