Skip to content

Instantly share code, notes, and snippets.

View matugm's full-sized avatar

Jesus Castello matugm

View GitHub Profile
@matugm
matugm / dp-change.rb
Created June 8, 2015 18:02
Change problem solution
COINS = [1,3,6,10,15,20,30,50]
@cache = []
def min_change(amount)
return 0 if amount == 0
min = 9999999999
possible_coins = COINS.select { |n| n <= amount }
@matugm
matugm / max_subarray.rb
Created June 10, 2015 02:03
Max SubArray
#######################
# Version 1 - O(n^2)
#######################
def max_seq(chars, x = 0, y = 0)
return chars if chars.size < 2
combinations = {}
(0...chars.size).each do |x|
class ListNode
attr_accessor :val, :next
def initialize(val)
@val = val
@next = nil
end
end
@carry = false
@matugm
matugm / refactor.js
Created July 14, 2015 02:10
javascript refactor
// Old
$(function() {
var flashCallback;
flashCallback = function() {
return $(".alert").fadeOut();
};
$(".flash-message").bind('click', (function(_this) {
return function(ev) {
return $(".alert").fadeOut();
};
require 'faker'
20.times do
post = Post.create!(title: Faker::Lorem.word, body: Faker::Lorem.paragraph)
puts "Created #{post.title}"
end
#coding: utf-8
class HighLine
module BuiltinStyles
def self.included(base)
base.extend ClassMethods
end
STYLES = {
erase_line: "\e[K",
<pre>
<?php
// Creating an array
$chars = array();
array_push($chars,'a','b','c');
@matugm
matugm / topic.md
Last active September 11, 2017 16:17
@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 / 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}"