Skip to content

Instantly share code, notes, and snippets.

View adrianomitre's full-sized avatar

Adriano Mitre adrianomitre

  • Sao Paulo, SP - Brazil
View GitHub Profile
@adrianomitre
adrianomitre / hampel_filter_forloop_numba.py
Last active September 13, 2022 13:12
Hampel filter implementation in Python using numba
# Based on https://gist.github.com/erykml/9b07b916ceee78c207d14fa2548b8f6f#file-hampel_filter_forloop_numba-py
import numpy as np
from numba import jit
@jit(nopython=True)
def hampel_filter_forloop_numba(input_series, window_length, n_sigmas=3):
if window_length % 2 == 0:
raise ValueError('window_length should be odd')
@adrianomitre
adrianomitre / schedule_work_approaches.exs
Last active August 12, 2020 23:20
Two approaches to schedule work with GenServer
defmodule Worker do
use GenServer
@delay 5
defp work(source) do
IO.puts("work from #{source}")
end
# Client
@adrianomitre
adrianomitre / improved_heuristic_inference.exs
Last active July 29, 2020 22:37
Heuristic to infer whether a list should be printed as charlist in IEx - An improvement proposal
defmodule HeuristicInference do
@moduledoc """
Heuristic to infer whether a list should be printed as charlist in IEx.
An improvement proposal.
"""
def should_print_as_charlist?([]) do
true
end
@adrianomitre
adrianomitre / argf.exs
Last active July 15, 2020 03:13
uniformly stream from IO and File in Elixir (akin to Ruby's ARGF)
defmodule App do
defmodule CLI do
def main(argv) do
io_stream_from_file_args_or_stdin(argv)
|> App.process_stream()
end
defp io_stream_from_file_args_or_stdin(argv) do
get_io_source(argv)
|> IO.stream(:line)
@adrianomitre
adrianomitre / .gitconfig
Created August 15, 2016 17:12
My .gitconfig
[credential]
helper = cache --timeout=3600
[user]
name = Adriano Mitre
email = adriano.mitre@gmail.com
[core]
editor = subl --wait
[alias]
# one-line log
@adrianomitre
adrianomitre / ivona.py
Created July 20, 2016 18:51
IVONA CreateSpeech test based on AWS example
# AWS Version 4 signing example
# EC2 API (DescribeRegions)
# See: http://docs.aws.amazon.com/general/latest/gr/sigv4_signing.html
# This version makes a GET request and passes the signature
# in the Authorization header.
import sys, os, base64, datetime, hashlib, hmac
import requests # pip install requests
import urllib
@adrianomitre
adrianomitre / Twilight with GitGutter support.tmTheme
Created March 30, 2016 21:58
SublimeText 3 Twilight theme with GitGutter support
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>author</key>
<string>Michael Sheets</string>
<key>name</key>
<string>Twilight with GitGutter support</string>
<key>settings</key>
<array>
@adrianomitre
adrianomitre / circular_primes.rb
Last active February 24, 2016 18:14
Circular Primes
# Ruby solution to http://www.beatmycode.com/challenge/5/show
class Integer # in real apps should use refinements instead of monkey patching
def prime?
return false if self < 2
! 2.upto(self**0.5).any? { |n| self % n == 0 }
end
def rotations
n, ss = to_s.length, to_s * 2
@adrianomitre
adrianomitre / circular_primes_v1.rb
Created February 24, 2016 17:59
Circular Primes v1
# O( N log N )
class Integer # in real apps should use refinements instead of monkey patching
def prime?
return false if self < 2
! 2.upto(self**0.5).any? { |n| self % n == 0 }
end
def rotations
n, ss = to_s.length, to_s * 2
@adrianomitre
adrianomitre / migration_tricks.rb
Last active February 3, 2016 20:21
Changing tables from within the Rails console
ActiveRecord::Migration.class_eval do
change_table :teams, :force => true do |t|
# copy and paste from migrations create_table block, e.g.,
t.string :slug, unique: true
end
# specific commands
add_column :people, :cpf, :integer, null: false
remove_column :people, :cpf