Skip to content

Instantly share code, notes, and snippets.

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

Joaquin Rivera Padron joahking

🏠
Working from home
View GitHub Profile
@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
@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 / 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 / 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 / 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 / phone_number.rb
Last active November 1, 2016 22:11
example of usage of concerns
# app/models/concerns/phone_number.rb
# concern to validate spanish phone numbers and provide some custom formatters
module PhoneNumber
extend ActiveSupport::Concern
PHONE_REGEXP = /\+\d{2}\s\d{3}\s\d{3}\s\d{3}/.freeze # e.g. +34 900 123 123
included do
validates :phone_number, presence: true, format: { with: PHONE_REGEXP, message: "invalid phone number" }
end
@joahking
joahking / confirm_dialog_steps.rb
Created March 2, 2011 15:03
bypass confirm dialog
Then /^(.+) and I confirm dialog box$/ do |step|
bypass_confirm_dialog
Then step
end
@joahking
joahking / show_revision.rb
Created January 18, 2011 15:02
cap deploy:show_revision
namespace :deploy do
desc "Shows deployed revision."
task :cat_revision do
run "cat #{current_path}/REVISION"
end
desc "Shows deployed revision using git."
task :show_revision do
run "cd #{current_path}; git log -n 1"
end

(a gist based on the old toolmantim article on setting up remote repos)

To collaborate in a distributed development process you’ll need to push code to remotely accessible repositories.

This is somewhat of a follow-up to the previous article setting up a new rails app with git.

For the impatient

Set up the new bare repo on the server:

// this allows culerity to wait until all ajax requests have finished
jQuery(function($) {
var original_ajax = $.ajax;
var count_down = function(callback) {
return function() {
try {
if(callback) {
callback.apply(this, arguments);
};
} catch(e) {