Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

View darrenclark's full-sized avatar

Darren Clark darrenclark

View GitHub Profile
@darrenclark
darrenclark / snippet.java
Created November 9, 2021 14:33
Java Byte Buffers
import java.nio.ByteBuffer;
// is a byte[] under the hood
ByteBuffer buffer1 = ByteBuffer.allocate(12);
// is a block of bytes (similar to malloc)
ByteBuffer buffer2 = ByteBuffer.allocateDirect(12);
// buffers have a "position" that is advanced by read/write operations
buffer1.put((byte)1).put((byte)2).put((byte)3).put((byte)4);
#/usr/bin/env bash
echo $(( ($(date -j -f "%d %B %Y" "$(cal -N -e)" +%s) - $(date +%s)) / (24 * 60 * 60) )) days until the Easter bunny comes
@darrenclark
darrenclark / progress-bar.sh
Created November 25, 2011 05:02
Shell Progress Bar
# After wondering how commands like curl showed a progress bar, with the very big help of
# Google, I decided to write a shell script to show a progress bar
#
# Having not done much shell scripting, I learned a few (very likely quite obvious) things:
# * It looks much nicer to create the string to echo in a variable, then echo it. If I echo'ed
# each part of the string instead of concatenating it with the rest of the string, the cursor
# jumped around quite a bit.
# * 'let x=x+1' is a lot faster than 'x=`expr $x + 1`' (I have a feeling this is probably because
# let is implemented directly in bash, instead of a separate command)
@darrenclark
darrenclark / bugsnag_logger_backend.ex
Created September 1, 2022 17:34
BugsnagLoggerBackend
defmodule BugsnagLoggerBackend do
@behaviour :gen_event
@impl true
def init(__MODULE__) do
{:ok, %{}}
end
@impl true
def handle_call({:configure, _options}, state) do