Skip to content

Instantly share code, notes, and snippets.

View ejpcmac's full-sized avatar
🎯
Focusing

Jean-Philippe Cugnet ejpcmac

🎯
Focusing
View GitHub Profile
@ejpcmac
ejpcmac / my_app
Created May 1, 2017 08:38
FreeBSD startup script for Elixir/OTP release
#!/bin/sh
#
# PROVIDE: my_app
# REQUIRE: networking
# KEYWORD:
. /etc/rc.subr
name="my_app"
rcvar="${name}_enable"
@ejpcmac
ejpcmac / bazik.zsh-theme
Created July 17, 2017 11:02
Bazik ZSH theme
###################
# Bazik ZSH theme #
###################
# Colored ls
# a black
# b red
# c green
# d brown
# e blue
@ejpcmac
ejpcmac / passphrase.rs
Created March 15, 2018 22:21
Procedural vs functional Rust for passphrase generation
// Let’s say we have a word list.
let word_list: Vec<String> = ...;
// We want to generate a random passphrase using words from the list.
// Let’s see how to do this with equal performance in two different styles:
// procedural and functional Rust.
// In both cases we need a random generator.
let mut rng = rand::thread_rng();
@ejpcmac
ejpcmac / loop.ll
Last active March 27, 2018 17:22
Rust loop performance
; test_loop::sum_manual
; Function Attrs: noinline uwtable
define internal fastcc void @_ZN9test_loop10sum_manual17h519a3902bc8dc8acE(%"alloc::string::String"* noalias nocapture dereferenceable(24), i64** dereferenceable(8) %rng, i8 %n) unnamed_addr #5 {
start:
%sum = alloca i32, align 4
%1 = bitcast i32* %sum to i8*
call void @llvm.lifetime.start(i64 4, i8* nonnull %1)
store i32 0, i32* %sum, align 4
%2 = icmp eq i8 %n, 0
br i1 %2, label %bb2, label %bb3.preheader
@ejpcmac
ejpcmac / fixtures.ex
Created July 1, 2018 15:35
Recursively defining fixtures
defmodule Fixtures do
def user do
quote do
def user, do: :user
end
end
def client do
quote do
# You can use fixtures recursively.
@ejpcmac
ejpcmac / shell.nix
Last active February 12, 2024 18:03
Example shell.nix for Elixir projects using a preversion
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
elixir_1_7_0_rc_1 = { mkDerivation }:
mkDerivation rec {
version = "1.7.0-rc.1";
# Use `nix-prefetch-github --rev <version> elixir-lang elixir` to update.
sha256 = "1hp1zdscq7h2qcgcfbzw5dx1wxy05bqlrxvv5kcl8414c69inx8g";
@ejpcmac
ejpcmac / shell.nix
Last active March 10, 2021 16:37
Example shell.nix for Nerves projects, setting both Erlang and Elixir versions
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
inherit (lib) optional optionals;
erlangDrv = { mkDerivation }:
mkDerivation rec {
version = "21.0";
@ejpcmac
ejpcmac / .envrc
Created September 18, 2018 12:36
.envrc for persistent cached Nix shells
####################################
# Environment setup for Nix shells #
####################################
# From https://github.com/direnv/direnv/wiki/Nix#persistent-cached-shell
#
# Usage: use_nix [...]
#
# Load environment variables from `nix-shell`.
# If you have a `default.nix` or `shell.nix` one of these will be used and
@ejpcmac
ejpcmac / shell.nix
Created September 26, 2018 20:29
Bare minimum shell for Elixir projects
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
# I like to define variables for derivations that have
# a specific version and are subject to change over time.
elixir = beam.packages.erlangR21.elixir_1_7;
in
@ejpcmac
ejpcmac / shell.nix
Last active September 26, 2018 20:48
Shell for standard Elixir projects with file_system and ExUnit Notifier
{ pkgs ? import <nixpkgs> {} }:
with pkgs;
let
inherit (lib) optional optionals;
elixir = beam.packages.erlangR21.elixir_1_7;
in
mkShell {