Skip to content

Instantly share code, notes, and snippets.

View Likeyn's full-sized avatar

Pierre-François CLEMENT Likeyn

View GitHub Profile
@Likeyn
Likeyn / elb-nginx-websockets.md
Last active September 9, 2019 23:26
How-to websockets through ELB + Nginx reverse proxy

Websockets-through-ELB-to-Nginx-to-another-ELB recap

We need to setup an ELB with SSL termination in front of a Nginx reverse proxy to some already working ELB + project system. IOW: SSL-ELB -> Nginx reverse proxy -> ELB -> project. We'll assume the last ELB + project bit works properly.

Front ELB configuration

  • Configure the listeners to use TCP (80) instead of HTTP to allow the websockets (non-HTTP) to pass through. For HTTPS with SSL termination, simply use SSL (443) -> TCP (80)
@Likeyn
Likeyn / check_foreign_keys.sql
Last active February 13, 2020 11:01
Check foreign keys integrity
-- Check foreign keys integrity
-- @link http://stackoverflow.com/a/12085689/1752536
DELIMITER $$
DROP PROCEDURE IF EXISTS ANALYZE_INVALID_FOREIGN_KEYS$$
CREATE
PROCEDURE `ANALYZE_INVALID_FOREIGN_KEYS`(
checked_database_name VARCHAR(64),
@Likeyn
Likeyn / randchar.sh
Created August 27, 2014 00:48
Get a random char
#!/usr/bin/env bash
# Get a random char
echo $(cat /dev/urandom | tr -dc 'A-Z' | head -c 1)
@Likeyn
Likeyn / physical_size.sql
Last active August 29, 2015 14:04
Attempt to compute the physical size of databases / tables
SELECT
TABLE_SCHEMA AS 'Database',
TABLE_NAME AS 'Table',
ROUND(((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024), 2) 'Size in MB'
FROM information_schema.TABLES
WHERE
TABLE_SCHEMA = '<database_name>'
AND TABLE_NAME = '<table_name>'
ORDER BY (DATA_LENGTH + INDEX_LENGTH) DESC;
@Likeyn
Likeyn / process-roulette.sh
Last active December 16, 2015 16:59
Russian Process Roulette: kill a random process
#!/usr/bin/env bash
# Kills one process randomly (including init)
p=$(ps -Aopid|sort -R|head -1)&&ps -p$p&&kill -9 $p
@Likeyn
Likeyn / git-stats.sh
Last active December 21, 2023 15:31
Shows small fun statistics from a git repository
#!/bin/bash
# Shows small fun statistics from a git repository
# Init
WEB='web/';
DB='config/doctrine/schema.yml data/sql/dbdeploy/';
COMMITS=$(git --no-pager shortlog -ns | head -3);
FIXS=$(git --no-pager shortlog -nsi --grep=fix | head -3);
DATABASE=$(git --no-pager shortlog -ns -- $DB | head -1 | cut -f 2);
@Likeyn
Likeyn / Levenshtein-function.sql
Created January 8, 2013 11:39
Levenshtein function for (My)SQL
CREATE FUNCTION LEVENSHTEIN (s1 VARCHAR(255), s2 VARCHAR(255)) RETURNS INT DETERMINISTIC
BEGIN
DECLARE s1_len, s2_len, i, j, c, c_temp, cost INT;
DECLARE s1_char CHAR;
DECLARE cv0, cv1 VARBINARY(256);
SET s1_len = CHAR_LENGTH(s1), s2_len = CHAR_LENGTH(s2), cv1 = 0x00, j = 1, i = 1, c = 0;
IF s1 = s2 THEN
RETURN 0;
ELSEIF s1_len = 0 THEN
RETURN s2_len;