Skip to content

Instantly share code, notes, and snippets.

View butchler's full-sized avatar

Adam Buechler butchler

View GitHub Profile
@butchler
butchler / honeybadger-in-jsdom.js
Created September 12, 2017 06:46
Reproduce Parse Error when sending notices to Honeybadger via POST requests inside JSDOM instance
const jsdom = require('jsdom');
const jsdomInstance = new jsdom.JSDOM('', {
url: 'http://example.com/',
runScripts: 'outside-only',
});
jsdomInstance.window.eval(`
// Make POST request to Honeybager Notice API.
const request = new XMLHttpRequest();
class MyStore extends Record({ a: 0, b: List() }) {
constructor(values) {
super(values);
const mySelector = createSelector(
[(record) => record.a, (record, arg) => arg],
(a, arg) => a + arg
);
Object.defineProperty(this, 'mySelector',
Object.getOwnPropertyDescriptor(values, 'mySelector') ||
import { Children, createElement } from 'react';
export function replaceRenderedComponents(mappings) {
let componentMap;
if (mappings instanceof Map) {
componentMap = mappings
} else if (Array.isArray(mappings)) {
componentMap = new Map(mappings);
} else {
import { createStore } from 'redux';
/**
* This is my attempt at creating a solution for the problem of scoping actions to specific
* items/entities inside of nested reducers.
*
* You can use withPath(action) to add a 'path' property to an action that defines its scope in the
* nested state.
*
* Then your reducers can use combineReducersWithPath() to pass an appropriately appended third
// Wrap combineReducers to pass a namespace as the third argument
// to each reducer, so that each reducer can know where it is in
// the state and accept namespaced actions targeted for it.
function combineReducersWithNamespace(reducers) {
return (state, action, namespace) => {
const newState = {};
Object.keys(reducers).forEach(name => {
const reducerNamespace = namespace ?
namespace + '.' + name :
@butchler
butchler / bat.lua
Created March 3, 2013 06:50
Battery indicator snippet from my AwesomeWM rc.lua.
...
-- Battery level widget
-- Create widget to show battery level
batterywidget = wibox.widget.textbox()
-- Create timer to update widget
batterytimer = timer({ timeout = 30 })
batterytimer:connect_signal("timeout", function()
local battery_info = vicious.widgets.bat("This argument doesn't seem to be used for anything.", "BAT0")
local battery_percentage = battery_info[2]