Skip to content

Instantly share code, notes, and snippets.

View ddresselhaus's full-sized avatar

Dan Dresselhaus ddresselhaus

  • AdPipe
  • Atlanta
View GitHub Profile
@ddresselhaus
ddresselhaus / scheduler_utilization.ex
Created December 28, 2019 18:51
Erlang Scheduler Utilization
¯\_(ツ)_/¯ iex -S mix
Erlang/OTP 22 [erts-10.4.4] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]
Interactive Elixir (1.9.1) - press Ctrl+C to exit (type h() ENTER for help)
iex(1)> :scheduler.sample() |> :scheduler.utilization()
[
{:total, 0.081145584725537, '8.1%'},
{:normal, 1, 0.057692307692307696, '5.8%'},
{:normal, 2, 0.06521739130434782, '6.5%'},
{:normal, 3, 0.34545454545454546, '34.5%'},
defmodule Rover do
@directions ["N", "E", "S", "W"]
def execute(location_string, moves_string) do
location = parse_location(location_string)
moves = parse_moves(moves_string)
process_move(location, moves)
end
@ddresselhaus
ddresselhaus / .vimrc
Last active January 21, 2021 18:05
run Elixir tests in a separate tmux pane
" when triggering this command, vim will grab your path and line location and pass it along
map <Leader>el :call RemoteSendCommand(TestLineCommand(expand("%:p"), line(".")))<CR>
" because I'm mostly writing Elixir and making heavy use of the REPL while writing my tests,
" I made a specific command to user with Mix, the Elixir task utility
" But I'm sure you could get this to work with vim-test or something like that
function! TestLineCommand(path, line_number)
let cmd = join(["mix test --only", " line:", a:line_number, " ", a:path], "")
return cmd
endfunction
# https://projecteuler.net/index.php?section=problems&id=50
defmodule Primes do
def primes(ceiling), do: Enum.filter(1..ceiling, fn x -> is_prime(x) end)
def is_prime(n), do: factors(n, div(n, 2)) == [1]
def factors(1, _), do: [1]
def factors(_, 1), do: [1]
def factors(n, i) do
if rem(n, i) == 0 do