Skip to content

Instantly share code, notes, and snippets.

View amiralles's full-sized avatar
🏠
Working from home

Ale Miralles amiralles

🏠
Working from home
View GitHub Profile
@amiralles
amiralles / set.rb
Last active December 8, 2019 19:22
Set implementation in Ruby
require_relative "./linked_list.rb"
class Set
# Set's constructor.
def initialize
@list = LinkedList.new
end
# Inserts a member into the current set.
@amiralles
amiralles / btree.rb
Last active December 8, 2019 20:06
General purpose binary tree implemented in Ruby.
class BTree
attr_accessor :root, :size
class Node
attr_accessor :parent, :data, :left, :right
def initialize parent, data
self.parent = parent
self.data = data
end
class AVLTree
# Represents an entry into the avl tree.
class Node
attr_accessor :key, :data, :height, :left, :right, :deleted
def initialize key, data
self.key = key
self.data = data
self.height = 1
@amiralles
amiralles / graph.rb
Created November 29, 2018 18:50
Graph implementation using Ruby
require_relative "./linked_list.rb"
require_relative "./set.rb"
# Here we monkey patched LinkedList to add a method
# that allows us to remove vertices in constant time.
class LinkedList
# Removes the node that is right next
# to the specified node.
# Complexity O(1).
def remove_next prev_node
@amiralles
amiralles / plist.rb
Created December 11, 2018 12:12
Persistent list implemented in Ruby.
require_relative "./linked_list.rb"
class LinkedList
# Reuses list nodes from the specified node
# to the end of the list.
# The complexity of this method is O(n) where n
# is the distance from the target node to the
# end of the list.
def reuse_from_node node
@amiralles
amiralles / myls.c
Last active September 24, 2019 02:25
Alternative implementation for the UNIX ls command.
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <dirent.h>
#include <pwd.h>
#include <grp.h>
#include <time.h>
@amiralles
amiralles / katrina.vim
Created June 18, 2020 23:57
Vim dark colorscheme
hi clear
if &t_Co > 255
" hi Normal ctermbg=234
hi CursorLine ctermbg=235 cterm=none
hi CursorLineNr ctermfg=208 cterm=none
hi Boolean ctermfg=135
hi Character ctermfg=144
hi Number ctermfg=135
hi String ctermfg=156
// All of this sortcuts are ergonomic if you remap
// CAPS -> Ctrl
// Right Opt -> Esc
//(I use Karabiner-Elements for that.)
[
{ "keys": [",", "/"],
"context": [
{ "key": "setting.command_mode", "operand": true },
{ "key": "setting.is_widget", "operand": false }
],
{
// Vim stuff.
"vintage_start_in_command_mode": true,
"vintage_ctrl_keys": true,
"added_words": [],
"caret_style": "smooth",
"tab_size": 2,
"translate_tabs_to_spaces": true,
"use_tab_stops": true,
@amiralles
amiralles / gitmine
Last active October 7, 2022 19:47
Shell script to mine your git repos.Copy this into your bin directory and run gitmine without arguments to see a list of available commands.
#!/bin/bash
function frequently_changed_files {
git log --name-only --pretty=format: | sort | uniq -c | sort -nr
}
# Find classes names on a given file.
function find_classes {
filename=$1
# Possible matches: