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 / EventDeferred.js
Created March 10, 2017 21:10
Promise listener for an event that will resolve when event fired
import SymbolImpl from 'SymbolImpl';
const INTERNALS_FIELD = SymbolImpl('event.deferred::internals');
class EventDeferred {
constructor(dispatcher, eventType) {
this.promise = new Promise((resolve, reject) => {
this[INTERNALS_FIELD] = {
dispatcher,
eventType,
@burdiuz
burdiuz / DuplexListener.js
Last active March 10, 2017 21:23
Dispatches event and wait for response event and resolve promise
import SymbolImpl from 'SymbolImpl';
import EventDeferred from 'EventDeferred';
const INTERNALS_FIELD = SymbolImpl('duplex.listener::internals');
class DuplexListener {
constructor(dispatcher, event, responseEventType, data = null) {
if (responseEventType) {
const deferred = new EventDeferred(dispatcher, responseEventType);
this.promise = deferred.promise;
'use strict';
import SymbolImpl from 'SymbolImpl';
import EventDispatcher from 'event-dispatcher';
const INTERNALS_FIELD = SymbolImpl('timer::internals');
const getInitObject = (delay, repeatCount,) => ({
delay,
repeatCount,
@burdiuz
burdiuz / SymbolImpl.js
Last active March 28, 2017 10:04
SymbolImpl simple fallback for environments that don't have Symbol type
'use strict';
let SymbolImpl;
if (typeof(Symbol) === 'undefined') {
SymbolImpl = (value) => {
const salt = Math.random();
const symbol = () => `@@${value}:${salt}`;
symbol.toString = symbol;
symbol.valueOf = symbol;
@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 / parseHTTPRequest.js
Created October 8, 2017 19:04
Parse HTTP request headers
export const parseHTTPRequest = (data) => {
const headers = {};
const rgx = /^([^\:\r\n]+)\:\s*([^\r\n]+)$/gm;
const [requestHeader, method, path, httpVersion] = data.match(/^(\w+)\s+([^\r\n]+)\s+HTTP\/([\d\.]+)/);
const request = { requestHeader, method, path, httpVersion, headers };
let header;
while ((header = rgx.exec(data))) {
const [, name, value] = header;
headers[name] = value;
@burdiuz
burdiuz / IndieGalaBulkCreateTrades.js
Last active February 11, 2018 18:00
Script that allows to create trades from all unused games ion your IndieGala account, trades for any other game.
/**
Login to your IndieGala accountand launch this script in console.
It asks to trade for any game.
*/
((window, document) => {
let alertsCount = 0;
const alert = (content) => {
console.warn('Alert:', content);
alertsCount++;
@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
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();