Skip to content

Instantly share code, notes, and snippets.

View DonSchado's full-sized avatar
🐢
null

Marco DonSchado

🐢
null
View GitHub Profile
@DonSchado
DonSchado / burning_woods.rb
Last active October 27, 2021 06:34
Game of life variation
class WoodOfLife
include Enumerable
ROWS = 50
COLUMNS = 50
EXAMPLE = Array.new(ROWS * COLUMNS) { rand(2) }.join
attr_reader :cells, :rows, :columns
def initialize(options = {})
@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 / 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 / playground.rb
Last active November 6, 2019 09:09
ActiveRecord Playground File `irb -r ./playground.rb` (or `pry ...`)
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'sqlite3'
gem 'activerecord', "~> 6.0.0.rc2"
end
require 'active_record'
@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"
@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 / 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 / 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 / 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 / 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 */