Skip to content

Instantly share code, notes, and snippets.

@maxmanders
maxmanders / kms_example.sh
Created April 13, 2017 11:36
KMS Envelope Encryption Using OpenSSL And AWS CLI
$ 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
@slashdotdash
slashdotdash / upsert_profile.ex
Last active July 26, 2020 23:09
Upserts in Ecto using `Ecto.Multi`
defp upsert_profile(multi, source, source_uuid, profile_url) do
profile = %Profile{
source: source,
source_uuid: source_uuid,
profile: profile_url,
}
Ecto.Multi.insert(multi, source_uuid, profile, on_conflict: [set: [profile: profile_url]], conflict_target: [:source, :source_uuid])
end
@MaxLap
MaxLap / rubocop.rb
Last active March 12, 2024 17:15 — forked from skanev/rubocop.rb
A Rubocop wrapper that checks only added/modified code
#!/usr/bin/env ruby
# A sneaky wrapper around Rubocop that allows you to run it only against
# the recent changes, as opposed to the whole project. It lets you
# enforce the style guide for new/modified code only, as opposed to
# having to restyle everything or adding cops incrementally. It relies
# on git to figure out which files to check.
#
# Here are some options you can pass in addition to the ones in rubocop:
#
@kipcole9
kipcole9 / Map.Helpers
Last active October 24, 2023 22:13
Helpers for Elixir Maps: underscore, atomise and stringify map keys
defmodule Map.Helpers do
@moduledoc """
Functions to transform maps
"""
@doc """
Convert map string camelCase keys to underscore_keys
"""
def underscore_keys(nil), do: nil
@fernandoaleman
fernandoaleman / fix-libv8-mac.txt
Created May 5, 2016 15:14
Fixing libv8 and therubyracer on Mac
brew tap homebrew/versions
brew install v8-315
gem install libv8 -v '3.16.14.13' -- --with-system-v8
gem install therubyracer -- --with-v8-dir=/usr/local/opt/v8-315
bundle install
@bastman
bastman / docker-cleanup-resources.md
Created March 31, 2016 05:55
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

@gabrielelana
gabrielelana / Vagrantfile
Last active January 2, 2024 18:58
How to create a VirtualBox machine with encrypted storage with Vagrant
# -*- mode: ruby -*-
# vi: set ft=ruby :
PASSWORD_PATH = ".password"
PASSWORD_ID_PATH = ".password_id"
# Make sure to have installed vagrant-triggers plugin
# > vagrant plugin install vagrant-triggers
# After the first `vagrant up` stop the VM and execute the following steps
@evg2108
evg2108 / string_as_slim_template.md
Last active February 4, 2019 06:41
render string as slim template

#render string as slim template

example:

module WelcomeHelper
  def tile_link_to(title, href, icon_content = nil, &block)
    icon_content = capture { block.call }.strip.squish if block_given?
    content = <<-slim
 .tile
@mark-d-holmberg
mark-d-holmberg / simple_form.rb
Created January 22, 2016 00:22
Simple Form Bootstrap Ruby Engine Config
# lib/my-engine/simple-form.rb
require 'simple_form'
# https://gist.github.com/mark-d-holmberg/78f2909de5b59a09329c
# Use this setup block to configure all options available in SimpleForm.
SimpleForm.setup do |config|
# Wrappers are used by the form builder to generate a
# complete input. You can remove any component from the
# wrapper, change the order or even add your own to the