Skip to content

Instantly share code, notes, and snippets.

View burdiuz's full-sized avatar
💭
isotope muffin

Oleg Galaburda burdiuz

💭
isotope muffin
View GitHub Profile
@burdiuz
burdiuz / gmtFactory.js
Created October 23, 2017 19:54
Simple factory provider for angular >1.4 that returns GMT string for local timezone.
/**
* Created by Oleg Galaburda on 26.09.15.
*/
(function(){
angular.module('timezone.gmt', []).factory('gmtFactory', function() {
function getTimezoneOffset(date){
date = date || new Date();
return date.getTimezoneOffset();
}
function intToString(num, length) {
@burdiuz
burdiuz / .npmignore
Last active February 4, 2019 21:16
@actualwave/redux-create-reducer
.*
source.js
@burdiuz
burdiuz / gogobundle_order.js
Last active December 25, 2018 15:44
GoGoBundle order helper, adds links for keys and titles
((cache={}, list=[]) => {
const fieldsets = document.querySelectorAll('fieldset');
document.body.innerHTML = fieldsets[fieldsets.length - 1].outerHTML;
document.querySelectorAll('table tr td:first-child')
.forEach(item => list.push(item));
document.querySelector('table thead tr').prepend(document.createElement('th'));
list
.reverse()
@burdiuz
burdiuz / README.md
Last active October 28, 2021 20:15
Functional replacement for Object.prototype.hasOwnProperty()

hasOwn

Failsafe function that uses Object.prototype.hasOwnProperty() and return false in case if target is not a valid object.

Note: It uses arrow functions that may not be supported by some old environments.

You better use lodash/has.

@burdiuz
burdiuz / README.md
Last active May 28, 2018 17:04
Is value a function check

isFunction

The isFunction() is a simple wrapper over

typeof value === 'function'

Previously I was using instanceof but it seems using typeof should faster. And since I do not like putting string literal here and there, I've decided to wrap it into a function.

@burdiuz
burdiuz / README.md
Last active May 28, 2018 17:22
Wrapper over new Proxy() that adds handlers for apply and construct traps for function targets.

withProxy

Factory generator for wrapping objects with Proxy. Applies construct and apply traps to function targets.

const myFactory = withProxy({
  get: myGetHandler,
  set: mySetHandler,
  apply: myApplyHandler,
  construct: myConstructHandler,
});
@burdiuz
burdiuz / README.md
Last active October 6, 2018 21:25
getClass() - Simple function wrapper over `Object.getPrototypeOf()`.

getClass()

Simple function wrapper over Object.getPrototypeOf().
Additionally provides functions to getClassName() and getParentClass().

Demo on jsFiddle.

@burdiuz
burdiuz / README.md
Created October 2, 2018 11:21
deferred() - Simple function to create Promise with exposed `resolve()` and `reject()` handlers.

deferred()

Simple function to create Promise with exposed resolve() and reject() handlers.

import deferred from '@actualwave/deferred';

const { resolve, reject, promise } = deferred();
@burdiuz
burdiuz / README.md
Last active October 2, 2018 13:30
translateJQueryEventsToDOM() - Re-dispatch jQuery events from DOM elements

jQuery events to DOM

Listens for jQuery events to re-dispatch them from DOM element as CustomEvent. To redispatch Bootstrap 4 modal events from modal DOM element

import translateJQueryEventsToDOM from '@actualwave/jquery-events-to-dom';

translateJQueryEventsToDOM()(
  'show.bs.modal',
 'shown.bs.modal',
@burdiuz
burdiuz / README.md
Last active April 8, 2019 12:16
Factory functions to create a value storage hidden in a closure

Closure Value

Factory functions to create a value storage hidden in a closure

  • singleValueFactory() - creates storage for a single value
  • valuesMapFactory() - creates storage with Map hidden, allows adding key/value pairs
  • valuesSetFactory() - creates storage with Set hidden, allows adding unique values

Demo on jsFiddle

singleValueFactory()