Skip to content

Instantly share code, notes, and snippets.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@jootse84
jootse84 / redblacktree.erl
Created March 6, 2017 02:38
Red-Black Tree in Erlang
-module(redblacktree).
-export([insert/2, empty_node/0,test/0]).
-define(BLACK, 'b').
-define(RED, 'r').
-define(BLACK_EMPTY_NODE, {?BLACK, nil, nil, nil}).
-define(RED_EMPTY_NODE, {?RED, nil, nil, nil}).
% 1 - black
% 0 - red
@jootse84
jootse84 / bubble.py
Last active September 19, 2018 23:25
Bubble sort recursive implementation in Python
def bubble(l_elems, is_sorted, step):
if step is 1 or is_sorted:
# base case: l_elems is already sorted or we pass through the list len(l_elems) times
return l_elems
else:
is_swapped = False
for i in range(len(l_elems) - 1):
# compares each pair of adjacent items and swaps them if they are in the wrong order
if l_elems[i] > l_elems[i + 1]:
is_swapped = True
@jootse84
jootse84 / retflix_improvement.R
Last active December 23, 2016 19:11
Movie recommendation system developed in R language, improvement for RC
# The program recommends to you a movie list based on the responses about movies ratings.
# How it works? It calculates the similarity between your responses and other users in the system, and recommends to you
# movies from the user with higher similarity (cosine index similarity: https://en.wikipedia.org/wiki/Cosine_similarity).
## How to run it? > Rscript retflix_improvement.R --test
getRecommendations <- function () {
# returns vector with the responses in order about the movies selected by the ids from indices
movieSurvey <- function (indices, movies) {
@jootse84
jootse84 / retflix.R
Last active December 23, 2016 07:23
Movie recommendation system developed in R language
# The program recommends to you a movie list based on the responses about movies that you have already seen.
# How it works? It calculates the similarity between your responses and other users in the system, and recommends to you
# movies from the user with higher similarity (jaccard index similarity: https://en.wikipedia.org/wiki/Jaccard_index).
## How to run it? > Rscript retflix.R --test
## Use --test command parameter to use for the user data frame a small sample with 8 movies and 3 users.
getRecommendations <- function () {
# returns vector with the responses in order about the movies selected by the ids from indices
@jootse84
jootse84 / chorela_map.py
Created December 12, 2016 11:23
John Snow's 1854 cholera map.
'''
John Snow created a map in 1854 about the cholera outbreak in London.
Snow plotted cholera cases in the Soho area of London around Broad Street and noticed a cluster around a water pump.
This led to improved sanitation facilities and also the discovery that cholera infection was water-borne rather than airborne.
This program:
* initally have a set of sample points - x,y (representing locations of chollera infection cases)
* allow the user to introduce Points of Interest - x,y (representing water pipes, buildings, markets ...)
* calculate the final result, representing the Point of Interest closer to all the cholera infection cases.
'''
@jootse84
jootse84 / tictactoe.py
Created July 21, 2016 10:11
Python version of the game Tic Tac Toe for second interview at RC
import sys
SYMBOLS = ['X', 'O']
def main(argv):
game = Game()
game.welcome()
game.start_game()
class Game:
@jootse84
jootse84 / trie.js
Last active December 21, 2016 11:35
A class that saves MQTT topics in a trie structure. The trie structure is represented by an Object which keys contains the topics levels.
/**
* @file Trie class
* @author Jose E. Martinez <[email protected]>
* @description A class that saves MQTT topics in a trie structure. The trie structure is represented by an Object which keys contains the topics levels. In addition, the topic levels with the key '$' as 'true' are the completed topics.
*
* @see [Project info]{@link https://jootse84.github.io/notes/create-your-own-MQTT-broker.-part-1}
* @see [Trie structure]{@link https://en.wikipedia.org/wiki/Trie}
* @see [MQTT topic]{@link http://www.hivemq.com/blog/mqtt-essentials-part-5-mqtt-topics-best-practices}
*
* @example