Skip to content

Instantly share code, notes, and snippets.

View nisevi's full-sized avatar
🧑‍🚀
Working from anywhere

Nicolas Sebastian Vidal nisevi

🧑‍🚀
Working from anywhere
View GitHub Profile
@nisevi
nisevi / prime.rb
Created April 24, 2018 17:12
Naive approach for calculating the prime number up to a given N.
class Prime
class << self
def prime?(number)
return false if number < 2
(2...number).each do |i|
return false if (number % i).zero?
end
true
end
@nisevi
nisevi / matrix.rb
Created April 24, 2018 17:17
First approach for getting a multiplication matrix of prime numbers.
class Matrix
attr_accessor :rows_header, :columns_header, :table
def initialize(args)
rows = header(args[:rows])
columns = header(args[:columns])
@table = load_table(rows, columns)
@rows_header = rows
@columns_header = columns
end
@nisevi
nisevi / prime.rb
Created April 27, 2018 09:49
Iterate only up through the square root of N.
class Prime
class << self
def prime?(number)
return false if number < 2
sqrt = Math.sqrt(number).to_i
(2..sqrt).each do |i|
return false if (number % i).zero?
end
true
end
@nisevi
nisevi / matrix.rb
Created April 27, 2018 10:16
The Sieve of Eratosthenes.
class Matrix
attr_accessor :rows_header, :columns_header, :table
def initialize(args)
rows = header(args[:rows])
columns = header(args[:columns])
@table = load_table(rows, columns)
@rows_header = rows
@columns_header = columns
end
@nisevi
nisevi / sieve_of_eratosthenes.rb
Created April 27, 2018 10:31
Methods for implementing the Sieve of Eratosthenes.
def header(max)
flags = [true] * (max + 1)
flags[0] = flags[1] = false
prime = 2
while prime <= Math.sqrt(max)
cross_off(flags, prime)
prime = next_prime(flags, prime)
end
process_flags(flags)
end
@nisevi
nisevi / process_flags.rb
Created April 27, 2018 10:35
Processing flags to get the prime numbers.
def process_flags(flags)
primes = []
flags.each_with_index do |value, index|
primes << index if value
end
primes
end
@nisevi
nisevi / ways_to_use_vcr.rb
Created May 30, 2018 20:42 — forked from myronmarston/ways_to_use_vcr.rb
Ways to use VCR for a request made by a let block
# 1) Use VCR.use_cassette in your let block. This will use
# the cassette just for requests made by creating bar, not
# for anything else in your test.
let(:foo) { VCR.use_cassette("foo") { create(:bar) } }
it "uses foo" do
foo
end
# 2) Wrap the it block that uses #foo in VCR.use_cassette.
@nisevi
nisevi / postgresql_configuration_on_ubuntu_for_rails.md
Created June 14, 2018 09:59 — forked from p1nox/postgresql_configuration_on_ubuntu_for_rails.md
PostgreSQL configuration without password on Ubuntu for Rails

Abstract

You could have postgre installed on localhost with password (or without user or password seted after instalation) but if we are developing we really don't need password, so configuring postgre server without password for all your rails project is usefull.

Install Postgre packages

  • postgresql
  • postgresql-client
  • libpq-dev
@nisevi
nisevi / index.html
Last active April 1, 2019 18:55
PAW_TP1_Maquetado_Punto_7
<table>
<tbody>
<tr>
<td class="fecha-de-entrega" rowspan="2">Fecha Entrega</td>
<td class="tp-border-solid">TP1</td>
<td class="tp-border-top-bottom-right">TP2</td>
<td class="tp-border-top-bottom-right">TP3</td>
<td class="tp-border-top-bottom-right">TP4</td>
<td class="tp-border-top-bottom-right">TP5</td>
<td class="tp-border-top-bottom-right">TP6</td>
@nisevi
nisevi / index.html
Last active April 2, 2019 03:24
PAW_TP1_Maquetado_Punto_6
<section class="section-resume">
<div class="main-container">
<!--PRESENTATION-->
<table class="presentation">
<tbody>
<tr><td class="header name width-525">Nicolas Sebastian Vidal</td></tr>
<tr><td class="header profession">Software Engineer</td></tr>
</tbody>
</table>
<!--WORK EXPERIENCE-->