Skip to content

Instantly share code, notes, and snippets.

@ChildrenofkoRn
ChildrenofkoRn / generator_nonlinear_sequence.md
Created September 19, 2021 11:46
nonlinear sequence generator between numbers on Ruby
def get_sequence_nonlinear(count, start = 0, stop = 1, curvature: 1)
  step = 1 / (count - 1).to_f
  linear_steps = 0.step(by: step, to: 1)
  sequence = if curvature.positive?
               linear_steps.map { |num| 1 - Math.exp(num * -curvature.abs) }
             else
               linear_steps.map { |num| Math.exp(num * curvature.abs) - 1 }
             end
 max = sequence.max
@ChildrenofkoRn
ChildrenofkoRn / diff_arr_nums.md
Created September 19, 2021 17:13
slow Numo::NArray#diff (differences between array elements on Ruby)
require "benchmark/ips"
require 'numo/narray'

Benchmark.ips do |x|
  arr_nums = Array.new(10) { |i| rand(1..100.0) }
  
  x.report "each_cons + map" do
    arr_nums.each_cons(2).map{|a, b| b - a}
  end
@ChildrenofkoRn
ChildrenofkoRn / SQLZoo.sql
Created April 21, 2023 22:51
SQLZoo.net solutions 2023.04.22
-- Select SQL Engine: MySQL
--
--
-- ==================================================================
-- SELECT basics
-- ==================================================================
-- 1. Modify it to show the population of Germany
SELECT population
FROM world
WHERE name = 'Germany'