Skip to content

Instantly share code, notes, and snippets.

Ryan Trontz tr00gle

View GitHub Profile
View pattern_matching_trontz.erl
-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 Aug 23, 2019
auth gen server
View auth.ex
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
View usingReduceClosure.js
// 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,
View usingReduce1.js
// 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 Jun 21, 2018 — forked from charlesdaniel/basic_auth_nodejs_test.js
Example of HTTP Basic Auth in NodeJS
View basic_auth_nodejs_test.js
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);
You can’t perform that action at this time.