Skip to content

Instantly share code, notes, and snippets.

View orestch's full-sized avatar

Orest Ch orestch

View GitHub Profile
@orestch
orestch / _spacing-helpers.scss
Created October 24, 2018 14:22 — forked from jacurtis/_spacing-helpers.scss
SASS Margin and Padding Helpers Loop. Generates .m-t-10 type helper classes.
/*
This .scss loop will create "margin helpers" and "padding helpers" for use in your web projects.
It will generate several classes such as:
.m-r-10 which gives margin-right 10 pixels.
.m-r-15 gives MARGIN to the RIGHT 15 pixels.
.m-t-15 gives MARGIN to the TOP 15 pixels and so on.
.p-b-5 gives PADDING to the BOTTOM of 5 pixels
.p-l-40 gives PADDING to the LEFT of 40 pixels
@orestch
orestch / difference.js
Created October 2, 2018 07:21 — forked from Yimiprod/difference.js
Deep diff between two object, using lodash
/**
* Deep diff between two object, using lodash
* @param {Object} object Object compared
* @param {Object} base Object to compare with
* @return {Object} Return a new object who represent the diff
*/
function difference(object, base) {
function changes(object, base) {
return _.transform(object, function(result, value, key) {
if (!_.isEqual(value, base[key])) {
@orestch
orestch / squirt.js
Created June 13, 2018 11:31 — forked from joelpt/squirt.js
Manually calculate the square root of a number with Javascript
// The Babylonian Method
// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots#Babylonian_method
// @param n - the number to compute the square root of
// @param g - the best guess so far (can omit from initial call)
function squirt(n, g) {
if (!g) {
// Take an initial guess at the square root
g = n / 2.0;
}
var d = n / g; // Divide our guess into the number
@orestch
orestch / es7-async-await.js
Created April 26, 2018 07:24
Javascript fetch JSON with ES7 Async Await
// Async/Await requirements: Latest Chrome/FF browser or Babel: https://babeljs.io/docs/plugins/transform-async-to-generator/
// Fetch requirements: Latest Chrome/FF browser or Github fetch polyfill: https://github.com/github/fetch
// async function
async function fetchAsync () {
// await response of fetch call
let response = await fetch('https://api.github.com');
// only proceed once promise is resolved
let data = await response.json();
// only proceed once second promise is resolved
@orestch
orestch / javascript-es6-design-patterns.js
Last active June 16, 2021 05:34
javaScript ES6 Design Patterns
/*
* Singleton Pattern
*/
let Singleton = (function() {
let instance = null;
class Singleton {
constructor() {
if (!instance) {
@orestch
orestch / javascript-recursion-factorial.js
Created November 23, 2016 17:41
javaScript Recursion Factorial
function factorial(n) {
if(n <= 1) {
return 1;
}
return factorial(n - 1) * n;
}
console.log(factorial(5));
@orestch
orestch / javascript-closures.js
Created November 23, 2016 17:36
javaScript Closures
// The following example shows nested functions:
function addSquares(a,b) {
function square(x) {
return x * x;
}
return square(a) + square(b);
}
a = addSquares(2,3); // returns 13
b = addSquares(3,4); // returns 25
c = addSquares(4,5); // returns 41
@orestch
orestch / javascript-recursive-dom-tree.html
Created November 23, 2016 17:31
javaScript Recursive DOM Tree
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>javaScript Recursive DOM Tree</title>
</head>
<body>
<div id="test">
<ul>
<li></li>
@orestch
orestch / javascript-ajax-load-xml.html
Created November 23, 2016 17:19
javaScript Ajax Load XML Data
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Javascript Ajax</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
</head>
<body>
<div class="container">