Skip to content

Instantly share code, notes, and snippets.

View descovi's full-sized avatar
🐈
Programming with cat

Alessandro Descovi descovi

🐈
Programming with cat
View GitHub Profile
@descovi
descovi / validate_url.rb
Created February 20, 2013 07:54
Validate a url with http or without / Validare una url con http sia senza http
# RegEx: is from http://stackoverflow.com/a/13311941/632478
# Rubular: http://rubular.com/r/cdkLxAkTbk
validates :url, format: { with: /^(http|https):\/\/|[a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,6}(:[0-9]{1,5})?(\/.*)?$/ix }
# Configs
config defaultToCurrentScreen true
config nudgePercentOf screenSize
config resizePercentOf screenSize
config secondsBetweenRepeat 0.1
config checkDefaultsOnLoad true
config focusCheckWidthMax 3000
config windowHintsShowIcons true
config windowHintsIgnoreHiddenWindows false
#config windowHintsDuration 5
@descovi
descovi / gist:7624800
Created November 24, 2013 08:24
error from unicorn
E, [2013-11-24T08:23:48.282063 #20438] ERROR -- : reaped #<Process::Status: pid 29427 exit 1> worker=1
I, [2013-11-24T08:23:48.282426 #20438] INFO -- : worker=1 spawning...
I, [2013-11-24T08:23:48.283720 #29440] INFO -- : worker=1 spawned pid=29440
I, [2013-11-24T08:23:48.301879 #29440] INFO -- : Refreshing Gem list
E, [2013-11-24T08:23:48.343457 #29430] ERROR -- : couldn't find HOME environment -- expanding `~' (ArgumentError)
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/guard-1.8.3/lib/guard.rb:23:in `expand_path'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/guard-1.8.3/lib/guard.rb:23:in `<module:Guard>'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/guard-1.8.3/lib/guard.rb:8:in `<top (required)>'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `require'
/usr/local/rvm/rubies/ruby-1.9.3-p429/lib/ruby/gems/1.9.1/gems/bundler-1.3.5/lib/bundler/runtime.rb:72:in `block (2 levels) in require'
class ApplicationController < ActionController::Base
def after_sign_in_path_for(resource)
request.env['omniauth.origin'] || stored_location_for(resource) || root_path
end
end
@descovi
descovi / development.rb
Created December 16, 2017 13:35
Configurazione per integrazione con amazon s3 e paperclip.
secrets = Rails.application.secrets
config.paperclip_defaults = {
storage: :s3,
s3_credentials: {
bucket: secrets.amazon_bucket_name,
access_key_id: secrets.amazon_access_key_id,
secret_access_key: secrets.amazon_secret_access_key,
s3_region: "eu-central-1"
}
}
@descovi
descovi / paperclip.rb
Created December 16, 2017 14:35
Configurazione di Paperclip S3 per l'Europa (Francoforte).
# config/initializers/paperclip.rb
Paperclip::Attachment.default_options[:s3_host_name] = 's3.eu-central-1.amazonaws.com'
@descovi
descovi / application.js
Last active May 8, 2020 14:43
Selectize e Turbolinks
document.addEventListener("turbolinks:load", function() {
$('.selectize').selectize()
})
document.addEventListener('turbolinks:before-cache', function(){
$('.selectize').each(function(){
if (this.selectize != undefined) {
this.selectize.destroy()
}
})
@descovi
descovi / title_helper_test.rb
Created February 22, 2018 10:11
Esempio di uso del metodo stub all'interno di un test di un helper.
# test/helpers/title_helper_test.rb
require 'test_helper'
class TitleHelperTest < ActionView::TestCase
test "return title with controller name when title content is nil" do
stub :controller_name, 'businesses' do
result = set_title_tag title_content: nil, from_layout: 'Admin Area'
assert_equal 'Clienti - Admin Area - iPY', result
end
@descovi
descovi / panel_inline.vue
Created March 6, 2018 11:15
Utilizzo di vue con tag <select> + binding di un valore strutturato ({name: 'Ciccio', id: 1})
<select type="text"
class="form-control"
v-model="momento.project"
name="project_id">
<option v-for="project in projects"
v-bind:value="{name: project.name, id: project.id}">
{{ project.name }}
</option>
</select>
@descovi
descovi / cursor_for_bash.rb
Created May 10, 2018 07:15
Giacomo Counter
businesses = Business.select{ |business| check_data_presence_for(business)}
previous_count = BusinessArea::RegisteredOffice.count
count = businesses.count.to_s
count_digits = count.length
cursors = ['|', '/', '-', '\\', '|', '/', '-', '\\']
businesses.each.with_index(1) do |business, index|
cursor = cursors[index % 32 / 4]
formatted_index = index.to_s.rjust(count_digits, '0')
print "#{cursor} #{formatted_index}/#{count} (business #{business.id}) #{cursor}"
params = extract_params_from(business)