Skip to content

Instantly share code, notes, and snippets.

Rails naming conventions

General Ruby conventions

Class names are CamelCase.

Methods and variables are snake_case.

Methods with a ? suffix will return a boolean.

@osazemeu
osazemeu / sha256-hmac.md
Created July 26, 2021 21:52 — forked from jasny/sha256-hmac.md
Hashing examples in different languages

Example inputs:

Variable Value
key the shared secret key here
message the message to hash here

Reference outputs for example inputs above:

| Type | Hash |

@osazemeu
osazemeu / gist:4bdf00813d6bc1b31116150231cb69f2
Last active December 29, 2019 02:21 — forked from jkubacki/gist:e2dd904bd648b0bd4554
Mac uninstall elasticsearch
#!/usr/bin/env sh
# checks to see if running
launchctl list | grep elasticsearch
launchctl unload ~/Library/LaunchAgents/homebrew.mxcl.elasticsearch.plist
launchctl remove homebrew.mxcl.elasticsearch
pkill -f elasticsearch
@osazemeu
osazemeu / custom_array.rb
Last active June 20, 2019 20:05
This gist illustrates the flatten array method from ground up. :)
# This solution attempts to handle flattening of nested arrays gracefully
class CustomArray
def flatten(array)
raise 'input is not an array' unless array?(array)
return [] if array.empty?
recursive_flatten(array)
end
private
@osazemeu
osazemeu / README.md
Created June 8, 2019 14:57 — forked from cohawk/README.md
CockroachDB fork of the postgrex adapter - Elixir Ecto caveats

Over the weekend I spun up a new Elixir :ecto, "2.2.7" project that I was able to get working with CockroachDB and this adapter fork - with some caveats I wanted to share to help others.

  1. Only the root user can create databases This requires you configure the Ecto.Adapters.Postgres username as root or else the mix ecto.create command will always fail. You can go back and change your configured username to something else after the database has been created, or create your database and user permissions using cockroach sql and skip the mix ecto.create command.

  2. Configuring Ecto primary_key ID to be created by CockroachDB By default when configuring your Ecto.Schema using autogenerate: false it appears either CockroachDB, Ecto or the Postrex adapter (I did not investigate this) uses the BIGINT unique_rowid() function as the default value for IDs

@primary_key {:id, :id, autogenerate:
@osazemeu
osazemeu / latency_numbers.md
Created March 2, 2019 14:26 — forked from GLMeece/latency_numbers.md
Latency Numbers Every Programmer Should Know - MarkDown Fork

Latency Comparison Numbers

Note: "Forked" from Latency Numbers Every Programmer Should Know

Event Nanoseconds Microseconds Milliseconds Comparison
L1 cache reference 0.5 - - -
Branch mispredict 5.0 - - -
L2 cache reference 7.0 - - 14x L1 cache
Mutex lock/unlock 25.0 - - -
@osazemeu
osazemeu / S3-Static-Sites.md
Created May 22, 2018 14:19 — forked from bradwestfall/S3-Static-Sites.md
Use S3 and CloudFront to host Static Single Page Apps (SPAs) with HTTPs and www-redirects. Also covers deployments.

S3 Static Sites

What this will cover

  • Host a static website at S3
  • Redirect www.website.com to website.com
  • Website can be an SPA (requiring all requests to return index.html)
  • Free AWS SSL certs
  • Deployment with CDN invalidation

Resources

@osazemeu
osazemeu / app.js
Created April 4, 2018 15:41 — forked from reichert621/app.js
Upload files to Amazon S3 with loopback, loopback-component-storage, angular, ng-file-upload
// bower dependency: "ng-file-upload"
// npm dependency: "loopback-component-storage"
'use strict';
angular
.module('app', [
'ngFileUpload'
])
.controller('UploadController', function(Upload) {
[1,2,3].map{|x| x.to_s}
[1,2,3].map(&:to_s)
Proc.new{|x| x.to_s}
def sym_to_proc(sym)
Proc.new{ |x| x.send(sym) }
end
sym_to_proc(:to_s).call(3)
:to_s.to_proc.call(3)
[1,2,3].map &->(n) { n.to_s }
@osazemeu
osazemeu / async.js
Created March 1, 2018 11:29 — forked from JedWatson/async.js
Example usage of async.map to update an array against a redis cache
// This function takes a contents object with a files array.
// The goal is to cache each file details in redis then replace
// the file's path with a secure, obscured url.
// Finally the contents object is returned with the updated array
// in place of the old one.
// async = require('async')
// uuid = require('node-uuid')
// redis.client = require('node-redis').createClient()