Skip to content

Instantly share code, notes, and snippets.

View EcutDavid's full-sized avatar
📚

David Guan EcutDavid

📚
View GitHub Profile
quickSort :: (Ord a) => [a] -> [a]
quickSort [] = []
quickSort [x] = [x]
quickSort (x:arrLeft) = smallerOnes ++ [x] ++ largerOnes
where smallerOnes = quickSort [ele | ele <- arrLeft, ele <= x]
largerOnes = quickSort [ele | ele <- arrLeft, ele > x]
mergeSort :: (Ord a) => [a] -> [a]
mergeSort [] = []
mergeSort [x] = [x]
mergeSort arr = merge(firHalfArr, secHalfArr)
where arrHalfLength = div (length arr) 2
firHalfArr = mergeSort (take arrHalfLength arr)
secHalfArr = mergeSort (drop arrHalfLength arr)
merge (a, []) = a
merge ([], b) = b
merge ((a1:aLeft), (b1:bLeft))
function solveTopDown(n, memo) {
if (memo[n]) return memo[n];
const result = solveTopDown(n - 1, memo) + solveTopDown(n - 2, memo);
memo[n] = result;
return result;
}
function topDown(n) {
return solveTopDown(n, { 1: 1, 2: 1 });
}
const textFromInternet = 'In computer science, mathematics, management science, economics and bioinformatics, dynamic programming (also known as dynamic optimization) is a method for solving a complex problem by breaking it down into a collection of simpler subproblems, solving each of those subproblems just once, and storing their solutions. The next time the same subproblem occurs, instead of recomputing its solution, one simply looks up the previously computed solution, thereby saving computation time at the expense of (it is hoped) a modest expenditure in storage space. (Each of the subproblem solutions is indexed in some way, typically based on the values of its input parameters, so as to facilitate its lookup.) The technique of storing solutions to subproblems instead of recomputing them is called "memoization".';
const LINE_LENGTH = 90;
function calcBadness(line) {
const diff = LINE_LENGTH - line.length;
if (diff >= 0) {
return Math.pow((LINE_LENGTH - line.length), 2);
}
return Number.MAX_
const edgesExample = [
[1, 4, 3], [1, 3, 6],
[2, 1, 3],
[3, 4, 2],
[4, 3, 1], [4, 2, 1],
[5, 2, 4], [5, 4, 2],
];
function dp(start, edges) {
const memo = {};
@EcutDavid
EcutDavid / bookmark.js
Last active November 9, 2018 10:33
Download Codeforces test cases
var inputs = document.querySelectorAll(".input pre");
for (var i = 0; i < inputs.length; i++) {
var s = inputs[i].innerHTML;
s = s.replace(/<br>/g, "\n");
console.log(s)
// decode html entities
var div = document.createElement("div");
div.innerHTML = s;
// Parsing a graph from the input, then, dfs to walk through the map.
package main
import (
"fmt"
)
var (
braceOpenASC = "("[0]
braceCloseASC = ")"[0]
@EcutDavid
EcutDavid / ui.js
Last active September 3, 2019 02:55
build-kite-stuff
// Retry the first time time-out
document.querySelectorAll('.build-details-pipeline-job-state-timed_out, .build-details-pipeline-job-state-failed').forEach(d => {
d.querySelector('i').click();
d.querySelector('a[href$=retry]').click();
});
const AWS = require("aws-sdk");
const polly = new AWS.Polly();
const bucketName = "polly-voice-notes";
const pollyCommonParas = {
OutputFormat: "mp3",
VoiceId: "Matthew",
OutputS3BucketName: bucketName
};
const path = require("path");
const AWS = require("aws-sdk");
const fs = require("fs");
const fsPromises = fs.promises;
const polly = new AWS.Polly();
const s3 = new AWS.S3();
const bucketName = "polly-voice-notes";
const notesDir = "notes";
const manifestFileKey = 'manifest.json';