Skip to content

Instantly share code, notes, and snippets.

Avatar
🦈
Building something cool

Corbin Crutchley crutchcorn

🦈
Building something cool
View GitHub Profile
View GoLangNotes
- Does not support nested functions
- Must use variable/lambda assignment:
```go
func main() {
test := func() {
println("Hello")
}
test()
@crutchcorn
crutchcorn / vscode-settings.sh
Created May 16, 2020
My settings for VSCode
View vscode-settings.sh
# I use a community "Material Palenight" theme. I've found it has a color pallete I like a lot more for code:
# https://marketplace.visualstudio.com/items?itemName=whizkydee.material-palenight-theme
# I also use the "Material Design Icons Palenight"
# https://marketplace.visualstudio.com/items?itemName=Equinusocio.vsc-material-theme-icons
# I use a lot of extensions. Here's a list of all of them:
code --install-extension Angular.ng-template
code --install-extension attilabuti.vscode-mjml
code --install-extension auchenberg.vscode-browser-preview
code --install-extension christian-kohler.npm-intellisense
@crutchcorn
crutchcorn / promise.all.js
Last active Apr 9, 2020
An explanation of Promise.all that includes mention of mapping through them
View promise.all.js
// This is a simple promise that will return a promise that resolves after the num
const getPromiseTimeout = num => new Promise(resolve => {
setTimeout(() => resolve(num), num);
})
const timeouts = [getPromiseTimeout(100), getPromiseTimeout(300), getPromiseTimeout(200)];
// Promise.all will run these promises in whatever order it wants, but will resolve
// with the same order they were passed in on. They run in 'parallel'
// Will console.log(100, 300, 200) in the same order as the order above
View arrayFrom.js
// Say you have an Iterable that you want to turn into an array
const map = new Map()
map.set('a', 1);
map.set('b', 2);
// Array.from has you covered!
const twoDArr = Array.from(map); // [['a', 1], ['b', 2]]
// Not only can Array.from handle Maps, it can create brand new arrays
const emptyArr = Array.from({length: 3}); // [blank, blank, blank];
@crutchcorn
crutchcorn / gist:3c33a9ced8c0cb6d31fa14bde14e0fbf
Created Mar 14, 2020
This is how I remove duplicate tracks in my music library
View gist:3c33a9ced8c0cb6d31fa14bde14e0fbf
const mm = require('music-metadata');
const fs = require('fs');
const files = fs.readFileSync('../New\ playlist.m3u').toString().split("\r\n");
let songs;
songsP = Promise.all(files.map(file =>mm.parseFile(file).then(v => ({...v, fileName: file})).catch(a => null)))
songsP.then(val => songs = val)
// make sure there are really duplicates in the list
songs = songs.filter(song => !!song).filter(song => song && songs.find(sonn => (song.common.title == sonn.common.title) && (song.fileName != sonn.fileName)))
View rebuilt-arr-prototypes.js
Array.prototype.filter = function (callback) {
const arr = this;
const returnedVal = [];
for (const i = 0; i < arr.length; i++) {
const exist = callback(arr[i], i, arr);
if (exist) {
returnedVal.push(arr[i]);
}
}
@crutchcorn
crutchcorn / nerd-snipe.js
Created Jan 29, 2020
I got distracted during writing some code for a talk slide
View nerd-snipe.js
const state = { test: 3, hello: 399, testinghhhh: 1 };
const stateWords = Object.keys(state);
const stateNumbers = Object.values(state);
const itemStr = 'Item';
const countStr = 'Count';
let longestWord = itemStr.length;
let longestNumber = countStr.length;
View learnMeAHaskellNotes.md
Haskell TypeScript Notes
2 /= 2 2 != 2
conanO'Brien = "It's a-me, Conan O'Brien!" const conanOBrien = "It's a-me, Conan O'Brien!" Called definitions or names in Haskell when fn has no params. Interchangable with the primitive value
doubleUs x y = doubleMe x + doubleMe y const doubleUs(x, y) => doubleMe(x) + doubleMe(y)
`doubleSmallNumber x = if x > 100 the
View helpful-regexes.md

Optional Chaining

\b([.a-zA-Z]+)\s+?&&\s+?\1\.

This should find instances such as:

test && test.thing

View challenge.md

Given an array of integers 0-9 inclusive, compute the max sum of k elements in the array. Where the length of the array > 0 and k is 0 < k <= length array Example: array ar is ar = [3, 2, 4, 5, 1, 0, 9, 8, 8, 7], and k is k = 3. Should return 25. finish this function (this is python, but you can use any language):

def compute_max_k(ar, k):
    return
You can’t perform that action at this time.