Skip to content

Instantly share code, notes, and snippets.

@byrnedo
byrnedo / indexed_sql_file_runner.go
Last active October 23, 2020 06:10
Run sql commands from a file, saving position in a `.index` file in case of error.
package main
import (
"bufio"
"database/sql"
"flag"
"fmt"
"path"
"strconv"
"strings"
@byrnedo
byrnedo / nginx-json-log.conf
Last active May 20, 2020 13:39
Json Nginx Logging
map $msec $millis { ~(.*)\.(.*) $2; }
map $time_iso8601 $time_iso8601_m { ~(.*)\+(.*) $1.$millis+$2; }
log_format json_combined escape=json
'{'
'"_ms": "$millis",' # Has to be here in order for timestamp to work. Wat
'"timestamp": "$time_iso8601_m",'
'"service": "sp-frontend",'
'"remote_addr":"$remote_addr",'
'"message":"[$status] $request_method $request_uri",'
@byrnedo
byrnedo / httpclient.go
Created May 12, 2020 07:07
Comprehensive http client base in go
package client
import (
"bytes"
"context"
"crypto/tls"
"encoding/json"
"fmt"
"github.com/pkg/errors"
"io"
@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]);
@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 / 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 / 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 / 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 / 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 / .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/*