Skip to content

Instantly share code, notes, and snippets.

View sompylasar's full-sized avatar

Ivan Babak sompylasar

View GitHub Profile
'use strict';
// The following line enables extended tracking of unhandled promise rejections.
// @see https://github.com/cujojs/when/blob/master/docs/api.md#whenmonitorconsole
require('when/monitor/console');
var when = require('when');
/**
* Converts an object to a thenable that can be resolved to itself.
@sompylasar
sompylasar / Viewport.js
Last active March 18, 2017 11:16
Viewport React component with animated scrolling and overlay handling.
import React, { Component, PropTypes } from 'react';
import verge from 'verge';
import { Motion, spring } from 'react-motion';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import styles from './styles.scss';
@sompylasar
sompylasar / actionMonitor.js
Last active March 30, 2017 09:01
Server-side rendering loop for universal sagas (redux-saga)
export default function createActionMonitor({
debug = false,
}) {
let actionMonitorLog = [];
const actionMonitorSubscriptions = [];
const middleware = () => (next) => (action) => {
if ( debug ) {
console.log('[actionMonitor] push:', action); // eslint-disable-line
@sompylasar
sompylasar / git-branch.sh
Last active September 8, 2017 23:27
A script that starts a git branch that is dedicated to a task tracking ticket (makes an empty commit that references the ticket).
#!/usr/bin/env bash
## Starts a git branch that is dedicated to a task tracking ticket.
## Makes an empty commit that references the ticket.
##
## Created: 2016-08-22
## Author: sompylasar <babak.john@gmail.com> https://github.com/sompylasar
## License: MIT
@sompylasar
sompylasar / ReduxClockProvider.js
Created December 8, 2017 23:43
Pure clock state with React, Redux, Redux-Saga. Do not use `Date.now()` or `new Date()` or `moment()` in `render()`, reading the current clock state is not pure (returns different values on each call). https://twitter.com/acdlite/status/939260579247562752
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { connect } from 'react-redux';
import {
extractClockTimestamp,
} from './reduxClockReducer';
import {
ACTION_CLOCK_SUBSCRIBE,
@sompylasar
sompylasar / cjs-timestamps-dates-inject-via-rawgit.js
Last active December 29, 2017 02:40
Human-readable timestamps in Chrome JSONView.
// Custom JavaScript for websites: https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija?hl=en
// JSONView: https://chrome.google.com/webstore/detail/jsonview/chklaanhfefbnpoihckbnefhakgolnmc?hl=en
(function () {
var script = document.createElement('script');
script.async = true;
script.src = 'https://rawgit.com/sompylasar/5440f7f0e3e7bc75c64674f14f58f6df/raw/cjs-timestamps-dates.js';
document.head.appendChild(script);
})();
@sompylasar
sompylasar / hoistRedditImages.js
Last active January 15, 2018 01:08
Avoid clicking every subreddit to view the full image at https://www.reddit.com/r/ColorizedHistory/
// Avoid clicking every subreddit to view the full image, for example, at https://www.reddit.com/r/ColorizedHistory/
// Run the following code via the Chrome DevTools Console in the top frame of the Reddit page.
(function hoistRedditImages() {
Promise.all(
[].slice
.call(document.querySelectorAll("#siteTable a[data-href-url]"))
.map(el => {
if (document.querySelectorAll(".hoistRedditImages").length) {
return;
}
@sompylasar
sompylasar / Fahrenheit.md
Created January 19, 2018 19:56
"Cold" is a relative term. Use the handy list below to overcome the confusion. Degrees (Fahrenheit)

"Cold" is a relative term. Use the handy list below to overcome the confusion. Degrees (Fahrenheit)

65

  • Hawaiians declare a two-blanket night

60

  • Californians put on sweaters (if they can find one)

50

  • Miami residents turn on the heat

45

  • Vermont residents go to outdoor concerts
@sompylasar
sompylasar / cjs-jira-favicon-per-project.js
Created January 19, 2018 20:52
Sync JIRA favicon with the icon for the currently opened project.
// Custom JavaScript for websites: https://chrome.google.com/webstore/detail/custom-javascript-for-web/poakhlngfciodnhlhhgnaaelnpjljija?hl=en
// NOTE(@sompylasar): Doesn't work for the default project icons because they are in SVG, and link rel "shortcut icon" doesn't seem to accept SVGs.
(function () {
var iconEl = window.document.querySelector('link[rel="shortcut icon"]');
if (!iconEl) { return; }
var defaultSrc = iconEl.getAttribute('href');
var observer;
var timer;
var update = function () {
var imageEl = window.document.querySelector('[src^="' + window.location.origin + '/secure/projectavatar?"]');
const jestDiff = require('jest-diff'); // should be jest-diff@22.1.0
function jestDiffAndPrint(a, b) {
console.log(
'----------- a:\n' +
a +
'\n----------- b:\n' +
b +
'\n----------- diff:\n' +
jestDiff(a, b) +