Skip to content

Instantly share code, notes, and snippets.

View manuel-rubio's full-sized avatar
👋
Say Hi! and let me know if you want to contribute!

Manuel Rubio manuel-rubio

👋
Say Hi! and let me know if you want to contribute!
View GitHub Profile
@manuel-rubio
manuel-rubio / crc16.erl
Last active August 11, 2023 13:37
crc16.erl
-module(crc16).
-export([calculate/1]).
calculate(Data) ->
calculate(Data, 0).
calculate([H | T], CRC) when H >= 0 andalso H =< 255 ->
calculate(T, (CRC bsl 8) bxor crc16tab(((CRC bsr 8) bxor H) band 16#00FF));
calculate([], CRC) ->
@manuel-rubio
manuel-rubio / chat.ex
Created November 15, 2022 11:03
Chat server using GenServer
defmodule Chat do
@moduledoc """
Handle a process with a name for performing chat with other processes of the same kind.
It is an example about how a chat could be, based on the interchange of information
between the processes in a direct way, or using a list of processes.
"""
use GenServer
@type name() :: atom()
@manuel-rubio
manuel-rubio / reading_time.exs
Created May 19, 2022 20:41
Reading time extension for Lambdapad
@doc """
A transformation for items. Analyze the content configuring a new value in the metadata
called `reading_time`.
"""
transform "reading_time" do
set on: :item
set run: fn(post, _config) ->
words_count =
post["content"]
@manuel-rubio
manuel-rubio / categories.exs
Created May 11, 2022 23:39
Categories extension for lambdapad
@doc """
A set of transformations to help us work with categories.
This extension requires the following configuration entries:
[categories.desarrollo]
class = "cat-1"
link = "category/desarrollo"
[categories.historias]
class = "cat-2"
@manuel-rubio
manuel-rubio / broken_local_links.exs
Created May 11, 2022 23:28
Broken local links extension for lambdapad
@manuel-rubio
manuel-rubio / get-run-cmd
Last active August 2, 2021 14:10 — forked from djmaze/get-run-cmd
Get run command from running Docker container
#!/bin/bash
set -eo pipefail
container=$1
image=$(docker inspect --format '{{.Config.Image}}' $container)
cmd=$(docker inspect --format '{{.Config.Cmd}}' $container)
if [[ $cmd == '<nil>' ]]; then cmd=''; fi
binds=$(docker inspect --format '{{.HostConfig.Binds}}' $container | sed "s/\[//; s/\]//")
if [[ $binds == '<nil>' ]]; then binds=''; fi
envs=$(docker inspect --format '{{.Config.Env}}' $container | sed "s/\[//; s/\]//")
@manuel-rubio
manuel-rubio / .gitconfig
Created March 2, 2021 08:37
Configuration for Git
[core]
# delta requires installation (delta & bat)
pager = delta
[delta]
plus-color = "#012800"
minus-color = "#340001"
# syntax-theme = gruvbox-light
syntax-theme = gruvbox
[interactive]
@manuel-rubio
manuel-rubio / adjacent_cells.ex
Created October 20, 2019 21:52
Search adjacent cells of the same color.
defmodule AdjacentCells do
@moduledoc """
This module is a way to search, mark and count the adjacent cells based on
the post published by Kevin Ghadyani originally in JavaScript and showing
that using Elixir the code could be simpler and powerful.
https://medium.com/free-code-camp/bet-you-cant-solve-this-google-interview-question-4a6e5a4dc8ee
Indeed, the original code run by Kevin is spending in the better case 229 ms
with 3 random colors and more than 1 second with only one color.

More Testing ephp

To continue testing ephp with the new features I release, first we need a fresh ephp version:

git clone https://github.com/altenwald/ephp
cd ephp
make
@manuel-rubio
manuel-rubio / Vagrantfile
Created October 28, 2014 09:15
Vagrantfile for a CentOS 6.4 64bits
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Vagrantfile API/syntax version. Don't touch unless you know what you're doing!
VAGRANTFILE_API_VERSION = "2"
Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
config.vm.box = "centos-6.4"
config.vm.box_url =
"http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210.box"