Skip to content

Instantly share code, notes, and snippets.

CharmedSatyr / request-mastodon-oauth.js
Last active Jul 22, 2019
A function to retrieve a Mastodon user's profile using the `request` HTTP client
View request-mastodon-oauth.js
// routes/oauth/mastodon.js
const request = require('request');
const authorize = (req) => {
// The authorization code returned from Mastodon on a successful login
const { code } = req.query;
console.log('(1) AUTHORIZATION CODE:', code);
// Token endpoint
CharmedSatyr / mastodon-auth0.js
Last active Jul 19, 2019
Mastodon Social extension for Auth0
View mastodon-auth0.js
function(accessToken, ctx, cb) {
'https://[MASTODON INSTANCE URL]/api/v1/accounts/verify_credentials', {
headers: {
'Authorization': `Bearer ${accessToken}`
function(err, res, body) {
if (err) {
return cb(err);
CharmedSatyr / caesars-cipher.js
Created Jul 5, 2019
freeCodeCamp JavaScript Algorithms and Data Structures Projects
View caesars-cipher.js
function rot13(str) {
//translate each letter of the string into unicode and push them to an array
var uniArr = [];
for (j = 0; j < str.length; j++) {
//add or subtract 13 letters or do nothing, depending on where the initial value falls in the ISO Latin-1 table
CharmedSatyr / index.html
Last active Aug 1, 2018
Interview Question// JS Bin// source
View index.html
<!DOCTYPE html>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
<script id="jsbin-javascript">
CharmedSatyr / fibonacci_number.js
Last active Aug 1, 2018
Fibonacci Number Finder algorithms, one recursive and one iterative, implemented in JavaScript
View fibonacci_number.js
// Fibonacci Number
// Objective: Find the n-Fibonacci number,
// the nth term of the Fibonacci Sequence,
// often denoted by F(n)
// For example, given the Fibonacci Sequence:
// 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377...
// F(8) = 21
// F(20) = 6765
CharmedSatyr / merge_sort.js
Last active Aug 1, 2018
Merge Sort implemented in JavaScript
View merge_sort.js
/* Like quick sort, merge sort also uses a divide-and-conquer,
* recursive methodology to sort an array. It takes advantage
* of the fact that it is relatively easy to merge two arrays
* in sorted order as long as each is sorted in the first place.
* 1) Recursively split the input array in half until a sub-array
* with only one element is produced.
* 2) Merge each sorted sub-array together to produce the final
* sorted array.
CharmedSatyr / quick_sort.js
Last active Aug 1, 2018
Quick Sort implemented in JavaScript
View quick_sort.js
/* Quick sort is an efficient, recursive divide-and-conquer
* approach to sorting an array. In this method, a pivot value
* is chosen in the original array. The array is then
* partitioned into two subarrays of values less than and
* greater than the pivot value. We then combine the result of
* recursively calling the quick sort algorithm on both
* sub-arrays. This continues until the base case of an empty
* or single-item array is reached, which we return. The
* unwinding of the recursive calls return us the sorted array.
CharmedSatyr / selection_sort.js
Last active Aug 1, 2018
Selection Sort implemented in JavaScript (2 methods)
View selection_sort.js
/* Selection sort works by selecting the minimum value in a list
* and swapping it with the first value in the list. It then
* starts at the second position, selects the smallest value in
* the remaining list, and swaps it with the second element. It
* continues iterating through the list and swapping elements
* until it reaches the end of the list.
// METHOD 1: Using 2 `for` loops (ES5)
function selectionSort(array) {
CharmedSatyr / bubble_sort.js
Last active Aug 1, 2018
Bubble Sort implemented in JavaScript
View bubble_sort.js
/* The bubble sort method starts at the beginning of
* an unsorted array and 'bubbles up' unsorted values
* towards the end, iterating through the array until
* it is completely sorted. It does this by comparing
* adjacent items and swapping them if they are out
* of order. The method continues looping through the
* array until no swaps occur, at which point the
* array is sorted.
CharmedSatyr / insertion_sort.js
Last active Aug 1, 2018
Insertion Sort implemented in JavaScript
View insertion_sort.js
/* This method works by building up a sorted array at the beginning of
* the list. It begins the sorted array with the first element. Then it
* inspects the next element and swaps it backwards into the sorted
* array until it is in sorted position. It continues iterating through
* the list and swapping new items backwards into the sorted portion
* until it reaches the end.
'use strict';
// insert - puts a number in the right spot in an array in ascending order