Skip to content

Instantly share code, notes, and snippets.

View regeda's full-sized avatar
🔦
Make code not war

Anthony Regeda regeda

🔦
Make code not war
View GitHub Profile
@regeda
regeda / allow_origin.js
Created February 14, 2022 11:46
Allow origin function for AWS CloudFront
function allowOriginFunc(allowOrigins) {
if (allowOrigins.length == 0) {
return function(o) { return true; };
}
var origins = [], wildcards = [];
allowOrigins.forEach(function(o) {
var i = o.indexOf('*');
if (i == -1) {
@regeda
regeda / backoff.sh
Created January 12, 2021 10:10
Backoff in Bash
function backoff_delay {
local -r -i factor=${BACKOFF_FACTOR-2}
local -i min=$(($1*$factor))
local -r -i max=$2
if [[ $max < $min ]]; then
min=$max
fi
echo $min
}
@regeda
regeda / main.go
Last active February 19, 2020 14:15
Test different TLS options in a server written in Go
package main
import (
"bufio"
"crypto/tls"
"crypto/x509"
"errors"
"flag"
"fmt"
"io"
@regeda
regeda / isdigit.sh
Created October 16, 2019 07:39
Bash Script to test if a variable is numeric
#!/bin/bash
function isdigit() {
local digit='^[+-]?[0-9]+$'
if [[ $1 =~ $digit ]]; then
return 0
fi
return 1
}
#!/bin/bash
redis-cli -p 7000 cluster set-config-epoch 1
redis-cli -p 7001 cluster set-config-epoch 1
redis-cli -p 7000 cluster reset
redis-cli -p 7001 cluster reset
redis-cli -p 7000 cluster addslots $(seq -s " " 0 16383)
@regeda
regeda / rope.c
Created February 21, 2017 21:16
Rope data structure built on splay tree
#include <stdio.h>
#include <stdlib.h>
#include <strings.h>
#define MAX_LEN 300001
typedef struct _rope {
int offset, len, size;
char *s;
struct _rope *left, *right, *parent;
@regeda
regeda / underscore.go
Last active December 12, 2018 10:23
Convert CamelCase to underscore in golang with UTF-8 support.
package main
import (
"testing"
"unicode"
"unicode/utf8"
"github.com/stretchr/testify/assert"
)