Skip to content

Instantly share code, notes, and snippets.

View Maqsim's full-sized avatar

Max Diachenko Maqsim

View GitHub Profile
@Maqsim
Maqsim / promise-wrapper.ts
Last active October 28, 2024 21:14
A non-block promise wrapper fro axios/fetch
import type { AxiosError, AxiosPromise } from 'axios';
type Result<T> = [AxiosError, null] | [null, T];
type AllResult<T> = [AxiosError, null] | [null, T[]];
/**
* Wraps an Axios promise to return a tuple with either the error or the response data.
*
* @template T - The type of the response data.
* @param {AxiosPromise<T>} promise - The Axios promise to wrap.
@Maqsim
Maqsim / Music.swift
Created October 12, 2019 09:29
SBApplication headers in Swift for Music.app
import AppKit
import ScriptingBridge
@objc public protocol SBObjectProtocol: NSObjectProtocol {
func get() -> Any!
}
@objc public protocol SBApplicationProtocol: SBObjectProtocol {
func activate()
var delegate: SBApplicationDelegate! { get set }
# EditorConfig is awesome: http://EditorConfig.org
# top-most EditorConfig file
root = true
# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
indent_style = space
@Maqsim
Maqsim / angular-resource-mock.ts
Created July 15, 2019 08:13
Mocks angular resource service to quickly emulate server communication
import angular from 'angular';
import AngularResource from 'angular-resource';
import AppEnvironment from 'app-environment';
import { each, where, findWhere, extend, pick, omit } from 'underscore';
export const RewardShopProductModule = angular.module('app.resources.reward-shop-product', [
AngularResource,
AppEnvironment
])
.service('RewardShopProduct', ($resource: ng.resource.IResourceService, $timeout: any, SHOP_API_BASE: string) => {
@Maqsim
Maqsim / wait-for-image.module.ts
Created July 15, 2019 08:10
Directive that waits for image is available (not 404) for some time and then set image to src="" or background-image: url()
import angular from 'angular';
import { defaults } from 'underscore';
interface IScope extends ng.IScope {
url: string;
backgroundImage: string;
showSpinner: string;
maxRetries: string;
delay: string;
}
@Maqsim
Maqsim / imports.js
Created February 1, 2019 16:58
HTML Imports
const links = document.querySelectorAll('link[rel="import"]');
Array.from(links).forEach(link => {
const template = link.import.querySelector('template');
const clone = document.importNode(template.content, true);
document.querySelector(link.getAttribute('destination')).replaceWith(clone);
});
@Maqsim
Maqsim / 413-payload-too-large-fix.js
Last active October 28, 2024 21:06
HOW TO FIX "413 Payload too large" in NodeJS (Express)
const express = require('express');
const bodyParser = require('body-parser');
...
// Express 4.0
app.use(bodyParser.json({ limit: '10mb' }));
app.use(bodyParser.urlencoded({ extended: true, limit: '10mb' }));
// Express 3.0
@Maqsim
Maqsim / api-wrapper.js
Created March 4, 2018 00:51
Custom API wrapper (minimalistic concept) for any RESTful API to minimize and beautify your code
class WhateverAPI {
constructor(baseUrl, clientID, accessToken) {
this._baseUrl = baseUrl;
this._clientID = clientID;
this._accessToken = accessToken;
this._baseUrl += this._baseUrl.slice(-1) !== '/' ? '/' : '';
}
resolveUrl(path) {
return this._baseUrl + path + `?client_id=${this._clientID}&access_token=${this._accessToken}`;
@Maqsim
Maqsim / hex-to-bgr.js
Created February 13, 2018 23:12
HEX to BGR
'#ff2233'.substr(1).match(/.{2}/g).reverse().join('')
@Maqsim
Maqsim / gist:a660b5624d05249b704c
Created May 15, 2015 17:59
Set all title by max height
var maxTitleHeight = angular
.element('.tracker_title')
.map(function() {
return angular.element(this).height();
});
maxTitleHeight = Math.max.apply(this, maxTitleHeight);
angular
.element('.tracker_title')