Skip to content

Instantly share code, notes, and snippets.

View xpepper's full-sized avatar
💭
😏

Pietro Di Bello xpepper

💭
😏
View GitHub Profile
@xpepper
xpepper / set_cookie_domain.md
Last active March 26, 2019 00:50
Rails - Dynamic cookie domains using Rack
@xpepper
xpepper / set_cookie_domain_from_server_name.rb
Created June 17, 2013 21:56
A valid solution when you have to set the domain of the Rails session cookie based on the server name. We use it on our e-commerce platform which supports multiple stores (and thus multiple domain names) on a single Rails app.
@xpepper
xpepper / data_source.rb
Created June 17, 2013 22:00
Inspired by Michael Feathers' post "Avoid Null Checks by Replacing Finders with Tellers" (http://michaelfeathers.typepad.com/michael_feathers_blog/2013/06/avoid-null-checks-by-replacing-finders-with-tellers.html)
Person = Struct.new(:id, :name, :phone_number)
DataSource = Struct.new(:people) do
def find_by_id(id)
people.detect { |p| p.id == id }
end
def person(id, &block)
p = find_by_id(id)
block.call(p) if p && block
@xpepper
xpepper / download_rubytapas.rb
Last active January 1, 2019 01:37
This script will download all the published rubytapas. Each episode, with all the attachments, will be downloaded in a folder named after the episode number. For example, in the folder "64" will be downloaded: 064-yield-or-enumerate.html, 064-yield-or-enumerate.mp4, 064-yield-or-enumerate.rb You need to set your credentials (username and passwor…
# username = "my_username"
# pwd = "my_password"
# target_path = "my_target_path"
# saving auth cookie
system %Q{wget --save-cookies /tmp/cookie.txt --keep-session-cookies --post-data "username=#{username}&password=#{pwd}" -O - \
https://rubytapas.dpdcart.com/subscriber/login?__dpd_cart=d08391e6-5fe2-4400-8b27-2dc17b413027}
(25..600).each do |i|
require 'minitest/autorun'
class StringCalculator
def self.add(string)
if string.empty?
0
else
match_data = string.match(/^\/\/(.+)\n/)
if match_data.nil?
separator = /(,|\n)/
// casperjs version 1.1.0
casper.test.begin('Edicola CDS', 2, function suite(test) {
casper.start('http://edicola.corrieredellosport.it', function() {
console.log('location is ' + this.getCurrentUrl());
test.assertTitle("Login al portale - Corriere dello Sport.it");
this.fill('form#theFormLogin', {
USERNAME: "[email protected]",
#! /bin/bash
start=$SECONDS
end=$((SECONDS+5))
while [ $SECONDS -lt $end ]; do
casperjs test browse_cms.js &
# ./bin/phantomjs examples/loadspeed.coffee http://cmsite-uat.herokuapp.com/sites/1 &
# ./bin/phantomjs examples/loadspeed.coffee http://cmsite-uat.herokuapp.com/sites/2 &
# ./bin/phantomjs examples/loadspeed.coffee http://cmsite-uat.herokuapp.com/sites/5 &
sleep 0.5
var casper = require('casper').create({
pageSettings: {
userAgent: 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:22.0) Gecko/20100101 Firefox/22.0'
}
});
casper.test.begin('CMSite', 1, function suite(test) {
casper.start('http://cmsite-uat.herokuapp.com/sites/5', function() {
this.waitForUrl(/cmsite-uat\.herokuapp\.com\/sites\/5\/site_rules/,
@xpepper
xpepper / purchase.txt
Last active December 25, 2015 01:59
Purchase flow for couponing. Per generare il sequence, andare su http://www.websequencediagrams.com e copiare il contenuto del testo.
title Coupon purchase process
ClientBrowser->+Vetrina: Purchase deal
note right of ClientBrowser: 10 Giorni alle Terme di Merano
Vetrina->DataPower: call PurchaseDeal API
note right of Vetrina:
dealId,
amount,
buyer email
# Formatting constants
export BOLD=`tput bold`
export UNDERLINE_ON=`tput smul`
export UNDERLINE_OFF=`tput rmul`
export TEXT_BLACK=`tput setaf 0`
export TEXT_RED=`tput setaf 1`
export TEXT_GREEN=`tput setaf 2`
export TEXT_YELLOW=`tput setaf 3`
export TEXT_BLUE=`tput setaf 4`
export TEXT_MAGENTA=`tput setaf 5`