Skip to content

Instantly share code, notes, and snippets.

Avatar
👻

Timi Aiyemo cozzbie

👻
View GitHub Profile
@cozzbie
cozzbie / .bashrc
Created Feb 8, 2021 — forked from vsouza/.bashrc
Golang setup in Mac OSX with HomeBrew. Set `GOPATH` and `GOROOT` variables in zshell, fish or bash.
View .bashrc
# Set variables in .bashrc file
# don't forget to change your path correctly!
export GOPATH=$HOME/golang
export GOROOT=/usr/local/opt/go/libexec
export PATH=$PATH:$GOPATH/bin
export PATH=$PATH:$GOROOT/bin
View gist:59ffba00cb913623ba7febbfef177853
# Install golang with homebrew
brew install go --cross-compile-common
# Set following env variables in ~/.bashrc or ~/.zshrc
export GOPATH=$HOME/go
export GOROOT=/usr/local/opt/go/libexec
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
export PATH=$PATH:$GOROOT/bin
View autoplay.js
const body = document.querySelector('body');
const iframe = document.createElement('iframe');
iframe.src = `<link to sound>`;
iframe.allow = 'autoplay';
iframe.style.cssText = `display: none`;
body.appendChild(iframe);
// Definitly a better thing to do this is to have listeners
// on your sound instance.
setTimeout(() => {
@cozzbie
cozzbie / composing-software.md
Created Mar 7, 2020 — forked from Geoff-Ford/composing-software.md
Eric Elliott's Composing Software Series
View composing-software.md

Eric Elliott's "Composing Software" Series

A collection of links to the excellent "Composing Software" series of medium stories by Eric Elliott.

Edit: I see that each post in the series now has index, previous and next links. However, they don't follow a linear flow through all the articles with some pointing back to previous posts effectively locking you in a loop.

View countingsort.js
const countsort = (array, k) => {
const frequency = [...Array(k + 1).keys()].map(k => 0);
const out = [];
for(let j in array){
frequency[array[j]] = frequency[array[j]] + 1;
}
for(let i = 1; i < frequency.length; i++){
frequency[i] = frequency[i] + frequency[i - 1];
View quicksort.js
// https://en.wikipedia.org/wiki/Quicksort
// Divide and Conquer type.
// Worst Case (Rare): O(n**2)
// Typical: O(NlogN)
const swap = (array, x, y) => {
array[x] = [array[y], array[y] = array[x]][0];
};
const partition = (array, p, r) => {
View heapsort.js
const swap = (array, a, b) => {
let tempa = array[a];
array[a] = array[b];
array[b] = tempa;
}
const maxheap = (array, index) => {
const parenty = i => Math.ceil(i/2);
const lefty = i => 2*i;
const righty = i => 2*i + 1;
@cozzbie
cozzbie / insertsort.js
Created Jan 5, 2020
In-place insert sort.
View insertsort.js
const insertSort = array => {
for(let i = 1; i < array.length; i++) {
const el = array[i];
let j = i - 1;
while(j >= 0 && el < array[j]){
array[i--] = array[j];
array[j] = el;
j--;
}
@cozzbie
cozzbie / treesize.js
Last active Jan 5, 2020
Get the total number of nodes in a tree
View treesize.js
// Iterative
const size = (tree) => {
const axe = [tree];
let total = 0;
if(!tree){
return n;
}
while(axe.length) {
@cozzbie
cozzbie / bdelete.js
Last active Jan 5, 2020
Given a binary tree, delete a node from it by making sure that tree shrinks from the bottom.
View bdelete.js
const rightMost = tree => {
if(!tree.right){
return tree;
}
return rightMost(tree.right);
}
const deleteRmt = tree => {
if(!tree){
return;