Skip to content

Instantly share code, notes, and snippets.

Pere Joan Martorell pjmartorell

Block or report user

Report or block pjmartorell

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@pjmartorell
pjmartorell / mask_phone_number.rb
Last active Aug 5, 2019
Mask phone with asterisks except last 3 characters
View mask_phone_number.rb
phone = '+36637950242'; phone[0..-4] = '*' * phone[0..-4].length; phone
# OR
phone = '+36637950242'; phone.gsub(/.(?=.{3})/,'*')
@pjmartorell
pjmartorell / vimeo_download_subtitles.md
Last active Dec 5, 2019
How to download subtitles/text tracks of a On Demand Vimeo video
View vimeo_download_subtitles.md

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:
View package_fitting_checker.rb
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
View quantities_with_max_units_and_shipping_package_categories_mapper.rb
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 Jun 28, 2017
Cuba framework resources and examples
View cuba_resources.md

Source code

Tutorials

@pjmartorell
pjmartorell / git-checkout.rake
Last active Sep 9, 2016 — forked from sunny/git-checkout.rake
Task to checkout a branch in rails and apply or rollback the migrations between the two.
View git-checkout.rake
# 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
View Google Maps Simple Multiple Marker Example
<html>
<head>
<title>Google Maps Multiple Markers</title>
<script src="http://maps.google.com/maps/api/js?sensor=false" type="text/javascript"></script>
</head>
<body>
<div id="map" style="height: 400px; width: 500px;">
</div>
<script type="text/javascript">
@pjmartorell
pjmartorell / comm-s3.sh
Last active May 6, 2016
Find the symmetric difference between Amazon S3 object list and your local files list
View comm-s3.sh
#!/usr/bin/env bash
comm -13 <(aws s3 ls s3://my-bucket | awk '{print $NF}' | sort) <(ls my_local_folder/ | awk '{print $NF}' | sort)
@pjmartorell
pjmartorell / laravel_naming.php
Last active May 5, 2016
Laravel Naming Conventions
View laravel_naming.php
<?php
class MyClass {
const MY_CONSTANT = 0.0;
protected $myProperty;
protected $table = [
"my_table"
@pjmartorell
pjmartorell / MapSVG.js
Last active May 6, 2016
Function to fetch the region name from the region ID in mapSVG WordPress plugin Can be used for Global tooltips or popovers
View MapSVG.js
/* Function to fetch the region name from
the region ID in mapSVG WordPress plugin
Can be used for Global tooltips or popovers */
function (event, region) {
return '<b>' + region.id.replace(/_/g," "); + '</b>';
}
You can’t perform that action at this time.