Skip to content

Instantly share code, notes, and snippets.

# If you come from bash you might have to change your $PATH.
# export PATH=$HOME/bin:/usr/local/bin:$PATH
# Path to your oh-my-zsh installation.
export ZSH="/Users/pere/.oh-my-zsh"
# Set name of the theme to load --- if set to "random", it will
# load a random theme each time oh-my-zsh is loaded, in which case,
# to know which specific one was loaded, run: echo $RANDOM_THEME
# See https://github.com/robbyrussell/oh-my-zsh/wiki/Themes
@pjmartorell
pjmartorell / file_history.sh
Created March 21, 2023 19:39
Find when a file was deleted in Git by showing all history of modifications of a given file
git log --full-history -- app/views/plugins/_list.html.erb
@pjmartorell
pjmartorell / calculate_base64_size.rb
Created August 26, 2020 11:40
Calculate the size of Base64.encode64 (strict or not) in Ruby
def calculate_base64_size(size, strict: false)
# see http://stackoverflow.com/questions/13378815/base64-length-calculation for more details about this calculation
code_size = (size * 4) / 3
# Adds padding (0, 1 or 2 '=') depending on the size
padding = size % 3 ? (3 - (size % 3)) : 0
# sum plus terminating null character
padded_size = code_size + padding + 1
# The RFC 2045 states that 'the encoded output stream must be represented in lines of no more than 76 characters
@pjmartorell
pjmartorell / Dockerfile
Created April 7, 2020 14:05
How to deploy SoapUI mock server on Heroku with Docker
# Dockerfile for building a soapui-runner
FROM openjdk:8
ENV SOAPUI_VERSION="5.5.0" \
SOAPUI="/opt/soapui" \
PROJECT_FILE="/root/your-project.xml" \
MOCKSERVICE_NAME="MockServiceName" \
MOCK_BIN="mockservicerunner.sh"
RUN wget https://s3.amazonaws.com/downloads.eviware/soapuios/$SOAPUI_VERSION/SoapUI-$SOAPUI_VERSION-linux-bin.tar.gz && \
@pjmartorell
pjmartorell / mask_phone_number.rb
Last active August 5, 2019 16:55
Mask phone with asterisks except last 3 characters
phone = '+36637950242'; phone[0..-4] = '*' * phone[0..-4].length; phone
# OR
phone = '+36637950242'; phone.gsub(/.(?=.{3})/,'*')
@pjmartorell
pjmartorell / vimeo_download_subtitles.md
Last active September 23, 2023 07:56
How to download subtitles/text tracks of a On Demand Vimeo video

Download subtitles/text tracks of an On-Demand Vimeo video

It works with on-demand videos that have the subtitles/captions included (CC symbol). You need to be registered in Vimeo in order to retrieve subtitles.

Steps

  1. Open Chrome Developer Tools
  2. Start playing the Vimeo video
  3. Look for any request named segment-XX.m4s (where XX is a number)
  4. Select the request and inspect the request payload, which is something in the form:
module Delivery
class PackageFittingChecker
def self.fit?(shipping_method_id, quantities_with_max_units_and_shipping_package_categories)
case shipping_method_id
when "correos", "d_post"
max_units_per_package = :max_units_per_correos_package
when "ups_envelope"
max_units_per_package = :max_units_per_ups_package
when "dhl", "ups_express_saver", "ups_standard"
return true
module Delivery
class QuantitiesWithMaxUnitsAndShippingPackageCategoriesMapper
def initialize(cart_products)
@cart_products = cart_products
end
def quantities_with_max_units_and_shipping_package_categories
@cart_products.map do |cart_product|
variant = cart_product.sample_pack_product.presence || cart_product.variant.presence
raise "Unsupported type! #{cart_product.inspect}" unless variant
@pjmartorell
pjmartorell / cuba_resources.md
Created June 28, 2017 09:53
Cuba framework resources and examples

Source code

Tutorials

@pjmartorell
pjmartorell / git-checkout.rake
Last active September 9, 2016 11:58 — forked from sunny/git-checkout.rake
Task to checkout a branch in rails and apply or rollback the migrations between the two.
# encoding: UTF-8
#
# $ rake checkout new_branch_name
#
# Via https://gist.github.com/jonlemmon/4076864
#
# 1. Roll back any migrations on your current branch which do not exist on the
# other branch
# 2. Discard any changes to the db/schema.rb file
# 3. Check out the other branch