Skip to content

Instantly share code, notes, and snippets.

@berkin
berkin / authorization-middleware.js
Last active August 16, 2018 11:08
redux authorization header middleware
import axios from 'axios'
export default ({ getState }) => next => action => {
const prevToken = getState().auth.access_token
// if authorization header is null and we have token, set it for the next action
if (!axios.defaults.headers['Authorization'] && prevToken) {
axios.defaults.headers['Authorization'] = `Bearer ${prevToken}`
}
const events = ['click', 'touchstart', 'touchmove', 'touchend', 'mousedown', 'mousemove', 'mouseup', 'keydown', 'keyup'];
const defaults = {
timeout: 5000
};
let timer = null;
function BlockUi(context, options) {
#!/bin/bash
album=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "album"|egrep -v "album"|egrep -v "array"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$`
artist=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 2 "artist"|egrep -v "artist"|egrep -v "array"|cut -b 27-|cut -d '"' -f 1|egrep -v ^$`
title=`dbus-send --print-reply --dest=org.mpris.MediaPlayer2.spotify /org/mpris/MediaPlayer2 org.freedesktop.DBus.Properties.Get string:'org.mpris.MediaPlayer2.Player' string:'Metadata'|egrep -A 1 "title"|egrep -v "title"|cut -b 44-|cut -d '"' -f 1|egrep -v ^$`
echo $artist " - " $album " - " $title;
@berkin
berkin / install_dbus.sh
Created December 6, 2016 14:42
Install DBus under Mac OS X.
#!/usr/bin/env bash
# Created @ 13.01.2015 by Christian Mayer <http://fox21.at>
brew install dbus
cp /usr/local/Cellar/d-bus/1.8.8/org.freedesktop.dbus-session.plist ~/Library/LaunchAgents
# Load DBus
launchctl load -w ~/Library/LaunchAgents/org.freedesktop.dbus-session.plist
@berkin
berkin / scroll-height.js
Created December 6, 2016 07:21
Scroll height of content
function scrollHeight() {
const body = document.body;
const html = document.documentElement;
return Math.max(body.scrollHeight, body.offsetHeight, html.clientHeight, html.scrollHeight, html.offsetHeight);
}
@berkin
berkin / Inconsolata-dz-Powerline.otf
Created December 5, 2016 08:31 — forked from qrush/Inconsolata-dz-Powerline.otf
vim-powerline patched fonts
let tabbables;
function setTabbable(e) {
if (e.keyCode === 9) {
e.preventDefault();
// the tabbable elements can be changed.
tabbables = Array.prototype.slice.call(tabbable(this.currentStepView));
const isFocused = tabbables.some((item, i) => {
<a href="http://stackoverflow.com/questions/9804280/how-to-prevent-focus-event-in-ie-when-mousedown-happens/17525223#17525223">http://stackoverflow.com/questions/9804280/how-to-prevent-focus-event-in-ie-when-mousedown-happens/17525223#17525223</a>
<br />
<input type="text" id="name">
<div onmousedown="return false" unselectable="on" id="suggest">
<div unselectable="on">mark</div>
<div unselectable="on">sam</div>
<div unselectable="on">john</div>
</div>
import scrollParent from './scrolll-parent.js';
if (/Android [4-6]/.test(navigator.appVersion)) {
window.addEventListener('resize', () => {
if (document.activeElement.tagName === 'INPUT') {
window.setTimeout(() => {
const el = document.activeElement;
const rect = el.getBoundingClientRect();
const container = scrollParent(el);
const regex = /(auto|scroll)/;
const parents = function (node, ps) {
if (node.parentNode === null) { return ps; }
return parents(node.parentNode, ps.concat([node]));
};
const style = function (node, prop) {
return getComputedStyle(node, null).getPropertyValue(prop);