Skip to content

Instantly share code, notes, and snippets.

View httpJunkie's full-sized avatar
🏠
Working from home

Eric Bishard httpJunkie

🏠
Working from home
View GitHub Profile
@httpJunkie
httpJunkie / std-margin-and-padding-input.scss
Last active March 16, 2022 14:10
Standard margin and padding loop with Sass
$amounts: (5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 75, 100);
$sides: (top, right, bottom, left);
@each $space in $amounts {
@each $side in $sides {
.margin-#{$side}-#{$space} {
margin-#{$side}: #{$space}px !important;
}
.padding-#{$side}-#{$space} {
@httpJunkie
httpJunkie / index.html
Created March 25, 2018 09:04
JS Bin play-with-svg // source http://jsbin.com/veyesob
<!DOCTYPE html>
<html>
<head>
<meta name="description" content="play-with-svg">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<style>
#one { fill: #444; }
import React, { Component } from 'react';
class ComponentName extends Component {
render() {
return ("");
}
}
export default ComponentName
function debounce(func, wait, immediate) {
let timeOutSet = null;
//return function
return function() {
let args = arguments;
let futureCall = () => {
timeOutSet = null;
@httpJunkie
httpJunkie / shortestDistance.js
Created August 24, 2018 12:00
Shortest distance between two coordinates
function shortestDistance(str) {
str = str.split(',');
let xdist = str[0] - str[2]; // find dist betwen x coords
let ydist = str[1] - str[3]; // find dist between y coorsds
// then we want to square x and y distances multiplied by each other
// and add the result of each
let output = Math.sqrt((xdist * xdist) + (ydist * ydist));
// if output is not divisible by 1, let's set the decimal to two spaces.
@httpJunkie
httpJunkie / factorial.js
Created August 25, 2018 16:26
JavaScript Factorial using recursion
function factorial( n ) {
// the end of the road
if ( n === 1 ) {
return n;
}
// otherwise: we need to multiply our number that we want to find the factorial for
// by calling this same function with the number less than it and continuing that all
// the way down to one.
return n * factorial( n - 1 );
}
@httpJunkie
httpJunkie / reverse.js
Created August 25, 2018 16:33
JavaScript Recursion Reverse String
function reverseStr( str ) {
// if the string is only 1 character in length, we return that character
if ( str.length === 1 ) {
return str;
}
// otherwise we return the product of reverse passing in the second index item with the first index item after it
// this constant swapping out of the second item with the first item after it eventually reverses the entire string
return reverseStr( str.substr( 1 ) ) + str[ 0 ];
}
@httpJunkie
httpJunkie / fibonacci.js
Created August 25, 2018 16:50
JavaScript Recursive Fibonacci
function fibonacci(num) {
if (num <= 1) return 1;
// considering the number passed in, always return the product
// of the two numbers lesss than it added together.
return fibonacci(num - 1) + fibonacci(num - 2);
}
@httpJunkie
httpJunkie / fibonacci_memo.js
Last active August 25, 2018 16:58
JavaScript Recursive Fibonacci with Memoization
// solving the fibonacci problem with memoizaion
// bringin the time complexity back to 0(n) and constant where as
// the simple recursive way of doing it was O(2^N) with O(n) space comlexity
function fibonacciMem(num, memo = memo || {}) {
if (memo[num]) return memo[num];
if (num <= 1) return 1;
return memo[num] = fibonacciMem(num - 1, memo) + fibonacciMem(num - 2, memo);
}
@httpJunkie
httpJunkie / sum.js
Created August 30, 2018 11:02
Function which takes an array spread out as argument and returns the sum of all integers in the array.
let arrayOfIntegers = [1,2,3,4]
function sum() {
let add = (a, b) => { return a + b; }
return [].reduce.call(arguments, add);
}
console.log(sum(1,2,3,4));