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 / MultiHandlerFactory.js
Last active December 5, 2016 19:24
MuntiHandler is a callable object that manages handlers for single event
const handlerFactory = (sub = null) => {
const handlers = [];
const handler = (...args) => {
for (let handler of handlers) {
handler.apply(null, args);
}
};
handler.add = (sub) => {
if (sub !== handler && sub instanceof Function && handlers.indexOf(sub) < 0) {
handlers.push(sub);
@burdiuz
burdiuz / CallableObject.js
Last active December 4, 2016 12:42
Callable object
class AbstractCallableObject {
constructor() {
return (...args) => this.apply(this, args);
}
apply(target, args) {
this.call(target, ...args);
}
/*abstract*/ call(target, ...args) {
@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;
'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 / 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;
@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 / GithubSignIn.js
Last active March 11, 2019 22:33
React Native component built to login users and obtain accessToken via callback
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { WebView } from 'react-native';
const WEBVIEW_URL = 'https://github.com/login/oauth/authorize';
const TOKEN_URL = 'https://github.com/login/oauth/access_token';
/*
URL that will be displayed after successful login, it should be different to track URL change, so component can grab code
*/
@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 / FilterOutLockedItems.js
Last active February 19, 2020 21:24
Steam market script that filters out items with locked properties
(() => {
let index = 0;
const step = 10;
const root = document.querySelector('#searchResultsRows');
root.innerHTML = '';
const loadPage = (page, count) => {
fetch(`https://steamcommunity.com/market/listings/<GAME_ID>/<ITEM_NAME>/render/?query=&start=${page*count}&count=${count}&country=RU&language=english&currency=5`)
.then((response) => response.json())
.then(({results_html, listinginfo, assets}) => {
assets = assets['570']['2'];