Skip to content

Instantly share code, notes, and snippets.

View crutchcorn's full-sized avatar
📒
Writing like whoa

Corbin Crutchley crutchcorn

📒
Writing like whoa
View GitHub Profile
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
Array.prototype.sayHello = () => console.log('Hi there!')
[].sayHello()
[1, 2, 3, 4, 5].sayHello()

And if you really want a negative stance on your code review

Array.prototype.peteAndRepeat = function(){this.forEach(val => console.log(`Pete says ${val}`))}
@crutchcorn
crutchcorn / nerd-snipe.js
Created January 29, 2020 00:45
I got distracted during writing some code for a talk slide
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;
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 / gist:3c33a9ced8c0cb6d31fa14bde14e0fbf
Created March 14, 2020 07:47
This is how I remove duplicate tracks in my music library
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)))
// 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 / promise.all.js
Last active April 9, 2020 00:41
An explanation of Promise.all that includes mention of mapping through them
// 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
@crutchcorn
crutchcorn / vscode-settings.sh
Created May 16, 2020 19:52
My settings for VSCode
# 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
  • Does not support nested functions
    • Must use variable/lambda assignment:
func main() {
	test := func() {
		println("Hello")
	}

	test()