Skip to content

Instantly share code, notes, and snippets.

James Edwards jamespedwards42

Block or report user

Report or block jamespedwards42

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View gist:c28ba78d11113fee7458434f389d16e2
Verifying my Blockstack ID is secured with the address 16nkM86wpv7W3BKgTA5qfQQtGEdZECNVgr https://explorer.blockstack.org/address/16nkM86wpv7W3BKgTA5qfQQtGEdZECNVgr
@jamespedwards42
jamespedwards42 / 0x8616e6270e14ff16dbbf1ea0a46ea3dc0d84ce1d
Created Jul 28, 2017
0x8616e6270e14ff16dbbf1ea0a46ea3dc0d84ce1d
View 0x8616e6270e14ff16dbbf1ea0a46ea3dc0d84ce1d
0x8616e6270e14ff16dbbf1ea0a46ea3dc0d84ce1d
@jamespedwards42
jamespedwards42 / rmServices.sh
Created Dec 19, 2016
Remove Docker Services
View rmServices.sh
#!/bin/bash
#./rmServices.sh redis-cluster-m-
readonly FILTER=${1:-"redis-cluster-m-"}
docker service ls | grep "$FILTER" | awk '{print $1}' | xargs docker service rm
exit 0
@jamespedwards42
jamespedwards42 / forEach.sh
Created Dec 19, 2016
Convenience Script for Executing CommandsAcross all Redis Swarm Services.
View forEach.sh
#!/bin/bash
#./forEach.sh 7001 5 redis-cluster-m- CLUSTER INFO
readonly STARTING_PORT=$1
readonly NUM_MASTERS=$2
readonly NAME_PREFIX=$3
readonly REDIS_CMD=("${@:4}")
readonly LOCAL_CONTAINER_ID=$(docker ps -f name="$NAME_PREFIX" -q | head -n 1)
readonly LOCAL_PORT=$(docker inspect --format='{{index .Config.Labels "com.docker.swarm.service.name"}}' "$LOCAL_CONTAINER_ID" | sed 's|.*-||')
for ((port = STARTING_PORT, endPort = port + NUM_MASTERS; port < endPort; port++)) do
host=$([ "$LOCAL_PORT" == $port ] && echo "127.0.0.1" || echo "$NAME_PREFIX$port")
@jamespedwards42
jamespedwards42 / assignSlots.sh
Last active Oct 12, 2017
Evenly assign slots to a new Redis Cluster
View assignSlots.sh
#!/bin/bash
#./assignSlots.sh 7001 5 redis-cluster-m-
readonly STARTING_PORT=${1:-0}
readonly NUM_MASTERS=${2:-0}
readonly NAME_PREFIX=${3:-"redis-cluster-m-"}
readonly MAX_SLOT=$((16383))
readonly SLOT_RANGE=$(((MAX_SLOT + NUM_MASTERS - 1) / NUM_MASTERS))
readonly LOCAL_CONTAINER_ID=$(docker ps -f name="$NAME_PREFIX" -q | head -n 1)
readonly LOCAL_PORT=$(docker inspect --format='{{index .Config.Labels "com.docker.swarm.service.name"}}' "$LOCAL_CONTAINER_ID" | sed 's|.*-||')
for ((port = STARTING_PORT, endPort = STARTING_PORT + NUM_MASTERS, slot = 0; port < endPort; port++)) do
@jamespedwards42
jamespedwards42 / meetNodes.sh
Last active Dec 21, 2016
Automates the MEET process for Redis Swarm Services.
View meetNodes.sh
#!/bin/bash
#./meetNodes.sh 7001 5 redis-cluster-m-
readonly STARTING_PORT=${1:-0}
readonly NUM_MASTERS=${2:-0}
readonly NAME_PREFIX=${3:-"redis-cluster-m-"}
readonly LOCAL_CONTAINER_ID=$(docker ps -f name="$NAME_PREFIX" -q | head -n 1)
readonly LOCAL_PORT=$(docker inspect --format='{{index .Config.Labels "com.docker.swarm.service.name"}}' "$LOCAL_CONTAINER_ID" | sed 's|.*-||')
# From local service task, meet all other nodes
for ((port = STARTING_PORT, endPort = STARTING_PORT + NUM_MASTERS; port < endPort; port++)) do
if [ "$LOCAL_PORT" == $port ]; then
@jamespedwards42
jamespedwards42 / createMasters.sh
Last active Dec 19, 2016
Create Redis Masters as Swarm Services
View createMasters.sh
#!/bin/bash
#./createMasters.sh 7001 5 redis-cluster-m- comodal/alpine-redis
readonly STARTING_PORT=${1:-0}
readonly NUM_MASTERS=${2:-0}
readonly NAME_PREFIX=${3:-"redis-cluster-m-"}
readonly IMAGE=${4:-"comodal/alpine-redis"}
for ((port = STARTING_PORT, endPort = port + NUM_MASTERS; port < endPort; port++)) do
name="$NAME_PREFIX$port"
docker service create\
--name "$name"\
View HttpServletRequestUtil.java
import javax.servlet.http.HttpServletRequest;
public class RequestUtil {
public static String getRequestIp(final HttpServletRequest request) {
String ip = request.getHeader("X-Forwarded-For");
if (ip == null) {
return request.getRemoteAddr();
}
ip = ip.trim();
@jamespedwards42
jamespedwards42 / AtomicLogCounters.java
Last active Apr 12, 2017
Compact Atomic Log Counters
View AtomicLogCounters.java
package systems.comodal.collision.cache;
import java.lang.invoke.MethodHandles;
import java.lang.invoke.VarHandle;
import java.util.concurrent.ThreadLocalRandom;
/**
* Provides atomic operations for 8-bit logarithmic counters backed by a byte array.
*
* @author James P. Edwards
View Hex.java
import java.util.PrimitiveIterator;
import static java.lang.Character.digit;
public final class Hex {
private Hex() {}
private static final char[] HEX_CHARS = new char[]{'0', '1', '2', '3', '4', '5', '6', '7', '8',
'9', 'a', 'b', 'c', 'd', 'e', 'f'};
You can’t perform that action at this time.