Skip to content

Instantly share code, notes, and snippets.

View matugm's full-sized avatar

Jesus Castello matugm

View GitHub Profile
@matugm
matugm / caesar.rb
Last active September 16, 2023 05:23
Caesar cipher using Ruby
ALPHABET_SIZE = 26
def caesar_cipher(string)
shiftyArray = []
charLine = string.chars.map(&:ord)
shift = 1
ALPHABET_SIZE.times do |shift|
shiftyArray << charLine.map do |c|
((c + shift) < 123 ? (c + shift) : (c + shift) - 26).chr
@matugm
matugm / array.c
Last active May 11, 2021 04:30
dynamic arrays in c
#include "array.h"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
struct ArrayData *initArray() {
struct ArrayData *newArray = malloc(sizeof(struct ArrayData));
newArray->pointer = calloc(1000, sizeof(int));
newArray->size = 1000;
require 'benchmark/ips'
str = { "foo" => 1 }
sym = { foo: 1 }
Benchmark.ips do |x|
x.report("string") { str["foo"] }
x.report("symbol") { sym[:foo] }
x.compare!
@matugm
matugm / array-random.rb
Last active November 17, 2018 15:34
Benchmarks
def a
t = Time.now
Array.new(10_000_000) { rand }
puts Time.now - t
end
10.times { a }
require 'benchmark'
N = 1_000_000
Benchmark.bm(10) { |x|
0.step(to: 16) { |size|
data = (1..size).zip(Array.new(size))
x.report(size) {
i = 0

Keybase proof

I hereby claim:

  • I am matugm on github.
  • I am jesus_castello (https://keybase.io/jesus_castello) on keybase.
  • I have a public key whose fingerprint is 5697 A6C4 0820 FCB6 E86E BD21 53CB 0DB1 23B1 3816

To claim this, I am signing this object:

@matugm
matugm / time-range.rb
Created January 12, 2018 13:53
Time Range
require 'time'
require 'pp'
objects = [Time.strptime("20", "%M"), Time.strptime("21", "%M"), Time.strptime("25", "%M"),Time.strptime("26", "%M")]
@range = Hash.new { |hash, key| hash[key] = [] }
def add_into_time_range(time)
base = time.min - (time.min % 5)
key = "#{time.hour}:#{base}"
@matugm
matugm / toc.md
Last active October 13, 2017 15:57
Table Of Contents

Ruby Deep Dive - Table Of Contents

  • Using Pry to Learn Ruby
    • The Power of Pry
    • Where did this method come from?
    • Debugging using Pry
  • Understanding Exceptions
    • What are Exceptions and Why They Happen
    • Understanding Stack Traces
  • Using Exceptions
@matugm
matugm / topic.md
Last active September 11, 2017 16:17
<pre>
<?php
// Creating an array
$chars = array();
array_push($chars,'a','b','c');