Skip to content

Instantly share code, notes, and snippets.

View igorescobar's full-sized avatar
🐕

Igor Escobar igorescobar

🐕
View GitHub Profile
@igorescobar
igorescobar / rails_db_migrate.sh
Created February 16, 2016 20:21
The correct way to run rails db migration on AWS Beanstalk (Docker Container Environment)
#!/bin/bash
# .ebextensions/scripts/db_migrate.sh
. /opt/elasticbeanstalk/hooks/common.sh
EB_SUPPORT_FILES=$(/opt/elasticbeanstalk/bin/get-config container -k support_files_dir)
EB_CONFIG_DOCKER_ENV_ARGS=()
while read -r ENV_VAR; do
EB_CONFIG_DOCKER_ENV_ARGS+=(--env "$ENV_VAR")
$(".data").mask("AB/CD/0000", {
translation:{
A: {pattern: /[0-3]/},
B: {pattern: /[0-9]/},
C: {pattern: /[0-1]/},
D: {pattern: /[0-9]/},
},
onKeyPress: function(a, b, c, d) {
if (!a) return;
var m = a.match(/(\d{2})/g);
@igorescobar
igorescobar / imageboss-url.js
Last active May 16, 2020 16:36
Generating ImageBoss URLs with JavaScript
function mountImageBossUrl(src, { source, operation, cover_mode, width, height, options }) {
var serviceUrl = 'https://img.imageboss.me';
var template = '/:source/:operation/:options/';
if (operation === 'cover') {
template = '/:source/:operation::cover_mode/:widthx:height/:options/';
} else if (operation === 'width') {
template = '/:source/:operation/:width/:options/';
} else if (operation === 'height') {
template = '/:source/:operation/:height/:options/';
@igorescobar
igorescobar / getJpegQuality.js
Created May 15, 2020 18:35 — forked from FranckFreiburger/getJpegQuality.js
pure JavaScript jpeg quality value recover
// javascript jpeg decoder: https://github.com/eugeneware/jpeg-js/blob/79c4c7ea876d2e7b46981a563fcc4ae8f9e19849/lib/decoder.js
// Determine the JPEG compression quality from the quantization tables: https://github.com/ImageMagick/ImageMagick/blob/59f28acff016f6ae5e8b7e6300bcdf97e94affc9/coders/jpeg.c#L879
// JPEG File Layout and Format: http://vip.sugovica.hu/Sardi/kepnezo/JPEG%20File%20Layout%20and%20Format.htm
// jpeg constants: https://github.com/LuaDist/libjpeg/blob/6c0fcb8ddee365e7abc4d332662b06900612e923/jpeglib.h#L45
function getQuantizationTables(data) {
var quantizationTables = []
var dctZigZag = new Int32Array([
@igorescobar
igorescobar / .gitconfig
Last active April 21, 2020 07:59
A simple way to make pair programming possible with git and doesn't loose track of who's pair programming with you.
[alias]
pair = !git config user.name \"Igor & $1\"
unpair = config --unset-all user.name
@igorescobar
igorescobar / .bashrc_ps1.sh
Last active April 21, 2020 07:59
My Personal PS1 customization to work with git repositories.
# This bash script will update your PS1 configuration to inform you about:
# - current hour
# - current logged user
# - machine name
# - current path
# - status of current branch:
# - untracked files
# - uncommited changes
# - when nothing is changed on current branch
# - inform you when the current user.name and user.email is different of the global settings
@igorescobar
igorescobar / git-spush.bash
Last active April 10, 2019 14:19
Git alias to run your maven tests before push your changes to remote
git config alias.spush='!sh -c "mvn clean test && git push \$1 \$2 \$3"'
@igorescobar
igorescobar / docker-tips.sh
Last active May 3, 2018 10:15
Docker useful commands
# Clean unused images
docker image prune
# Clean up dangling volumes
docker volume rm $(docker volume ls -qf dangling=true)
# Stop all containers
docker stop $(docker ps -a -q)
@igorescobar
igorescobar / 01_sync_postgres_sequences.sql
Last active January 10, 2018 12:04
Syncing Postgres Sequences for All Tables
-- https://wiki.postgresql.org/wiki/Fixing_Sequences
SELECT 'SELECT SETVAL(' ||
quote_literal(quote_ident(PGT.schemaname) || '.' || quote_ident(S.relname)) ||
', COALESCE(MAX(' ||quote_ident(C.attname)|| '), 1) ) FROM ' ||
quote_ident(PGT.schemaname)|| '.'||quote_ident(T.relname)|| ';'
FROM pg_class AS S,
pg_depend AS D,
pg_class AS T,
pg_attribute AS C,
pg_tables AS PGT
@igorescobar
igorescobar / delete_git_old_tags.rb
Created December 12, 2017 12:03
A utility for deleting old git tags
# CUT_OFF_DATE needs to be of YYYY-MM-DD format
CUT_OFF_DATE = "2016-06-30"
def get_old_tags(cut_off_date)
`git log --tags --simplify-by-decoration --pretty="format:%ai %d"`
.split("\n")
.each_with_object([]) do |line, old_tags|
if line.include?("tag: ")
date = line[0..9]
tags = line[28..-2].gsub(",", "").concat(" ").scan(/tag: (.*?) /).flatten