Skip to content

Instantly share code, notes, and snippets.

View cozzbie's full-sized avatar
👻

Timi Aiyemo cozzbie

👻
View GitHub Profile
@cozzbie
cozzbie / treesize.js
Last active January 5, 2020 18:42
Get the total number of nodes in a tree
// Iterative
const size = (tree) => {
const axe = [tree];
let total = 0;
if(!tree){
return n;
}
while(axe.length) {
@cozzbie
cozzbie / bdelete.js
Last active January 5, 2020 18:40
Given a binary tree, delete a node from it by making sure that tree shrinks from the bottom.
const rightMost = tree => {
if(!tree.right){
return tree;
}
return rightMost(tree.right);
}
const deleteRmt = tree => {
if(!tree){
return;
@cozzbie
cozzbie / binsert.js
Created January 5, 2020 05:01
Given a binary tree and a key, insert the key into the binary tree at first position available
const insert = (tree, value) => {
const plug = [];
plug.push(tree);
while(plug.length){
const elem = plug.shift();
if(!elem.left) {
elem.left = node(value);
break;
const node = val => {
return {
data: val,
left: null,
right: null
};
}
const buildTree = () => {
const root = node(10);
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
/* Latitude/longitude spherical geodesy tools (c) Chris Veness 2002-2019 */
/* MIT Licence */
/* www.movable-type.co.uk/scripts/latlong.html */
/* www.movable-type.co.uk/scripts/geodesy-library.html#latlon-spherical */
/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
import Dms from './dms.js';
const π = Math.PI;
@cozzbie
cozzbie / introrx.md
Created October 18, 2019 08:56 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing
import { Directive, Input, HostBinding } from '@angular/core';
@Directive({
selector: 'img[appImageFallback]'
})
export class ImageFallbackDirective {
fallback = 'path/to/default/image.png';
@Input() src: string;
@cozzbie
cozzbie / gist:b82fc6fb8240f49e83ff006dd0ac316c
Created September 22, 2019 22:21 — forked from adeluccar/gist:d105299f2d5af55e3e96f9b989e7eb48
How to Flatten the History of a Git Repository Safely
git checkout --orphan future-master
git add -A  # Add all files and commit them
git commit
git branch -D master  # Deletes the master branch
git branch -m master  # Rename the current branch to master
git push -f origin master  # Force push master branch to github
git gc --aggressive --prune=all     # remove the old files
@cozzbie
cozzbie / media-query.css
Created July 25, 2019 11:28 — forked from gokulkrishh/media-query.css
CSS Media Queries for Desktop, Tablet, Mobile.
/*
##Device = Desktops
##Screen = 1281px to higher resolution desktops
*/
@media (min-width: 1281px) {
//CSS
## Installs for a new Mac
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew cask install google-chrome appcleaner hyper docker visual-studio-code keka google-backup-and-sync dropbox adware-removal-tool
brew cask install skype
brew install fish node python
## setup fish as default
sudo cat /usr/local/bin/fish >> /etc/shell