Skip to content

Instantly share code, notes, and snippets.

@dbernheisel
dbernheisel / elixir_macro_lightning_talk.html
Last active April 25, 2017 00:37
Elixir Meetup Macro Lightning Talk
<!DOCTYPE html>
<html>
<head>
<title>Elixir Metaprogramming: An Introduction</title>
<meta charset="utf-8">
<style>
@import url(https://fonts.googleapis.com/css?family=Yanone+Kaffeesatz);
@import url(https://fonts.googleapis.com/css?family=Droid+Serif:400,700,400italic);
@import url(https://fonts.googleapis.com/css?family=Inconsolata:400,700,400italic);
@dbernheisel
dbernheisel / install-new-ssl-with-old-ruby.md
Last active March 30, 2017 01:59
Install modern SSL with old Ruby

Installing Old Rubies

How to tell old-man Ruby to work with the new OpenSSL kids

tldr:

wget https://gist.githubusercontent.com/dbernheisel/82e9bf55d01fe167a815425f77a71cc4/raw/e0af0db1139448e6a32a80d8b94a750644c2d8af/old-jerk-ruby-ssl.patch -O ~/old-jerk-ruby-ssl.patch
RUBY_CONFIGURE_OPTS="--with-openssl-dir=$(brew --prefix openssl)" rbenv install --patch 1.8.7-p375 < ~/old-jerk-ruby-ssl.patch

Older Ruby versions (1.8.7 or older) were built with an old OpenSSL version in mind, so if we try to build old Ruby

--- ext/openssl/ossl_pkey_ec.c
+++ ext/openssl/ossl_pkey_ec.c
@@ -757,8 +757,10 @@ static VALUE ossl_ec_group_initialize(int argc, VALUE *argv, VALUE self)
method = EC_GFp_mont_method();
} else if (id == s_GFp_nist) {
method = EC_GFp_nist_method();
+#if !defined(OPENSSl_NO_EC2M)
} else if (id == s_GF2m_simple) {
method = EC_GF2m_simple_method();
+#endif
# unmodified
# LICENSE CDDL 1.0 + GPL 2.0
#
# Copyright (c) 1982-2016 Oracle and/or its affiliates. All rights reserved.
#
# ORACLE DOCKERFILES PROJECT
# --------------------------
# This is the Dockerfile for Oracle Database 12c Release 1 Enterprise Edition
#

Elixir Error Handling

  1. Exceptions
  2. Errors as data
  3. On the nature of bugs... Let it... crash?
  4. Supervisors & Strategies
  5. Recovering State

Exceptions

@dbernheisel
dbernheisel / finder_functions.ex
Last active January 12, 2021 13:05
Elixir module to use for Ecto models. This macro will implement Rails-like finder functions for the given module.
defmodule Common.FinderFunctions do
@moduledoc """
Certainly not a perfect replication of Rails' finder methods, but at least gives Rails developers
some sense of home with Ecto. This does not reach into associations, nor is it huge-db friendly.
## Usage:
0. Don't. Just learn Ecto.
1. In your given module that implements Ecto's schema, let it
`use Common.FinderFunctions, repo: MyApp.Repo`. This also assumes there
is a changeset function on your model.
@dbernheisel
dbernheisel / seeds.rb
Last active March 29, 2017 15:38
Seeding for Rails environments
module Seed
def self.sprout
require_seed_modules!
puts "\n======= SEEDING FOR ALL ENVIRONMENTS"
seed_from(Seed::Base)
if Rails.env.development?
puts "\n======= SEEDING FOR DEVELOPMENT"
seed_from(Seed::Development)
@dbernheisel
dbernheisel / fibonacci.rb
Last active August 11, 2016 16:19
Return the n numbers in the Fibonacci sequence
def fib(n, sequence = [1, 1])
return [n] if n == 0
return [n] if n == 1
sequence << sequence[-1] + sequence[-2] while sequence.length < n
sequence
end
# fib(0) => [0]
# fib(1) => [1]
# fib(10) => [1, 1, 2, 3, 5, 8, 13, 21, 34, 55]
# 1. From the rightmost digit, which is the check digit, moving left, double the
# value of every second digit; if the product of this doubling operation is
# greater than 9 (e.g., 8 × 2 = 16), then sum the digits of the products
# (e.g., 16: 1 + 6 = 7, 18: 1 + 8 = 9).
# 2. Take the sum of all the digits.
# 3. If the total modulo 10 is equal to 0 (if the total ends in zero) then the
# number is valid according to the Luhn formula; else it is not valid.
@dbernheisel
dbernheisel / RubyTools.md
Last active October 29, 2015 14:56
Overview of good tools for Ruby developers

Definitions

Noice

Continuous Integration is the practice of testing each change done to your codebase automatically and as early as possible.

Continuous Deployment follows your tests to push your changes to either a staging or production system. This makes sure a version of your code is always accessible.

I need to write tests, know that my tests cover everything, run those tests often and deploy when ready, and know that my dependencies do the same, and collaborate on fixing bugs.