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
class ArticlesController < ApplicationController
def create
@article = Article.create article_params
if @article.save
redirect_to article_path(@article)
else
render :new
end
end
@descovi
descovi / wei.rb
Last active January 25, 2021 18:00
Ruby Wei to eth converter
# Example of usage:
# result = WeiConverter.new(1890000000000000000).call
# Result contains 1.89
class WeiConverter
UNITS = {
wei: 1,
kwei: 1000,
ada: 1000,
@descovi
descovi / gist:da964c7ea589618c84e78a432c42a61a
Last active April 23, 2019 15:06
nginx cache - errato (include anche .json) - appunto per giacomo configurazione nginx
location ~* \.(png|jpg|jpeg|js|css|svg) {
expires max;
gzip_static on;
add_header Cache-Control public;
}
@descovi
descovi / webpacker.yml
Created March 8, 2019 11:06
webpacker config for hot reload with docker
development:
<<: *default
host: webpacker
hmr: true
compile: true
# Reference: https://webpack.js.org/configuration/dev-server/
dev_server:
https: false
host: webpacker
@descovi
descovi / easy_translation.rb
Last active February 9, 2023 17:12
EasyTranslation - I18n - Alias - Rails - Rubynetti
# Module for easier translation (Easy Translation)
module EasyTranslation
extend ActiveSupport::Concern
included do
def self.t(symbol=nil)
case symbol
when nil
model_name.human
when :plural
@descovi
descovi / docker-compose.yml
Created August 6, 2018 08:08
Impostazione per usare docker compose con elastic search.
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:6.3.2
container_name: elasticsearch
volumes:
- esdata1:/usr/share/elasticsearch/data
ports:
- 9200:9200
volumes:
esdata1:
driver: local
@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)
@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 / 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 / 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()
}
})