Skip to content

Instantly share code, notes, and snippets.

View trajano's full-sized avatar
🖖
https://t.me/s/tracer_needs_a_buff

Archimedes Trajano trajano

🖖
https://t.me/s/tracer_needs_a_buff
View GitHub Profile
@trajano
trajano / FileSchemeGlobalFilter.java
Last active February 11, 2019 15:33
Add file/classpath support in Spring Cloud Gateway
import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.cloud.gateway.route.Route;
import org.springframework.cloud.gateway.support.ServerWebExchangeUtils;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.core.io.buffer.DataBufferUtils;
import org.springframework.http.server.reactive.ServerHttpResponse;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
@trajano
trajano / proxy.yml
Created March 21, 2019 20:59
traefik compose file
version: "3.7"
services:
traefik:
image: traefik:v1.7.9-alpine
ports:
- target: 80
published: 80
protocol: tcp
mode: host
- target: 443
@trajano
trajano / .bashrc
Last active October 11, 2019 20:01
Bash RC
dsreload() {
IMAGE=$(docker service inspect -f "{{.Spec.TaskTemplate.ContainerSpec.Image}}" $1 | cut -f1 -d"@")
docker service update --force --image $IMAGE $1
}
cd() {
if [ $# -eq 0 ]
then
builtin pushd ${HOME} > /dev/null
else
builtin pushd "$1" >& /dev/null || builtin cd "$1"
@trajano
trajano / ansi.pl
Last active May 14, 2020 18:28
ANSI color dump in perl
for ($i = 0; $i < 30; $i++) {
for ($j = 0; $j < 10; $j++) {
$n = 10*$i + $j;
last if ($n > 255);
print sprintf("\033[%dm %3d\033[m", $n, $n);
}
print "\n";
last if ($n > 255);
}
@trajano
trajano / Dockerfile
Created July 16, 2020 19:19
Preloaded anonymized data
# This is only used for development. The production will use AWS RDS
FROM mysql:5.7.23 as prep
# Copy your anonymized files
COPY *.anon.sql /docker-entrypoint-initdb.d/
# zz.grant-all-to-sample-user.sql script that to change the permissions on the anonymized data in case it is not owned by the test user
# grant all on *.* TO 'sampleuser'@'%';
@trajano
trajano / bubble.sh
Created August 12, 2020 16:45
Bubble up changes for rebase
#!/bin/bash
# Usage: bubble topRef
if [ $( git status -s | wc -l ) -eq 0 ]
then
git rebase --skip
else
if [ "$( git status -s | grep -E '(UD|DU) ' | wc -l )" -gt 0 ]
then
git rm `git status -s | grep -E '(UD|DU) ' | c2`
fi
@trajano
trajano / bubble.sh
Created August 12, 2020 16:45
Bubble up changes for rebase
#!/bin/bash
# Usage: bubble topRef
if [ $( git status -s | wc -l ) -eq 0 ]
then
git rebase --skip
else
if [ "$( git status -s | grep -E '(UD|DU) ' | wc -l )" -gt 0 ]
then
git rm `git status -s | grep -E '(UD|DU) ' | c2`
fi
@trajano
trajano / foo.ts
Created March 22, 2021 02:14
HSL to RGB and WCAG contrast ratio computations in TypeScript
// https://www.w3.org/TR/WCAG20-TECHS/G17.html
/**
* RGB Values. Each number is a number between 0.0 to 1.0
*/
type Rgb = { r: number, g: number, b: number }
/**
* HSL Values.
* @property h hue 0 to 360
* @property s saturation 0.0 to 1.0
@trajano
trajano / aliases.sh
Last active May 16, 2021 09:48
git aliases
#!/bin/sh
git config --global alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
git config --global alias.pu '!git push --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'
git config --global alias.puf '!git push --force --set-upstream origin $(git rev-parse --abbrev-ref HEAD)'
git config --global alias.r '!git fp && (GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash origin/HEAD || GIT_SEQUENCE_EDITOR=true git rebase -i --autosquash origin/master)'
git config --global alias.fr '!git fp && git pull --rebase origin HEAD'
git config --global alias.fp 'fetch --prune'
git config --global alias.ac '!git add -A && git commit'
git config --global alias.amend 'commit --amend -a --reuse-message=HEAD'
git config --global alias.remaster 'rebase -i origin/HEAD'
@trajano
trajano / stack-redeploy.pl
Last active October 22, 2021 05:55
Redeploy stack images if they do not match
#!/usr/bin/perl
use warnings;
use strict;
use Fatal qw(open);
our $VERSION = '1.0.0';
my $stack_name = shift;
sub _process_stack_entry {
my ($task_id, $task_image) = @_;
open my $container_fn, q{-|},