Skip to content

Instantly share code, notes, and snippets.

@CharmedSatyr
CharmedSatyr / request-mastodon-oauth.js
Last active July 22, 2019 06:07
A function to retrieve a Mastodon user's profile using the `request` HTTP client
// 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
CharmedSatyr / mastodon-auth0.js
Last active July 19, 2019 16:09
Mastodon Social extension for Auth0
function(accessToken, ctx, cb) {
request.get(
'https://[MASTODON INSTANCE URL]/api/v1/accounts/verify_credentials', {
headers: {
'Authorization': `Bearer ${accessToken}`
}
},
function(err, res, body) {
if (err) {
return cb(err);
@CharmedSatyr
CharmedSatyr / caesars-cipher.js
Created July 5, 2019 02:09
freeCodeCamp JavaScript Algorithms and Data Structures Projects
function rot13(str) {
// LBH QVQ VG!
//translate each letter of the string into unicode and push them to an array
var uniArr = [];
for (j = 0; j < str.length; j++) {
uniArr.push(str.charCodeAt(j));
}
//add or subtract 13 letters or do nothing, depending on where the initial value falls in the ISO Latin-1 table
### Keybase proof
I hereby claim:
* I am charmedsatyr on github.
* I am charmedsatyr (https://keybase.io/charmedsatyr) on keybase.
* I have a public key ASAlfvhXnBEtxQECzQFYUMWRhL0wUBV1pvNmsRA9UXuMiAo
To claim this, I am signing this object:
@CharmedSatyr
CharmedSatyr / index.html
Last active August 1, 2018 15:01
Interview Question// JS Bin// source https://jsbin.com/wurebac
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script id="jsbin-javascript">
@CharmedSatyr
CharmedSatyr / insertion_sort.js
Last active August 1, 2018 04:14
Insertion Sort implemented in JavaScript
/* 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
@CharmedSatyr
CharmedSatyr / bubble_sort.js
Last active August 1, 2018 04:10
Bubble Sort implemented in JavaScript
/* 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
CharmedSatyr / selection_sort.js
Last active August 1, 2018 04:06
Selection Sort implemented in JavaScript (2 methods)
/* 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
CharmedSatyr / quick_sort.js
Last active August 1, 2018 03:57
Quick Sort implemented in JavaScript
/* 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
CharmedSatyr / merge_sort.js
Last active August 1, 2018 03:45
Merge Sort implemented in JavaScript
/* 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.
*/