Skip to content

Instantly share code, notes, and snippets.

View joahking's full-sized avatar
🏠
Working from home

Joaquin joahking

🏠
Working from home
View GitHub Profile
@joahking
joahking / store_tracking.rb
Last active November 1, 2016 14:08
example of usage of a service in a controller
# app/services/store_tracking.rb
# service that tracks user visits to a store, and keeps counters in the models
class StoreTracking
def initialize(store, user, request)
@store = store
@user = user
@request = request
end
@joahking
joahking / flatten.rb
Created November 9, 2016 16:01
flatten arrays of integers without using Array.flatten
class Flatten
def initialize(array)
@array = array
end
def flatten(array = @array)
if array.is_a? Integer
[array]
else
array.inject([]) { |memo, elem| memo + flatten(elem) }
@joahking
joahking / compare-imgs.sh
Last active August 31, 2017 15:27
Bash script used in ifeelmaps.com to compare image sizes
#!/bin/bash
# Compare every file passed over stdin with it's converted one
# i.e. file.extension vs file_imagemagick_converted.extension and echo the bigger one of each pair
#
# Usage:
# ./compare-imgs.sh < converted_images > bigger_imgs
#
# Arguments:
# stdin - list of filenames
@joahking
joahking / convert-imgs.sh
Last active August 30, 2017 16:01
Script used in ifeelmaps.com to optimise images as suggested by PageSpeed Insights
#!/bin/bash
# Convert images received as list of filenames over stdin
#
# Uses imagemagick's convert script https://www.imagemagick.org/script/convert.php
# Follows suggestions on https://developers.google.com/speed/docs/insights/OptimizeImages
#
# Usage:
# find . -path './*original*' -type f | sed 's/\.\///' | ./convert-imgs.sh 615 > converted_images
#
@joahking
joahking / rename-imgs.sh
Created August 31, 2017 15:41
Script used in ifeelmaps.com to rename converted images to original ones
#!/bin/bash
# Rename files file_imagemagick_converted.extension to file.extension
#
# Usage:
# grep -v imagemagick_converted bigger_imgs | ./rename-imgs.sh
#
# Arguments:
# stdin - list of filenames