Skip to content

Instantly share code, notes, and snippets.

@silviorelli
silviorelli / commercelayer_cli_order_place.md
Last active October 22, 2021 14:04
Place an order via the Commerce Layer CLI

Place an order for a t-shirt via the Commerce Layer CLI

  1. Search for the desired t-shirt:
commercelayer resources:get skus -w name_i_cont_all=t-shirt,pink -w name_not_i_cont_all=women,white

Example ID of t-shirt selected: NzWOpOSyBx.

@silviorelli
silviorelli / paginate.rb
Created September 10, 2020 14:09 — forked from be9/paginate.rb
kaminari + JSON API pagination helper
def paginate(scope, default_per_page = 20)
collection = scope.page(params[:page]).per((params[:per_page] || default_per_page).to_i)
current, total, per_page = collection.current_page, collection.num_pages, collection.limit_value
return [{
pagination: {
current: current,
previous: (current > 1 ? (current - 1) : nil),
next: (current == total ? nil : (current + 1)),
@silviorelli
silviorelli / application_controller.rb
Created July 1, 2020 15:21 — forked from mwlang/application_controller.rb
Logging headers, params, and body to console -- useful for debugging what a mobile app is sending Rails API backend server.
class ApplicationController < ActionController::Base
protect_from_forgery with: :exception
around_action :global_request_logging
def global_request_logging
http_request_header_keys = request.headers.env.keys.select{|header_name| header_name.match("^HTTP.*|^X-User.*")}
http_request_headers = request.headers.env.select{|header_name, header_value| http_request_header_keys.index(header_name)}
puts '*' * 40
pp request.method
#!/bin/sh
if [ $# -ne 2 ]; then
echo "Usage: $(basename $0) <heroku-app-name> <local_database_name>"
exit -1
fi
if heroku pg:backups capture --app $1 ; then
if curl -o latest.dump `heroku pg:backups public-url --app $1` ; then
pg_restore --verbose --clean --no-acl --no-owner -h localhost -U $USER -d $2 latest.dump
@silviorelli
silviorelli / party.js
Created September 21, 2016 08:02
Epilessia portami via
function party_background_color() {
$("html, body").css("background-color", getRandomColor());
var all = document.getElementsByTagName("*");
for (var i = 0, max = all.length; i < max; i++) {
$(all[i]).css("color", getRandomColor());
$(all[i]).css("background-color", getRandomColor());
}
}
function getRandomColor() {
@silviorelli
silviorelli / ml-ruby.md
Created May 6, 2016 07:36 — forked from gbuesing/ml-ruby.md
Resources for Machine Learning in Ruby

Resources for Machine Learning in Ruby

Gems

@silviorelli
silviorelli / gist:ad8e1d80bdc0245eb7e7
Created February 3, 2016 09:34
Install Ruby 1.8.7 on Mac OSX 10.11 El Capitan with rbenv
brew install apple-gcc42 openssl libyaml libffi
xcode-select --install
export CC=/usr/local/bin/gcc-4.2
export CFLAGS='-g -O2'
export RUBY_CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl`
export CONFIGURE_OPTS=--with-openssl-dir=`brew --prefix openssl`
rbenv install 1.8.7-p375
@silviorelli
silviorelli / gist:e8f98261d3328e1dabae
Created August 19, 2014 15:16
CoffeeScript AND between two arrays
array_and = (ary1, ary2) ->
result = []
seen = {}
i = 0
length = ary1.length
while i < length
item = ary1[i]
unless seen[item]
j = 0
length2 = ary2.length
@silviorelli
silviorelli / rails4flor.txt
Created December 19, 2012 01:32
What's new in Ruby on Rails 4, a RoR 4 press review by Silvio Relli @ Florence On Ruby - Bibliography and related resources
What's new in Ruby on Rails 4
A RoR 4 press review
Silvio Relli @ Florence On Ruby
Bibliography and related resources
1) Rails queue
http://reefpoints.dockyard.com/ruby/2012/06/25/rails-4-sneak-peek-queueing.html
http://blog.remarkablelabs.com/2012/12/rails-queue-rails-4-countdown-to-2013
https://github.com/rails/rails/commit/adff4a706a5d7ad18ef05303461e1a0d848bd662
@silviorelli
silviorelli / gist:3910867
Created October 18, 2012 10:13
Run save callbacks when touch is called on a record - Rails 3
# Inside User Observer
def after_touch(user)
user.run_callbacks :save
end