Skip to content

Instantly share code, notes, and snippets.

class Date
def step_by_month(to_date, step=1)
date = self
op = %w(- <= >=)[step <=> 0]
while date.__send__(op, to_date)
yield(date)
date >>= step
end
end
end
@bogdanRada
bogdanRada / multi_provider_saml_handler.rb
Created April 19, 2019 12:27 — forked from jturkel/multi_provider_saml_handler.rb
How to configurate omniauth-saml to work with multiple identity providers based on a dynamic URL path segment. A gem based on this idea has been extracted to https://github.com/salsify/omniauth-multi-provider-saml.
require 'omniauth'
require 'omniauth-saml'
class MultiProviderSamlHandler
UUID_REGEX = /[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}/
attr_reader :path_prefix, :provider_name
def initialize(path_prefix: OmniAuth.config.path_prefix, provider_name: 'saml')
@path_prefix = path_prefix
@bogdanRada
bogdanRada / factory_girl_strategy_find_or_create.rb
Created March 15, 2019 08:33 — forked from hiasinho/factory_girl_strategy_find_or_create.rb
FactoryGirl strategy for adding find & find_or_create
## http://stackoverflow.com/questions/7145256
module FactoryGirl
module Strategy
class Find
def association(runner)
runner.run
end
def result(evaluation)
build_class(evaluation).where(get_overrides(evaluation)).first
@bogdanRada
bogdanRada / gist:77a7eda45e41ccafa5be48199d662a36
Created November 22, 2018 05:49
Understanding encoding through examples in Ruby
# encoding: UTF-8
utf8_resume = "Résumé"
latin1_resume = utf8_resume.encode("ISO-8859-1")
latin9_resume = utf8_resume.encode("ISO-8859-15")
lower_spanish = "\u00E1 \u00E9 \u00ED \u00F3 \u00FA \u00F1".encode("UTF-8")
puts lower_spanish
upper_spanish = "\u00C1 \u00C9 \u00CD \u00D3 \u00DA \u00D1".encode("UTF-8")
puts upper_spanish
@bogdanRada
bogdanRada / StringUtil.txt
Created November 19, 2018 11:14 — forked from ferstl/StringUtil.txt
A hacky shell script that counts all libraries on Maven Central containing a specific Java class
activemq:activemq
ant:ant-optional
ant:ant-trax
ant:optional
aptconvert:aptconvert
biz.neustar:browsermob-proxy
bsh:bsh
cactus:cactus
cactus:cactus.core.framework.uberjar.javaEE.12
cactus:cactus.core.framework.uberjar.javaEE.13
@bogdanRada
bogdanRada / env.rb
Created November 12, 2018 10:35 — forked from whitneyimura/env.rb
Web env.rb file
require 'selenium-webdriver'
require 'capybara'
require 'rspec'
require 'launchy'
require 'active_support'
require 'active_support/inflector'
require 'headless'
require 'ruby-debug'
require 'webdriver-user-agent'
@bogdanRada
bogdanRada / acceptance_helper.rb
Created November 12, 2018 07:42 — forked from bibendi/acceptance_helper.rb
Example Capybara tests
require 'rails_helper'
require 'capybara/rspec'
require 'selenium-webdriver'
require 'site_prism'
Capybara.server = :puma, { Silent: true }
Capybara.server_host = `hostname`.strip.downcase
Capybara.server_port = 3002
Capybara.default_max_wait_time = 5
dataset = [18.562874251497007, 20.958083832335326, 18.562874251497007, 19.161676646706585, 22.75449101796407]
diff = 100 - dataset.map(&:floor).reduce(&:+)
rounded_percentages = dataset
.sort_by { |x| x.floor - x}
.map
.with_index { |e, index| index < diff ? e.floor + 1 : e.floor }
@bogdanRada
bogdanRada / Sort Algorithms
Created October 30, 2018 13:19 — forked from marcaosi/Sort Algorithms
This gist contains the implementation of sort algorithms in C
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void bubbleSort(int arr[], int count);
void quicksort(int arr[], int left, int right);
void insertionSort(int arr[], int count);
void selectionSort(int arr[], int count);
void shellSort(int arr[], int count);
void heapSort(int arr[], int count);
@bogdanRada
bogdanRada / README.md
Created October 30, 2018 13:19 — forked from nitaku/README.md
Graph comparison

A simple method for comparing small, similar graphs. Two linked views are presented, showing differences as "phantom" nodes and links. The views share the same layout, ensuring comparability.