Skip to content

Instantly share code, notes, and snippets.

@osazemeu
osazemeu / assignment.rb
Created June 14, 2019 11:51
assignment
Write a function that takes three arguments, 2 arrays (a and b) and 1 integer (c) then returns one array (d) which is created by inserting all elements in b into a at indexes which are spaced by the integer value.
Consider all possible corner cases.
e.g
a = ["a", "b", "c", "d", "e", "f"]
b = ["1", "2", "3"]
c = 2
d = ["a", "b", "1", "c", "d", "2", "e", "f", "3"]
@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 / wp.sh
Created April 3, 2019 14:59 — forked from robertogalan/wp.sh
Shell script to install apache/mysql/php/wordpress into an EC2 instance of Amazon AMI Linux.
#! /bin/bash
# Shell script to install apache/mysql/php/wordpress into an EC2 instance of Amazon AMI Linux.
# Step 1: Create an AWS EC2 instance
# Step 2: ssh in like: ssh -v -i wordpress.pem ec2-user@ec2-54-185-74-0.us-west-2.compute.amazonaws.com
# Step 3: Run this as root/superuser, do sudo su
echo "Shell script to install apache/mysql/php/wordpress into an EC2 instance of Amazon AMI Linux."
echo "Please run as root, if you're not, choose N now and enter 'sudo su' before running the script."
echo "Run script? (y/n)"
@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 / heaps_and_stacks.js
Last active May 23, 2018 12:07
JS Heaps and Stacks
//Javascript stack linked list data structure (no array)
function node(value, noderef) {
this.value = value;
this.next = noderef;
}
function stack() {
this.push = function (value) {
this.next = this.first;
this.first = new node(value, this.next);
@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()
@osazemeu
osazemeu / deploy.sh
Created January 29, 2018 14:46 — forked from tokudu/deploy.sh
A simple deployment script for EC2 instances
#!/bin/bash
# Updates all EC2 instances from git
# Author: anton@sothree.com
CODE_LOCATION=/var/www/your_project
SERVER_PREFIX=your_project
# exit if something fails
set -e