Skip to content

Instantly share code, notes, and snippets.

Avatar

Mark Holmberg mark-d-holmberg

View GitHub Profile
@jamesgmarks
jamesgmarks / gist:56502e46e29a9576b0f5afea3a0f595c
Last active Oct 30, 2020
MySQL/MariaDB BIN_TO_UUID and UUID_TO_BIN Polyfill
View gist:56502e46e29a9576b0f5afea3a0f595c
DELIMITER //
CREATE FUNCTION BIN_TO_UUID(b BINARY(16))
RETURNS CHAR(36)
BEGIN
DECLARE hexStr CHAR(32);
SET hexStr = HEX(b);
RETURN LOWER(CONCAT(
SUBSTR(hexStr, 1, 8), '-',
SUBSTR(hexStr, 9, 4), '-',
@srevenant
srevenant / time.ex
Last active Oct 10, 2019
Time bits for use in Elixir. Sometime, it's easier to just fall back to posix time... LMK if you find better ways to do this!
View time.ex
defmodule Utils.Time do
import Utils.Types, only: [str_to_int!: 1, str_to_float: 1]
import Utils.Enum, only: [enum_rx: 2]
# note for future
# https://hexdocs.pm/nimble_parsec/NimbleParsec.html
def iso_time_range(input) when is_binary(input) do
case String.split(input, "/") do
[stime, etime] ->
@mark-d-holmberg
mark-d-holmberg / rails-5.2.3-ruby-2.6.4-gem-engine
Created Sep 10, 2019
Create a Rails 5.2.3 on Ruby 2.6.4 Gem engine running API JSON mode only
View rails-5.2.3-ruby-2.6.4-gem-engine
rails plugin new elemental -d mysql --mountable -T --dummy-path=spec/dummy --skip-action-mailer -C --skip-turbolinks --skip-action-cable --skip-spring --skip-active-storage --skip-coffee --skip-yarn --api -p
View Node.JS healthcheck
/* bring in configs, and backends, like db */
/* const config = require('config') */
let healthy = true
setInterval(() => {
// check db pools, maybe run a query, etc.
try {
if (db.check_health()) { // but do this with a timelimit that is less than check interval seconds
healthy = true
@srevenant
srevenant / .bashrc
Last active Sep 7, 2018
fast-forward git bash helpers
View .bashrc
# When working on a project with multiple developers master will get ahead of your work.
# To come in sync should you rebase? merge? what is a fast-forward? Lots of discussion
# is available on this, here are a few:
# https://hackernoon.com/git-merge-vs-rebase-whats-the-diff-76413c117333
# https://www.atlassian.com/git/tutorials/merging-vs-rebasing
#
# I prefer a merge/fast-forward, rather than rebase. These helpers assist in that process.
# LMK your thoughts and if you know of a better way! Enjoy!
@tkfu
tkfu / srd_5e_monsters.json
Last active Dec 3, 2020
A JSON file with all the D&D 5e SRD monster data
View srd_5e_monsters.json
[
{
"name": "Aboleth",
"meta": "Large aberration, lawful evil",
"Armor Class": "17 (Natural Armor)",
"Hit Points": "135 (18d10 + 36)",
"Speed": "10 ft., swim 40 ft. ",
"STR": "21",
"STR_mod": "(+5)",
"DEX": "9",
@elderbas
elderbas / class_controller.ex
Last active Aug 12, 2020
Elixir — Inserting Multiple Changesets Into Database - create batch
View class_controller.ex
def create_batch(conn, %{"people" => people_params}) do
changesets = Enum.map(people_params, fn class ->
Person.changeset(%Person{}, person)
end)
result = changesets
|> Enum.with_index()
|> Enum.reduce(Ecto.Multi.new(), fn ({changeset, index}, multi) ->
Ecto.Multi.insert(multi, Integer.to_string(index), changeset)
end)
@austra
austra / Largest Binary Gap
Last active Dec 14, 2017
Largest Binary Gap
View Largest Binary Gap
I read about this problem and thought I would try it. Later I found it is a question here too:
https://codility.com/programmers/lessons/1-iterations/binary_gap/
My first instinct was, "I know regex can do this, but I hate regex" (Which is also a good reason to get better at regex).
I couldn't quite hoop the syntax so I moved on. Here is what I came up with:
def max_binary_gap(n)
max_gap = 0
arr = n.to_s(2).chars
while arr.size > 2 do
@takeit
takeit / INSTALL.md
Last active Nov 24, 2020
Write to NTFS on macOS Sierra (osxfuse + ntfs-3g)
View INSTALL.md
  1. Install osxfuse:
brew cask install osxfuse
  1. Reboot your Mac.

  2. Install ntfs-3g:

@maxmanders
maxmanders / kms_example.sh
Created Apr 13, 2017
KMS Envelope Encryption Using OpenSSL And AWS CLI
View kms_example.sh
$ echo "secret" > secret.txt
$ key_material=$(aws kms generate-data-key --key-id <CMK_key_id> --key-spec AES_256)
$ echo ${key_material} | jq ".CiphertextBlob" | sed 's/"//g' | base64 -d > key.enc
$ export key=$(echo ${key_material} | jq ".Plaintext" | sed 's/"//g' | base64 -d)
$ openssl enc -aes-256-cbc -pass env:key -in secret.txt -out secret.txt.enc
$ rm secret.txt
$ ls
key.enc secret.txt.enc
$ key=$(aws-fd-full kms decrypt --ciphertext-blob fileb://key.enc --output text --query Plaintext | base64 -d)
$ openssl enc -d -aes-256-cbc -pass env:key -in secret.txt.enc -out secret.txt
You can’t perform that action at this time.