Skip to content

Instantly share code, notes, and snippets.

// pancakes are sorted if they are ordered from 1 to N
function isSorted(pancakes) {
return pancakes.every((p, i) => p === i + 1);
}
function flip(pancakes) {
const instructions = [''];
while (!isSorted(pancakes)) {
const maxUnsorted = pancakes.findLastIndex((p, i) => p !== i + 1) + 1;
const flipCount = pancakes.indexOf(maxUnsorted) + 1;
const exampleSignals =
'acedgfb cdfbe gcdfa fbcad dab cefabd cdfgeb eafb cagedb ab';
const charCount = {};
for (const char of exampleSignals
.split('')
.filter((char) => /[a-g]/.test(char))) {
charCount[char] = (charCount[char] ?? 0) + 1;
}
@leyanlo
leyanlo / webstorm-vs-vscode.md
Last active December 4, 2020 06:27
WebStorm vs VSCode

WebStorm vs VSCode

Tradeoffs

VSCode pros

  • Popular
  • MDX support
  • Can jump to files from console, e.g. when running eslint

VSCode cons

  • Cannot look at tab title and tell if file is new, modified, unstaged, or has errors
  • Cannot advance to next file in git view
@leyanlo
leyanlo / arrayDiff.js
Created November 30, 2020 08:21
cassidoo 11/29/2020
function arrayDiff(arr, target) {
const seen = {};
return arr.reduce((numPairs, n) => {
const targetsFromN = { [n + target]: null, [n - target]: null };
numPairs += Object.keys(targetsFromN).reduce(
(seenFromN, targetFromN) => seenFromN + (seen[targetFromN] || 0),
0
);
seen[n] = (seen[n] || 0) + 1;
return numPairs;
@leyanlo
leyanlo / babyLisp.js
Last active October 13, 2020 12:31
cassidoo 10/11/2020 O(n) solution with validation
// cassidoo 10/11/2020 O(n) solution with validation
// https://buttondown.email/cassidoo/archive/4b882f72-2fc1-4b77-b574-0118a37f480c
function getValue(operator, a, b) {
switch (operator) {
case "add":
return a + b;
case "subtract":
return a - b;
case "multiply":
@leyanlo
leyanlo / index.html
Last active February 17, 2020 05:59
momwordcloud.svg
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Mom’s 70th</title>
<style>
body {
display: flex;
flex-direction: column;
align-items: center;
@leyanlo
leyanlo / camelCase_to_snake_case.sh
Last active August 30, 2018 00:08
Script to convert camelCase filenames to snake_case
#!/bin/bash
# Recurse through subdirectories and convert camelCase filenames to snake_case
for file in */**/*.* ; do
mv "$file" "$(echo $file|gsed -e 's/\([A-Z]\)/_\1/g' -e 's/^.\/_//'|awk '{print tolower($0)}')"
done
@leyanlo
leyanlo / README.md
Last active February 2, 2018 08:43 — forked from quagliero/README.md
Installing cpuminer-multi on macOS 10.13.2 (High Sierra)

Installing cpuminer-multi on macOS 10.13.2 (High Sierra)

This assumes you have brew installed and are comfortable using a terminal.

Following the guide on https://github.com/tpruvot/cpuminer-multi will likely lead to errors about invalid paths to OpenSSL, and neoscrypt errors to the tune of Undefined symbols for architecture x86_64 during the build. I managed to piece together different fixes into an installation that has worked for me. So I hope it works for you.

Requirements

Ensure a c compiler is installed. Type g++ in the terminal and continue with the xcode installation if necessary. If it prints clang: error: no input files, then you can proceed.

Keybase proof

I hereby claim:

  • I am leyanlo on github.
  • I am leyanlo (https://keybase.io/leyanlo) on keybase.
  • I have a public key ASBdnEBzDJ--vDMLyxCy29JRMnh4nk86SOd-Pnyfa-kLygo

To claim this, I am signing this object:

@leyanlo
leyanlo / make-app.sh
Last active August 29, 2015 14:06 — forked from demonbane/makeapp.sh
#!/bin/sh
# Inspired by https://gist.github.com/demonbane/1065791
function pure_version() {
echo '0.1'
}
function version() {
echo "make-app $(pure_version)"
}