Skip to content

Instantly share code, notes, and snippets.

View tr00gle's full-sized avatar

Ryan Trontz tr00gle

View GitHub Profile
-module(pattern_matching_practice).
-export([test/0]).
xOr(X,X) ->
false;
xOr(_,_) ->
true.
exclusive_or(X, Y) when X =/= Y -> true;
@tr00gle
tr00gle / auth.ex
Created August 23, 2019 23:48
auth gen server
defmodule TransactionalMessagingService.Providers.Cheetah.Auth do
@moduledoc """
GenServer to handle all Cheetah auth token related functionality
All requests to Cheetah require using a valid auth token in the request
header, the tokens also expire after a certain time (currently 8 hours).
Setup a GenServer to keep a active token in its state and manage retrieval
of a new token when needed.
This is accomplished by storing the token value and the calculated expiration
// More advanced application using closures and pure functions
const randomNum = n => Math.floor(Math.random() * n);
const fillRandomArray = (len, range) => Array.from({length: len}, () => randomNum(range))
const sorterCreator = (length, ceiling) => {
const buckets = {
low: 0,
mid: 0,
// a meaningful use of reducing an array to an object
//steps:
// 1. use function to generate random ints in [0,n); we'll be using 1500 here.
// 2. use another function to create an array of given length filled random ints in
// given range
// 3. declare an object to divide numbers into low, mid, and high buckets
// 4. reduce the array of random integers into the sorting object
// using either anonymous or named callback
@tr00gle
tr00gle / basic_auth_nodejs_test.js
Created June 21, 2018 18:27 — forked from charlesdaniel/basic_auth_nodejs_test.js
Example of HTTP Basic Auth in NodeJS
var http = require('http');
var server = http.createServer(function(req, res) {
// console.log(req); // debug dump the request
// If they pass in a basic auth credential it'll be in a header called "Authorization" (note NodeJS lowercases the names of headers in its request object)
var auth = req.headers['authorization']; // auth is in base64(username:password) so we need to decode the base64
console.log("Authorization Header is: ", auth);