Skip to content

Instantly share code, notes, and snippets.

@mark-d-holmberg
mark-d-holmberg / rails-5.2.3-ruby-2.6.4-gem-engine
Created September 10, 2019 20:51
Create a Rails 5.2.3 on Ruby 2.6.4 Gem engine running API JSON mode only
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
@srevenant
srevenant / time.ex
Last active October 10, 2019 19:41
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!
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] ->
@kellishaver
kellishaver / SublimeBlockCursor.py
Created June 26, 2012 15:32
Sublime Text 2 Block Cursor - outside of Vintage Mode
import sublime
import sublime_plugin
class SublimeBlockCursor(sublime_plugin.EventListener):
def view_is_widget(view):
settings = view.settings()
return bool(settings.get('is_widget'))
def show_block_cursor(self, view):
validRegions = []
@igrigorik
igrigorik / faraday-em-http.rb
Created January 30, 2011 01:12
using Faraday with EM-Synchrony & EM-Http
require 'faraday'
require 'net/http'
require 'pp'
# Repos:
# https://github.com/technoweenie/faraday
# https://github.com/pengwynn/faraday_middleware
# Blog posts:
# http://adventuresincoding.com/2010/09/writing-modular-http-client-code-with-faraday
#multiple-datasets .league-name {
margin: 0 20px 5px 20px;
padding: 3px 0;
border-bottom: 1px solid #ccc;
}
@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
@kuboon
kuboon / Gemfile
Created November 20, 2015 06:30
acts_as_taggable_on + simple_form + select2
gem 'acts-as-taggable-on'
gem 'simple_form'
gem 'select2-rails'
@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
#Sort the Ruby files in your project by LOC
find . -iname "*.rb" -type f -exec wc -l {} \; | sort -rn
#Count the lines of Ruby code in your app
find . -iname "*.rb" -type f -exec cat {} \; | wc -l