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
// 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 }
],
@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
@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 / 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 / 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
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 / 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
@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 / stack.rb
Created November 5, 2018 13:05
Stack implemented in Ruby.
class Stack
class Node
attr_accessor :next, :data
def initialize data
self.data = data
self.next = nil
end
end
attr_accessor :head, :tail, :length
class HashTable
class Slot
attr_accessor :key, :value, :vacated
def initialize key, value
self.key = key
self.value = value
self.vacated = true
end