Skip to content

Instantly share code, notes, and snippets.

View BenSchZA's full-sized avatar
🎯
Focusing

Benjamin Scholtz BenSchZA

🎯
Focusing
View GitHub Profile
@BenSchZA
BenSchZA / nose-override.nix
Created August 9, 2020 07:39
Override Python nose package to solve `OSError: AF_UNIX path too long`
packageOverrides = self: super: {
# OSError: AF_UNIX path too long
nose = super.nose.overridePythonAttrs (oldAttrs: { !pkgs.stdenv.isDarwin; });
};
python = (pkgs.python36.override {inherit packageOverrides;}).withPackages (pkgs: with pkgs; [
numpy # One of these packages depend on nose
pandas
]);
<%= f = form_for :select_user_type, "#", [phx_change: :select_user_type, phx_value_id: creds.id, class: "ui form"] %>
<%= select(f, :role, ["Admin": "admin", "User": "user"]) %>
</form>
def handle_event("select_user_type", %{"select_user_type" => %{"role" => role}}, socket) do
IO.inspect socket.assigns
{:noreply, socket}
end
<form action="#" class="ui form" method="post" phx-change="select_user_type" phx-value-id="1">
@BenSchZA
BenSchZA / attribute-import.nix
Created July 27, 2020 07:39
Import attributes from Nix derivation
let
default = import ./default.nix {};
pkgs = default.pkgs;
python = default.python;
pythonPackages = default.pythonPackages;
in {
...
}
@BenSchZA
BenSchZA / unzip3.ex
Created June 19, 2020 12:17
Enum.unzip for tuples of size 3...
def unzip3(enumerable) do
{list1, list2, list3} =
Enum.reduce(enumerable, {[], [], []}, fn {el1, el2, el3}, {list1, list2, list3} ->
{[el1 | list1], [el2 | list2], [el3 | list3]}
end)
{:lists.reverse(list1), :lists.reverse(list2), :lists.reverse(list3)}
end
@BenSchZA
BenSchZA / uplot-liveview-hooks.ex
Created June 19, 2020 09:52
Phoenix LiveView hooks with uPlot
{dates, counts} = CountByDateQuery.row_counts_by_date()
|> App.Repo.all()
|> Enum.with_index()
|> Enum.map(fn {{date, count}, index} ->
{:ok, date} = Timex.parse(date, "%b %Y", :strftime)
{Timex.to_unix(date), count}
end)
|> Enum.sort()
|> Enum.unzip()
@BenSchZA
BenSchZA / flatten.exs
Last active June 10, 2020 13:12
Flatten a nested map
data = %{"key1" => %{sub_key: :a}, "key2" => %{"sub_key1" => %{"sub_key" => "a"}, "sub_key2" => :a}}
defmodule Flatten do
def flat(data, acc) when is_bitstring(data) or is_atom(data), do: {acc, data}
def flat({key, value}, acc) do
flat(value,
case acc do
"" -> key
_ -> acc <> "." <> "#{key}"
end

Keybase proof

I hereby claim:

To claim this, I am signing this object:

@BenSchZA
BenSchZA / solidity-math.sol
Created May 31, 2019 12:40
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.5.8+commit.23d335f2.js&optimize=false&gist=
//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f.
pragma solidity ^0.5.7;
/**
* @title SafeMath
* @dev Math operations with safety checks that revert on error
*/
library SafeMath {
/**
@BenSchZA
BenSchZA / truffle-debug-error.txt
Created January 8, 2019 18:37
`truffle debug tx` error when inspecting variables
debug(development:0x225810e0...)> v
TypeError: Cannot read property 'id' of undefined
at step (/home/bscholtz/.node_modules/lib/node_modules/truffle/build/webpack:/~/babel-runtime/helpers/asyncToGenerator.js:17:1)
at Generator.next (<anonymous>)
at /home/bscholtz/.node_modules/lib/node_modules/truffle/build/webpack:/packages/truffle-debugger/dist/debugger.js:3135:1
at Session.view (/home/bscholtz/.node_modules/lib/node_modules/truffle/build/webpack:/packages/truffle-debugger/dist/debugger.js:3031:1)
at /home/bscholtz/.node_modules/lib/node_modules/truffle/build/webpack:/~/reselect/lib/index.js:36:1
at /home/bscholtz/.node_modules/lib/node_modules/truffle/build/webpack:/~/reselect/lib/index.js:86:1
at args (/home/bscholtz/.node_modules/lib/node_modules/truffle/build/webpack:/~/reselect-tree/index.js:209:1)
at Function.<anonymous> (/home/bscholtz/.node_modules/lib/node_modules/truffle/build/webpack:/~/reselect/lib/index.js:36:1)
# https://wiki.archlinux.org/index.php/Installing_Arch_Linux_on_ZFS
wifi-menu
ping archlinux.org
timedatectl set-ntp true
# https://wiki.archlinux.org/index.php/GNU_Parted
parted /dev/nvme0n1
> mklabel gpt