Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh Dover joshdover

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am joshdover on github.
  • I am joshdover (https://keybase.io/joshdover) on keybase.
  • I have a public key ASAfX7rWttw5Abh7TK_kfxc421jTuwwL82kmpGLn_1W4Bwo

To claim this, I am signing this object:

@joshdover
joshdover / shim.js
Last active Aug 29, 2018
Hapi v17 Shim - probably not 100% complete - not recommended for production
View shim.js
const Hapi = require('hapi');
const Boom = require('boom');
function installShim(server) {
/**
* Request wrapping factory that emulates Hapi v14 behavior.
*/
function handlerWrapper(originalHandler, { isPreResponse = false } = {}) {
// Leave undefined, null, and string (registered server functions) values unchanged.
@joshdover
joshdover / pointer.patch
Created Jun 2, 2018
bochs for Mac OS 10.14
View pointer.patch
--- config.cc 2018-06-01 22:18:19.000000000 -0500
+++ config1.cc 2018-06-01 22:18:02.000000000 -0500
@@ -3258,7 +3258,7 @@
fprintf(fp, ", biosdetect=%s", SIM->get_param_enum("biosdetect", base)->get_selected());
- if (SIM->get_param_string("model", base)->getptr()>0) {
+ if (SIM->get_param_string("model", base)->getptr() != 0) {
fprintf(fp, ", model=\"%s\"", SIM->get_param_string("model", base)->getptr());
}
View 01_python_flamegraphs.md

Install python-flamegraph into your project:

pip install git+https://github.com/evanhempel/python-flamegraph.git

Record a profile around a bit of code:

import flamegraph
thread = flamegraph.start_profile_thread(fd=open("./profile.log", "w"))
@joshdover
joshdover / ExtendedRichUtils.js
Last active Jul 10, 2020
Example of how to add metadata to blocks for handling text alignment correctly
View ExtendedRichUtils.js
import { Modifier, EditorState, RichUtils } from 'draft-js';
import getCurrentlySelectedBlock from './getCurrentlySelectedBlock';
export const ALIGNMENTS = {
CENTER: 'center',
JUSTIFY: 'justify',
LEFT: 'left',
RIGHT: 'right'
};
@joshdover
joshdover / README.md
Last active Nov 1, 2020
Idiomatic React Testing Patterns
View README.md

Idiomatic React Testing Patterns

Testing React components seems simple at first. Then you need to test something that isn't a pure interaction and things seem to break down. These 4 patterns should help you write readable, flexible tests for the type of component you are testing.

Setup

I recommend doing all setup in the most functional way possible. If you can avoid it, don't set variables in a beforeEach. This will help ensure tests are isolated and make things a bit easier to reason about. I use a pattern that gives great defaults for each test example but allows every example to override props when needed:

@joshdover
joshdover / activity.js
Last active Aug 29, 2015
MozActivity example
View activity.js
new MozActivity({
name: 'send',
data: {
type: 'text/plain',
text: 'Hello Android, I am a web app!'
}
});
@joshdover
joshdover / controller_template.js
Last active Aug 29, 2015
angular unit test blog post
View controller_template.js
describe('Controller: MyCtrl', function () {
beforeEach(module('MyApp'));
var scope;
// Initialize the controller and a mock scope
beforeEach(inject(function ($controller, $rootScope) {
scope = $rootScope.$new();
startController = function() {
$controller('MyCtrl', {
@joshdover
joshdover / gist:7966016
Created Dec 14, 2013
Declarative Mixpanel Helper Allows you to declare tracking of onClick event on any type of DOM element.
View gist:7966016
# Helper for tracking mixpanel events, allows for declaritve events. Usage:
# <a href="http://google.com" data-mixpanel="name: 'clicked link'">Google</a>
# <a href="http://cows.com" data-mixpanel="name: 'clicked link', data: { animal: 'cow' }">Cow</a>
# <li data-mixpanel="'clicked list element'">I am not a link!</li>
$(document).on "click", "[data-mixpanel]", (event) ->
options = eval "({" + $(this).attr("data-mixpanel") + "})"
# If event is bound to a link, add delay to ensure event is tracked.
if event.currentTarget.href?
options.data = {} if !options.data?
@joshdover
joshdover / application.html.erb
Last active Dec 25, 2015
Rails helper for automatically generating mixpanel tracking for links.
View application.html.erb
<!-- Include Mixpanel and init before this. -->
<!-- Place at the bottom of your layout (ex: app/views/layouts/application.html.erb) -->
<% if content_for :mixpanel %>
<%= javascript_tag(yield :mixpanel) %>
<% end %>
You can’t perform that action at this time.