Instantly share code, notes, and snippets.

View Program.cs
using System;
using System.Net;
using System.Collections.Specialized;
using Newtonsoft.Json;
namespace SimpleSlackWebhook
{
public class Program
{
public static void Main(string[] args)
View Palindrome Chain Length.md

These are different solutions that I wrote for a problem that I was originally asked on an interview.

Recursive Solutions

Sequential Solutions

View pathsTo.js
function pathsTo(obj, fnTester, opt_limit, opt_searchLimit) {
opt_limit = +opt_limit || Infinity;
opt_searchLimit = ~~opt_searchLimit > 0 ? ~~opt_searchLimit : 1e5;
for (
var path, k, i, v, typeOfV,
objIndex = 0,
objs = [obj],
objsCount = 1,
paths = [[]],
View guessNumber.js
function guessNumber(maxNumber) {
var maxAttempts = Math.floor(Math.log(maxNumber) / Math.log(2)) + 1;
var answer = Math.floor(Math.random() * maxNumber) + 1;
var guess = '';
var guesses = [];
var message = '';
for (var attempts = 1; attempts <= maxAttempts; attempts = attempts + 1) {
guess = prompt(message + 'Enter a number between 1 and ' + maxNumber + ':', guess);
if (guess == undefined) {
View recursive-employees-with-subordinates.postgres.sql
WITH RECURSIVE subordinates AS ( -- CTE for employees with chain of command
WITH employees AS ( -- CTE for example employees
SELECT 1 AS id, 'Davy Crockett' AS full_name, NULL AS manager_id
UNION SELECT 2 AS id, 'Cindy Cruz' AS full_name, 1 AS manager_id
UNION SELECT 3 AS id, 'Harry Thompson' AS full_name, 1 AS manager_id
UNION SELECT 4 AS id, 'George Jefferson' AS full_name, 2 AS manager_id
UNION SELECT 5 AS id, 'Blinky Bill' AS full_name, 2 AS manager_id
UNION SELECT 6 AS id, 'Linda Vernsky' AS full_name, 1 AS manager_id
UNION SELECT 7 AS id, 'Abigail Quispe' AS full_name, 1 AS manager_id
UNION SELECT 8 AS id, 'Jessica Ericson' AS full_name, 7 AS manager_id
View recursive-cte-example.postgres.sql
WITH RECURSIVE subordinates AS ( -- CTE for employees with chain of command
WITH employees AS ( -- CTE for example employees
SELECT 1 AS id, 'Davy Crockett' AS full_name, NULL AS manager_id
UNION SELECT 2 AS id, 'Cindy Cruz' AS full_name, 1 AS manager_id
UNION SELECT 3 AS id, 'Harry Thompson' AS full_name, 1 AS manager_id
UNION SELECT 4 AS id, 'George Jefferson' AS full_name, 2 AS manager_id
UNION SELECT 5 AS id, 'Blinky Bill' AS full_name, 2 AS manager_id
UNION SELECT 6 AS id, 'Linda Vernsky' AS full_name, 1 AS manager_id
UNION SELECT 7 AS id, 'Abigail Quispe' AS full_name, 1 AS manager_id
UNION SELECT 8 AS id, 'Jessica Ericson' AS full_name, 7 AS manager_id
View mimic.js
function mimic(obj, opt_filter, opt_maxPathLength) {
function recurse(obj, ancestors, path) {
ancestors = ancestors.concat([obj]);
if (path.length > opt_maxPathLength) {
var e = new Error('Maximum path length exceeded.');
e.path = path;
e.root = obj;
throw e;
}
View swapProps.js
/**
* Swaps the specified properties between the target object and the source object.
* @param {*} target
* Target object from which the specified properties will be swapped.
* @param {*} source
* Source object from which the specified properties will be swapped.
* @param {Array<number|string>} keys
* Array of keys for the properties that should be swapped between source and
* target.
* @param {boolean=} [opt_dontDelete=false]
View getVideoImages.js
/**
* Gets one or more images from a video at the given times. Works for MP4s and
* at times MKVs.
* @param {string} path
* URL path to the video.
* @param {Array.<number|Function>|number|Function} times
* If a function it will be passed the duration and the return value will be
* used as the amount of seconds at which to grab the image. If a
* non-negative number this will be used as the amount of seconds at which
* to grab the image. If a negative number this will be used as the amount
View 4-corner-css3-gradient.html
<html>
<head>
<style>
.test {
background-image:
linear-gradient(315deg, hsl(0, 100%, 50%), rgba(255,255,255,0) 50%),
linear-gradient(45deg, hsl(90, 100%, 50%), rgba(255,255,255,0) 50%),
linear-gradient(135deg, hsl(180, 100%, 50%), rgba(255,255,255,0) 50%),
linear-gradient(225deg, hsl(270, 100%, 50%), rgba(255,255,255,0) 50%);
background-color: #808080;