Skip to content

Instantly share code, notes, and snippets.

View cr0t's full-sized avatar
🏠
Working from home

Sergey ⚗️ Kuznetsov cr0t

🏠
Working from home
View GitHub Profile
@cr0t
cr0t / generate-swarm.sh
Created November 6, 2016 20:12 — forked from derwiki/generate-swarm.sh
Series of commands (not an executable script per se) to get you from a git repository to a Code Swarm AVI (tested on Linux and OS X).
CODESWARM_DIR="/home/user/src/code_swarm/"
# extract from your git repo
git log --name-status --pretty=format:'%n------------------------------------------------------------------------%nr%h | %ae | %ai (%aD) | x lines%nChanged paths:' > $CODESWARM_DIR/data/activity.log
# convert to XML for CodeSwarm
python convert_logs/convert_logs.py \
-g $CODESWARM_DIR/data/activity.log -o $CODESWARM_DIR/data/activity.xml
# create a new config that points to the correct input XML and saves snapshots

What I Wish I'd Known About Equity Before Joining A Unicorn

Disclaimer: This piece is written anonymously. The names of a few particular companies are mentioned, but as common examples only.

This is a short write-up on things that I wish I'd known and considered before joining a private company (aka startup, aka unicorn in some cases). I'm not trying to make the case that you should never join a private company, but the power imbalance between founder and employee is extreme, and that potential candidates would

`sudo purge`
memory_by_process = Hash.new(0)
processes = `ps aux`
m_bytes = processes.split("\n").reduce(0) { |memo, prc|
fields = prc.split(/\s+/)
mem_bytes = fields[5].to_i
prc_name = fields[10...fields.length].join(' ')
@cr0t
cr0t / sensor_hub_i2c.ex
Last active May 23, 2023 15:20
Raspberry Pi, DockerPi SensorHub, I2C, Circuits.I2C, Elixir
defmodule Reader do
defmodule SensorHub do
@moduledoc """
Opens the first I2C bus ("i2c-1") and reads from SensorHub device address (0x17).
Updates its internal state periodically (every second in the example below).
Below you can find a table of registers, that we found on their website:
https://wiki.52pi.com/index.php/DockerPi_Sensor_Hub_Development_Board_SKU:_EP-0106
@cr0t
cr0t / vega_kino_tesla_examples.md
Last active December 3, 2023 10:17
Example of using Tesla, VegaLite, and Kino libraries in Elixir's Livebook
@cr0t
cr0t / uni.erl
Created July 27, 2022 16:10
Universal Server ("My favorite Erlang Program")
% Read more:
% - https://joearms.github.io/published/2013-11-21-My-favorite-erlang-program.html
% - https://ferd.ca/my-favorite-erlang-container.html
%
% How to run:
% $ erl
% > c(uni).
% {ok,uni}
% > uni:test().
% 30414093201713378043612608166064768844377641568960512000000000000
# Origin: https://blog.sequin.io/how-we-used-elixirs-observer-to-hunt-down-bottlenecks/
defmodule Overload do
# Define a CPU-intenstive work function, which can call itself
# recursively (forever)
def recursive do
:public_key.generate_key({:rsa, 4096, 65537})
recursive()
end
end
@cr0t
cr0t / cond_vs_pattern.exs
Created November 15, 2022 22:30
Performance comparison between `cond` and multiple-clauses functions in Elixir
Mix.install([
{:benchee, "~> 1.0"}
])
defmodule BirdCond do
def busy_days(list) do
cond do
list == [] -> 0
hd(list) < 5 -> busy_days(tl(list))
true -> 1 + busy_days(tl(list))
@cr0t
cr0t / bench_async_vs_map.exs
Last active November 21, 2022 13:55
Performance comparison between simple `Enum.map` and `Task.async_stream` in Elixir (oversimplified case)
Mix.install([
{:benchee, "~> 1.0"}
])
defmodule Cruncher do
def async(n) do
1..n
|> Task.async_stream(&(&1 ** 2))
|> Enum.reduce(0, fn {:ok, s}, acc -> s + acc end)
end
@cr0t
cr0t / elixir.yml
Created November 29, 2022 09:42
GitHub Actions Elixir Workflow Example
name: Elixir CI
on:
push:
branches: ["master"]
pull_request:
branches: ["master"]
env:
MIX_ENV: test