Skip to content

Instantly share code, notes, and snippets.

View denvaar's full-sized avatar
💭
👁👃👁

Denver Smith denvaar

💭
👁👃👁
View GitHub Profile
@denvaar
denvaar / assoc_array.c
Created February 25, 2024 16:59
AssocArray Refactor
#include <stdbool.h>
#include <stdlib.h>
#include "assoc_array.h"
typedef struct AssocArrayItem {
char key;
unsigned int value;
} AssocArrayItem;
@denvaar
denvaar / `mix format` on save for Neovim.md
Last active June 22, 2022 05:55
`mix format` on save in vim

There Are a few challenges when it comes to automatically mix format-ing your files on save in Vim.

  • Needs to happen async, so it doesn't block you from typing while it's working.
  • You want to be able to keep your cursor position, not be reset to the top of the file after formatting completes.
  • Formatting should happen smoothly whether doing :w, or :wq. Formatting after :wq gave me trouble in the past and would fail formatting. I think this is because mix format was called via the editor, but then the editor process exited, so it was getting terminated (I think).

This simple config seems to do a pretty good job at solving these challenges:

First, in $nvim_config_dir/ftplugin/elixir.vim (and eelixir.vim) I have an autocommand set up. It uses BufWritePost because the work is going to happen async. I think BufWritePre should be OK too.

@denvaar
denvaar / s3_downloads.ex
Last active January 9, 2024 02:15
Dependency free presigned S3 links
defmodule S3Downloads do
@moduledoc """
Use at your own risk.
Code heavily borrowed from:
- https://github.com/ex-aws/ex_aws/blob/main/lib/ex_aws/auth.ex
- https://gist.github.com/chrismccord/37862f1f8b1f5148644b75d20d1cb073
"""
@denvaar
denvaar / init.vim
Created September 21, 2019 18:04
Run mix format on file save in vim
function FormatElixirCode()
let l:winview = winsaveview()
silent %!mix format -
call winrestview(l:winview)
:endfunction
autocmd BufWritePre *.ex,*.eex :call FormatElixirCode()
@denvaar
denvaar / gist:109cdd4ed506a9e187320f438e0eb018
Created November 28, 2017 15:04
Setup Erland and Elixir on Amazon GNU/Linux
# Erlang
wget http://www.erlang.org/download/<latest_version>.tar.gz
tar -zxvf <latest_version>.tar.gz
# inside of the extracted directory:
./configure
make
sudo make install
# Elixir
wget https://github.com/elixir-lang/elixir/archive/<latest_version>.zip
@denvaar
denvaar / gist:1235fd26ec798c797e854fc06a7c7068
Created July 26, 2017 16:31
GraphQL query GitHub branches
query {
organization(login: "orgname") {
repository(name: "reponame") {
refs(first: 10, refPrefix: "refs/heads/") {
edges {
node {
name
}
}
}
@denvaar
denvaar / numberpairs.py
Last active February 13, 2017 03:43
Print out all pairs of numbers whose sum is equal to X
"""
You are given a sorted array of positive integers and a number 'X'.
Print out all pairs of numbers whose sum is equal to X.
Print out only unique pairs and the pairs should be in ascending order
Input:
Your program should accept as its first argument a filename.
This file will contain a comma separated list of sorted numbers
and then the sum 'X', separated by semicolon. Ignore all empty lines.
@denvaar
denvaar / traversal.go
Created February 12, 2017 21:47
Depth and Breadth-first traversal in a binary tree, implemented in Golang
package main
import "fmt"
type node struct {
value string
left *node
right *node
}
@denvaar
denvaar / bst.cpp
Created February 12, 2017 02:49
Binary Search Tree search, insert, and deletion operations with unit tests.
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <vector>
using namespace std;
struct Node {
int value;
Node *left;
Node *right;