This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-module(pattern_matching_practice). | |
-export([test/0]). | |
xOr(X,X) -> | |
false; | |
xOr(_,_) -> | |
true. | |
exclusive_or(X, Y) when X =/= Y -> true; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |