Skip to content

Instantly share code, notes, and snippets.

View philss's full-sized avatar

Philip Sampaio philss

View GitHub Profile
@philss
philss / rvm_ruby_install.sh
Created November 24, 2011 03:50
Rvm & Ruby 1.9.2 installation
#!/bin/bash
bash < <(curl -s https://raw.github.com/wayneeseguin/rvm/master/binscripts/rvm-installer )
source $HOME/.bashrc
rvm install ruby-1.9.2
#include <stdio.h>
#define MAX_N 5000
int main() {
int size = 0;
int tmp = 0;
int i = 0;
int soma = 0;
scanf("%d",&size);
@philss
philss / math.ex
Last active August 29, 2015 13:56
A simple recursion example using pattern matching.
defmodule Math do
def sum_list([number]) do
number
end
def sum_list([head|tail]) do
head + sum_list(tail)
end
end
@philss
philss / git_utils.sh
Last active August 29, 2015 14:14
A collection of shell script functions to work with git.
# Returns a list of files with a given term
function git_grep_files() {
git grep $1 | awk -F ':' '{print $1}' | sort | uniq
}
# Replace terms inside a git repository
#
# Example:
# git_replace "original_term" "new_term"
function git_replace() {
@philss
philss / zofe-audio-file-lengths.rb
Created February 21, 2015 04:24
This script fetches the audio file length in bytes for each audio file of ZOFE podcast
require 'yaml'
Dir.glob("./_posts/*.md").each do |post_file_path|
post = YAML.load_file(post_file_path)
audio_url = post.fetch("audio")
# NOTE: cURL may return multiple lines with length because
# it follows the redirects of the server.
#
lengths = `curl -I -L #{audio_url} | grep "Content-Length"`
@philss
philss / zshrc
Created June 30, 2015 20:41
Zsh git functions
# Put those functions on your ~/.zshrc or something similar.
# Cleans all merged branches (relative to the branch you are). Recommended to run from master.
function git_clean_branches()
{
# Fetch all merged branches that are not the master branch, and not the current branch
echo 'Deleting all merged branches...'
for branch in `git branch --merged | awk -F ' * ' '{print $2}' | grep -v -e 'master' | grep -v -e '*'`
do
echo "Removing .. $branch"
@philss
philss / ternjs-with-neovim.md
Last active August 12, 2018 13:26
Some details about my installation of Ternjs with Neovim and Deoplete

Ternjs with Neovim

  • upgrade nvim (in my case, I have the master version):
$ brew tap neovim/neovim
$ brew reinstall --HEAD neovim
  • check Python 2 and 3, if are installed:
$ which python2

Mutual recursion

Every finete state machine that does not need to hold state can be represented by a mutual recursive pair (or more) of functions.

ML specific

You can implement mutual recursion using the built-in and keyword between functions. It is also possible to implement it using a higher order function (a function that receives another function).

SML Module System

There is a way to define a namespace in SML: define an "structure" that creates a module.

Example:

structure MyMath =
struct
val pi = 3.141529
@philss
philss / docker-compose.yml
Created February 20, 2018 03:23
Example of docker compose for a Phoenix App
version: "3.3"
services:
db:
image: postgres
ports:
- "5432"
web:
build:
context: .
dockerfile: Dockerfile