This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import io.reactivex.disposables.CompositeDisposable | |
import io.reactivex.subjects.PublishSubject | |
/** | |
* Created by adrielcafe on 20/12/17. | |
*/ | |
object KBus { | |
val disposables = mutableMapOf<Any, CompositeDisposable>() | |
val publishSubject = PublishSubject.create<Any>()!! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fib = n => (n < 2) ? n : fib(n - 1) + fib(n - 2) | |
const fibSexy = (() => { | |
const cache = {} | |
const f = n => { | |
const value = (n in cache) | |
? cache[n] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Filters an object returning only properties specified | |
* | |
* @param {Object} obj Source object | |
* @param {Array} keys List of (strings) properties to keep | |
* @return {Object} Object with only props specified in `keys` | |
*/ | |
export const filterKeys = (obj, keepKeys, dropKeys) => { | |
if (typeof obj !== 'object') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Creates a debounced monad to allow a method to be called | |
* many times, but only execute after N seconds has elapsed | |
* | |
* @param {Function} func Method to call | |
* @param {Number} wait Timeout, in milliseconds | |
* @param {Boolean} [immediate] Optionally skip the wait | |
* @return {Function} Debounced monad that can be called multiple times | |
*/ | |
export function debounce(func, wait, immediate) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const throttle = (fn, delay) => { | |
let lastCall = 0 | |
return (...args) => { | |
const now = (new Date).getTime() | |
if (now - lastCall < delay) return | |
lastCall = now | |
return fn(...args) | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const attempt = (fn, delay, max, count = 0) => { | |
let pendingResolve = null | |
let pendingReject = null | |
const pendingPromise = new Promise((resolve, reject) => { | |
pendingResolve = resolve | |
pendingReject = reject | |
}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const ev = document.createEvent('MouseEvents') | |
ev.initEvent('click', true, true) | |
document.querySelector('a[data-moxie-start-engagement="chat"]').dispatchEvent(ev) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const arrayChunk = (array, chunkSize) => | |
Array(Math.ceil(array.length / chunkSize)) | |
.fill() | |
.map((_, index) => index * chunkSize) | |
.map(it => array.slice(it, it + chunkSize)) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// e.g. src/lib/helpers.js | |
export const createAsyncSetState = context => { | |
return function(newState) { | |
return new Promise(resolve => { | |
context.setState(newState, resolve) | |
}) | |
}.bind(context) | |
} | |
// Usage, e.g. MyComponent.jsx |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
~ cat /etc/nginx/sites-available/example.com | |
# HTTP - redirect all requests to HTTPS: | |
server { | |
listen 80; | |
listen [::]:80; | |
server_name example.com www.example.com; | |
# listen [::]:80 ipv6only=on; | |
return 301 https://$server_name$request_uri; | |
} |