Skip to content

Instantly share code, notes, and snippets.

View tallakt's full-sized avatar

Tallak Tveide tallakt

View GitHub Profile
defmodule Between do
@doc """
## Examples
iex> list = for x <- 1000..1031, rem(x, 5) != 0, do: x
iex> chunks = Between.chunk_between(list, fn a, b -> b - a != 1 end)
iex> IO.inspect
[[1001, 1002, 1003, 1004], [1006, 1007, 1008, 1009], [1011, 1012, 1013, 1014],
[1016, 1017, 1018, 1019], [1021, 1022, 1023, 1024], [1026, 1027, 1028, 1029],
[1031]]
defmodule XStream do
@doc """
Returns a stream of all permutations of the given collection.
The count parameter will limit the number of elements, all are returned
by default
## Examples
@tallakt
tallakt / lazy_permutations.exs
Last active January 2, 2021 04:42 — forked from martinsvalin/lazy_permutations.exs
Lazy permutations in Elixir
defmodule LazyPermutations do
def permutations(list) do
list
|> Enum.sort
|> Stream.unfold fn
[] -> nil
p -> {p, next_permutation(p)}
end
end
defmodule MatchAndAssign do
defmacro __using__(_) do
quote do
require MatchAndAssign
import MatchAndAssign, only: [match_and_assign: 2]
end
end
defp unhygienize(pattern = {n, _meta, c}) when is_atom(n) and is_atom(c) do
var! pattern
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
#!/usr/bin/env ruby
require 'net/http'
require 'json'
def get_json(url)
uri = URI(url)
JSON.parse(Net::HTTP.get uri)
end
#!/bin/sh
# $ curl -s https://gist.githubusercontent.com/tallakt/7048c646b999faf17db98a49e6374324/raw/020b759c6f71d72efe67d2c7f8f7d6fcb87b8635/mining_fetch_git.sh -O mining_fetch_git.sh
cd /home/tallakt
if [ ! -e ~/mining/README.md ]; then
rm -Rf mining
git clone [email protected]:tallakt/mining.git
fi;
@tallakt
tallakt / mudsync.ex
Last active November 30, 2017 14:49
@doc """
# Mud Sync
Koden er basert på en modell hvor man har x pumper, hver med y stempel som går i
(360 / y) graders fase på hverandre. Man får en puls per omdreining av kamakselen. Hver
pumpe har sine egne pulser som brukes til synkronisering
"""
defmodule MudSync do
@tallakt
tallakt / init.vim
Last active January 5, 2018 08:41
init.vim
if empty(glob('~/.local/share/nvim/site/autoload/plug.vim'))
silent !curl -fLo ~/.local/share/nvim/site/autoload/plug.vim --create-dirs
\ https://raw.githubusercontent.com/junegunn/vim-plug/master/plug.vim
autocmd VimEnter * PlugInstall --sync | source ~/.config/nvim/init.vim
endif
call plug#begin('~/.local/share/nvim/plugged')
Plug 'andymass/vim-matchup'
Plug 'frankier/neovim-colors-solarized-truecolor-only'
#!/usr/bin/env ruby
require 'pty'
loop do
begin
PTY.spawn( "/usr/bin/gpspipe -w" ) do |stdout, stdin, pid|
stdout.each do |line|
m = line.match /"time":"(2...-..-..T..:..:......Z)"/