Skip to content

Instantly share code, notes, and snippets.

View matugm's full-sized avatar

Jesus Castello matugm

View GitHub Profile
<pre>
<?php
// Creating an array
$chars = array();
array_push($chars,'a','b','c');
@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;
@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 / 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",
@matugm
matugm / topic.md
Last active September 11, 2017 16:17