Skip to content

Instantly share code, notes, and snippets.

const timeConversion = (s) => {
const hours = s.slice(0, 2)
const meridiem = s.slice(-2)
switch (true) {
case hours === '12' && meridiem === 'AM':
return `00${s.slice(2, -2)}`
case meridiem === 'PM' && hours !== '12':
return `${Number(hours) + 12}${s.slice(2, -2)}`
case hours === '12' && meridiem === 'PM':
default:
@ryanpcmcquen
ryanpcmcquen / wallabagUrlDeduper.js
Last active October 16, 2018 05:56
Remove duplicate URLs from a JSON export of Wallabag. Write a text file containing only unique URLs.
const fs = require('fs')
const mkdirp = require('mkdirp')
const path = require('path')
const write = (filePath, code) => {
mkdirp.sync(path.dirname(filePath))
return new Promise((resolve, reject) => {
fs.writeFile(filePath, code, (err) => {
if (err) {
reject(err)
@ryanpcmcquen
ryanpcmcquen / gitlab-delete-all-repos.js
Last active October 15, 2018 05:57
Delete all GitLab repos (start fresh!).
const request = require('request')
const token = require('./.SECRET')
const user = ''
request(
`https://gitlab.com/api/v4/users/${user}/projects?private_token=${token}`,
(error, response, body) => {
JSON.parse(body)
.map((project) => project.id)
.forEach((projectId) => {
const birthdayCakeCandles = (ar) => {
const max = Math.max(...ar);
return ar.filter(i => i === max).length;
};
const miniMaxSum = (arr) => {
const arrLength = arr.length;
const arrSorted = arr.sort();
const sum = a => a.reduce((acc, val) => acc = acc + val);
const minSum = sum(arrSorted.slice(0, -1));
const maxSum = sum(arrSorted.slice(1));
console.log(minSum, maxSum);
};
const staircase = (n) => {
console.log(
Array(n)
.fill()
.map(
(ignore, index) => `${' '.repeat(n - (index + 1))}${'#'.repeat(index + 1)}`
)
.join('\n')
);
};
const plusMinus = (arr) => {
let arrLength = arr.length;
let positives = 0;
let negatives = 0;
let zeroes = 0;
arr.forEach(num => {
switch (true) {
case num > 0:
positives++;
break;
const diagonalDifference = (arr, n) => {
const sum = a => a.reduce((acc, val) => acc += val);
const getFirstDiagonal = (gridSize, a) =>
Array(gridSize).fill().map((ignore, index) => a[index][index]);
const getSecondDiagonal = (gridSize, a) =>
Array(gridSize).fill().map((ignore, index) => {
gridSize--;
return a[index][gridSize];
});
return (Math.abs(
def maxProfit(prices):
minPrice = 9223372036854775807
maxProfit = 0
maxPrice = 0
for price in prices:
if price < minPrice:
minPrice = price
elif price > maxPrice:
maxPrice = price
maxProfit = maxPrice - minPrice
@ryanpcmcquen
ryanpcmcquen / sltClearCache.html
Last active October 1, 2018 22:00
Clear cache for SLT.
<a href="javascript:rulesEngine.global.persistantState={};rulesEngine.global.sessionState={};localStorage.clear();sessionStorage.clear();location.reload(true);">
Clear cache (SLT)
</a>
<br><br>
^^ Drag that to your bookmark bar!