Skip to content

Instantly share code, notes, and snippets.

@petelacey
petelacey / one_drive.ex
Created February 24, 2024 23:02
Sample Elixir code to upload large documents to OneDrive via the MS Graph API
defmodule OneDrive
require Logger
@graph_api_url "https://graph.microsoft.com/v1.0/"
# The parent_drive_item is a Graph API driveItem object representing the root folder the file it to be uploaded to.
# There are many other representations left as an exercise to the reader
#
# The remote_file_path variable has the complete path to the file on the OneDrive side, e.g. /foo/bar/baz.txt
# If either the /foo or /bar folders are not already there, they will be created. They do not have to be created
@petelacey
petelacey / Dockerfile
Last active April 22, 2024 00:56
Docker Compose setup for Elixir, Phoenix, and Postgres
FROM elixir:latest
# Install debian packages
RUN apt-get update && \
apt-get install --yes build-essential inotify-tools postgresql-client git && \
apt-get clean
ADD . /app
# Install Phoenix packages
class HealthController < ApplicationController
def index
ActiveRecord::Base.connection.execute('select 1')
head :ok
rescue
head :bad_request
end
end
@petelacey
petelacey / beanstalk_nginx.conf
Last active April 9, 2019 13:45
Nginx always-on SSL config for ElasticBeanstalk
files:
"/etc/nginx/conf.d/000_APP_NAME.conf":
mode: "000755"
owner: root
group: root
content: |
upstream APP_NAME_app {
server unix:///var/run/puma/my_app.sock;
}
module CoreExtensions
module Array
module Enhancements
# a = [0, 1, 2, 3, 4]
# a.splice(2, 1, *[9, 8, 7])
# => [1, 2, 9, 8, 7, 4]
def splice(start, len, *replace)
self[start, len] = replace
self
end
mysql> create table bar ( c1 int not null );
Query OK, 0 rows affected (0.00 sec)
mysql> select table_name, engine from information_schema.tables where table_schema = 'spyder_development' and table_name = 'bar';
+------------+--------+
| table_name | engine |
+------------+--------+
| bar | InnoDB |
+------------+--------+
1 row in set (0.00 sec)
@petelacey
petelacey / gist:3848819
Created October 7, 2012 16:25
Testing a use case
require 'spec_helper_lite'
require 'sonian/use_cases/create_root_partner'
require 'sonian/use_cases/create_account'
require 'sonian/use_cases/create_user'
require 'sonian/persistence/memory_store'
module Sonian
describe CreateUser do
let(:gateway) { MemoryStore.new }
@petelacey
petelacey / gist:3848733
Created October 7, 2012 15:55
An Actual Use Case
require 'sonian/use_cases/password_encryption'
require 'sonian/values/user'
require 'active_support/core_ext/object/blank'
module Sonian
class CreateUser
def initialize(account_vo, data_store)
raise ArgumentError.new unless account_vo && data_store
@account = account_vo
@user_gateway = data_store.user_gateway
sudo rmmod r8192se_pci
sleep 2
# sudo modprobe r8192se_pci hwwep=0
sudo modprobe r8192se_pci
Account in the trial period should not be found in queries after the trial period expires (Not Yet Implemented)
./spec/models/account_spec.rb:1643
1)
'Account in general should have password expiration range 180 days by default' FAILED
expected: 180,
got: 0 (using ==)
./spec/models/account_spec.rb:59:
2)