Skip to content

Instantly share code, notes, and snippets.

View igorescobar's full-sized avatar
🐕

Igor Escobar igorescobar

🐕
View GitHub Profile
@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 / 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 / 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
@igorescobar
igorescobar / clean-junk.sh
Last active November 21, 2017 14:49
Clean junk files from vendor/bundle directory
#!/usr/bin/env bash
find ./vendor/bundle \( -name '__tests__' -o \
-name "*.md" -o \
-name "*LICENSE*" -o \
-name "*.ts" -o \
-name "*.jst" -o \
-name "*.coffee" -o \
-name "*.rdoc" -o \
-name "example" -o \
-name "examples" -o \
@igorescobar
igorescobar / ssh_config.sh
Created March 3, 2017 14:22
Connect to a PRIVATE machine through a PUBLIC machine.
# put this in your ~/.ssh/config
Host public.host
HostName $ip
User $username
IdentityFile $identity_file_path
Host private.host
ProxyCommand ssh -q -W $private_ip:$private_local_port public.host
User $username
IdentityFile $identity_file_path
// e.g: @include truncate(.875em, 1.4, 10)
@mixin truncate($font-size, $line-height, $lines-to-show) {
display: block; // Fallback for non-webkit
display: -webkit-box;
max-width: 400px;
height: $font-size*$line-height*$lines-to-show; // Fallback for non-webkit
font-size: $font-size;
line-height: $line-height;
-webkit-line-clamp: $lines-to-show;
@igorescobar
igorescobar / github-expand-comments.js
Last active August 23, 2016 13:42
Expand Github Pull Request Comment Bookmark
// add this as a bookbark on your browser
javascript:Array.from(document.getElementsByClassName('outdated-diff-comment-container')).forEach(l => l.classList.add('open'));
@igorescobar
igorescobar / fix-house-search.md
Last active June 17, 2016 15:34
Feature Request: Search for a new house using its approximation of a POI like a subway, mall or something like that.

Feature Request: Search for a new house using its approximation of a POI like a subway, mall or something like that.

Here is how you can achieve it:

  1. When your user are adding a new house for sale/rent they also provide its address.
  2. With this address you are able to convert it to a latitute,longitude (x,y).
  3. With this x,y you are able to use a service like Google Places API and store on your database the proximity of a lot of useful POIs from the house itself.
  4. Now that you have all those nearby POIs stored and its distances from the provided address, you are able to provide a freaking awesome search for your users.
  5. Now you can for example search for a house or appartment, for rent, in Lisbon, which is 1-2km near of a subway or a train station.
  6. How? With postgres you can use extensions like cube or earthdistance. Or with a no-sql solution using Geospatial index (2d).
@igorescobar
igorescobar / docker-compose.yml
Last active May 27, 2016 10:07
Two neo4j containers on the same local network without sharing data.
# based on @spacecowboy at https://github.com/neo4j/docker-neo4j/issues/34
version: '2'
services:
neo4j:
image: neo4j
ports:
- "7474:7474"
networks:
- basic-lan