Skip to content

Instantly share code, notes, and snippets.

Alessandro Rodi coorasse

Block or report user

Report or block coorasse

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
View accessible_by unexpected behaviour
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.2.0' # use correct rails version
@coorasse
coorasse / example.html
Created Jan 9, 2019
Input switch from password to text
View example.html
<input id="api-token" type="password" value="" readonly data-select />
<button data-token-reveal="api-token" data-alternate-text="Hide">Show</button>
@coorasse
coorasse / bitbucket-pipelines.yml
Created Sep 13, 2018
Example of Bitbucket Pipeline for Ruby 2.5.1 + Webpacker + System Tests + Deployment to Elastic Beanstalk
View bitbucket-pipelines.yml
image: circleci/ruby:2.5.1-node-browsers
pipelines:
default:
- step: &tests
name: Tests
caches:
- bundler
- node
services:
@coorasse
coorasse / copy.sh
Last active Aug 6, 2018
Restore glacier files from S3
View copy.sh
fileName="$1" # File containing only S3 object key
bucketName="$2"
profileName="$3"
count=0
while read key; do
aws s3api copy-object --bucket $bucketName --copy-source "$bucketName/$key" --key "$key" --query "CopyObjectResult.{LastModified}" --profile $profile
var=$((count+1))
echo "#$count ... $key"
done < $fileName
@coorasse
coorasse / with left joins
Created Jul 11, 2018
Performance cancancan
View with left joins
Warming up --------------------------------------
easy 860.000 i/100ms
cannot 621.000 i/100ms
simple filter 596.000 i/100ms
one join 260.000 i/100ms
two joins 207.000 i/100ms
three joins 163.000 i/100ms
Calculating -------------------------------------
easy 8.739k (± 4.8%) i/s - 43.860k in 5.031055s
cannot 6.233k (± 5.2%) i/s - 31.671k in 5.096447s
View compressor.rb
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'minitest'
@coorasse
coorasse / with_union
Created Jul 7, 2018
cancancan with union
View with_union
-- execution time: 74ms
SELECT DISTINCT proposals.*
FROM (SELECT "proposals".*
FROM "proposals"
WHERE "proposals"."private" = 'f'
UNION SELECT "proposals".*
FROM "proposals"
WHERE "proposals"."visible_outside" = 't'
UNION SELECT "proposals".*
@coorasse
coorasse / en.yml
Created Jun 27, 2018
yml inheritance example
View en.yml
de:
default: &default
one: 1
two: 2
mama:
<<: *default
papa:
<<: *papa
# phraseapp
View same table twice cancancan example
begin
require 'bundler/inline'
rescue LoadError => e
$stderr.puts 'Bundler version 1.10 or later is required. Please update your Bundler'
raise e
end
gemfile(true) do
source 'https://rubygems.org'
gem 'rails', '5.1.0' # use correct rails version
@coorasse
coorasse / old_files_killer.rb
Last active Sep 12, 2019 — forked from pelgrim/old_file_killer.rb
A Ruby on Rails script to delete files older than X days in a given directory.
View old_files_killer.rb
# A Ruby On Rails script to delete files older than X days in a given directory.
# Quickly written by @coorasse
class FilesCleaner
def perform(days = 1)
Dir.glob(Rails.root.join('path', 'to', 'folder', '*')).each do |filename|
File.delete(filename) if File.mtime(filename) < days.days.ago
end
end
end
You can’t perform that action at this time.