Skip to content

Instantly share code, notes, and snippets.

// Class for creating multi inheritance.
class multi {
// Inherit method to create base classes.
static inherit(..._bases) {
class classes {
// The base classes
get base() {
return _bases;
}
@et4891
et4891 / getProperty.js
Created December 10, 2018 20:14
Get nested object property using dot notation
/*
* Get nested object property using dot notation
* */
const getProperty = ( propertyName, object ) => {
let parts = propertyName.split( "." ),
length = parts.length,
i,
property = object || this;
@et4891
et4891 / setNested.js
Created December 10, 2018 20:13
Set nested object properties using dot notation with value
/*
* Set nested object properties using dot notation with value
* */
const setNested = (obj, path, val) => {
const keys = path.split('.');
const lastKey = keys.pop();
const lastObj = keys.reduce((obj, key) =>
obj[key] = obj[key] || {},
obj);
@et4891
et4891 / returnObj.js
Created December 7, 2018 01:17
return only the fields needed in the array of object by stating the fields need in return
/*
* return obj with the field, used in mostly map()
* @param x {Object}
* @param fields {Array}
* @returns {Object[]}
*
* Sample Usage
* const returnFields = ['amount', 'created', 'status'];
* ArrayObjects.map(x => returnObj(x, returnFields));
*
@et4891
et4891 / circle-time.py
Last active August 19, 2018 03:37
Python comes with a timeit module specifically designed for benchmarking snippets of code
# just an example of how the `timeit` works
# below is an example of class attribute vs method parameter performance
class CircleTime():
def __init__(self, radius=1):
self.pi = 3.14
self.radius = 1
# use class attribute pi
def get_circum_self(self):
@et4891
et4891 / hide.js
Created October 15, 2016 21:33
Anywhere other than the form itself is clicked, the form will hide
$(document).mouseup(function(e){
var _con = $('.signUp-LogIn-form');
if(!_con.is(e.target) && _con.has(e.target).length === 0){
$('.signUp-LogIn-form').hide();
}
});
@et4891
et4891 / dup.js
Created May 29, 2016 01:54
Input two lists (using comma to separate the list) and compare 1st and 2nd list. Outputs any duplicates / not duplicates of 1st from 2nd
$(function(){
/*
Inputs need a comma in between each value don't put quotations (line break is allowed)
Example inputs
A,
B,
C
*/
//When submit
@et4891
et4891 / getAllElementsWithAttribute.js
Created April 4, 2016 08:40
getAllElementsWithAttribute
function getAllElementsWithAttribute(attribute)
{
var matchingElements = [];
var allElements = document.getElementsByTagName('*');
for (var i = 0, n = allElements.length; i < n; i++)
{
if (allElements[i].getAttribute(attribute) !== null)
{
// Element exists with attribute. Add to array.
matchingElements.push(allElements[i]);
@et4891
et4891 / getUrlVariables.js
Created June 15, 2015 00:49
Get URL Variables
function getQueryVariable(variable)
{
var query = window.location.search.substring(1);
var vars = query.split("&");
for (var i=0;i<vars.length;i++) {
var pair = vars[i].split("=");
if(pair[0] == variable){return pair[1];}
}
return(false);
}
@et4891
et4891 / Preferences.sublime-settings
Created December 3, 2014 09:43
ST2 User-Setting
{
"color_scheme": "Packages/Color Scheme - Default/Monokai.tmTheme",
"folder_exclude_patterns":
[
".svn",
".hg",
"CVS"
],
"font_size": 9.0,
"ignored_packages":