Skip to content

Instantly share code, notes, and snippets.

View DonSchado's full-sized avatar
🐢
null

Marco DonSchado

🐢
null
View GitHub Profile
@DonSchado
DonSchado / render_or_redirect.rb
Created June 8, 2014 19:11
an experiment for open discussion, to eliminate duplicate controller logic
# eliminate all the duplication
def render_or_redirect(_action, _path, &block)
if block.call
redirect_to _path, success: I18n.t('common.success')
else
flash.now[:alert] = I18n.t('common.error')
render _action
end
end
@DonSchado
DonSchado / layer-css
Created November 23, 2014 07:00
Different depth of nodes will use different colour allowing you to see the size of each element on the page, their margin and their padding. Now you can easily identify inconsistencies.
* { background-color: rgba(255,0,0,.2); }
* * { background-color: rgba(0,255,0,.2); }
* * * { background-color: rgba(0,0,255,.2); }
* * * * { background-color: rgba(255,0,255,.2); }
* * * * * { background-color: rgba(0,255,255,.2); }
* * * * * * { background-color: rgba(255,255,0,.2); }
@DonSchado
DonSchado / fast_elasticsearch_importer.rb
Created November 24, 2014 10:50
the elasticsearch-rails client provides a relatively simple interface for the Elasticsearch Bulk API, which can speed up the indexing
# A FASTER IMPORTER
#
# the built-in import is not very efficient.
# It grabs every record, builds the ActiveRecord object
# and calls #as_indexed_json on it.
#
# for large sets of data that spans multiple relations,
# this can take a lot of time to complete.
#
# the elasticsearch-rails client provides a relatively simple interface for
@DonSchado
DonSchado / notification.js
Last active May 10, 2016 10:33 — forked from kangguru/notification.js
Mangopay Notifications
// ==UserScript==
// @name Mangopay Notifications
// @namespace http://tampermonkey.net/
// @version 0.1
// @description simulate mangopay notifications direct from the dashboard
// @author Lars Brillert
// @include /https://dashboard.sandbox.mangopay.com/Users/\d+/WalletTransactions/\d+/
// @grant none
// ==/UserScript==
/* jshint -W097 */
@DonSchado
DonSchado / config.ru
Created May 11, 2016 15:02
140 character rails application that returns http status 200
require'action_controller/railtie';run Class.new(Rails::Application){config.secret_key_base=?x;routes{root to:->_{[200,{},[]]}}}.initialize!
@DonSchado
DonSchado / filter.rb
Created November 21, 2017 11:06
Railslove Ruby programming exercise A1
# Railslove Ruby programming exercise A1
#
# To run the following exercise you need to have rspec installed.
# Then watch the output of `rspec filter.rb` and see 3 of 4 failing specs.
#
# The task is to filter a given collection (L#31) for entries that contain unique pairs.
# While filtering return the same structure and keep the ranking.
#
# Write code in the body of the filter method to make the tests pass.
#
@DonSchado
DonSchado / subsets.rb
Created November 24, 2017 15:31
Railslove Ruby programming exercise A2
# Railslove Ruby programming exercise A2
#
# To run the following exercise you need to have rspec installed.
# Then inspect the failing specs by running `rspec subset.rb`
#
# The task is to get all possible subsets of a group of Railslovers (without duplicates).
# So return a collection containing a group of each Railslover alone,
# then a group of pairs, then groups of 3, etc...
# The empty group is not considered a valid Railslove group. :)
#
@DonSchado
DonSchado / mission.rb
Created December 20, 2017 14:27
Railslove Ruby programming exercise A3
# Railslove Ruby programming exercise A3
#
# To run the following exercise you need to have rspec installed.
# Then inspect the failing specs by running `rspec mission.rb`
#
# How well did the avengers manage their time on their missions?
# Your task is to group all time entries by mission and then sum the minutes in total per avenger.
# After grouping the entries the expected response looks something like:
#
# {
@DonSchado
DonSchado / tty.rb
Last active April 20, 2018 06:19
Fancy Ruby
c=[' ',?█].cycle;w="173322172322\n2322232223221322\n23222322262322\n263322232225\n23123322232233\n23222322232233\n2322353643".chars.reduce([]){|r,n|n==$/?r<<n:r<<c.next*n.to_i;r}.join.split($/).map{|c|c.chars.map{|c|c*2}.join<<$/}.map{|r|r*2}.join;loop{$><<"\e[2J\e[1;1H"<<w.chars.map{|t|"\e[38;5;#{rand(230)}m#{t}"}*'';sleep 1}
@DonSchado
DonSchado / translations.rb
Last active October 15, 2019 10:29
Railslove Ruby programming exercise A4
# Railslove Ruby programming exercise A4
#
# To run the following exercise you need to have rspec installed.
# Then inspect the failing specs by running `rspec translations.rb`
#
# This excercise is special, because it's the first one where you're allowed to require active_support. ;-)
#
# (!) The task is to navigate and write into a nested hash via a path represented as `.` separated keys.
#
# (?) Maybe start with the underling algorithm to expand a collection to a "directed graph"