Skip to content

Instantly share code, notes, and snippets.

View joshdover's full-sized avatar

Josh Dover joshdover

View GitHub Profile
@joshdover
joshdover / gauge_view.js.coffee
Last active December 10, 2015 14:58
GaugeView for Batman using JustGage
class Albedo.GaugeView extends Batman.View
@option 'title', 'max', 'min', 'value', 'better'
@::on 'appear', ->
@makeGauge()
makeGauge: ->
node = $(@get('node'))
node.attr 'id', @get('title')
@joshdover
joshdover / Gemfile
Created March 14, 2013 23:10
Standalone RSpec + Capybara Suite
source "https://rubygems.org"
gem "rspec"
gem "capybara"
gem "headless"
@joshdover
joshdover / application.html.erb
Last active December 25, 2015 03:49
Rails helper for automatically generating mixpanel tracking for links.
<!-- 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 %>
@joshdover
joshdover / gist:7966016
Created December 14, 2013 22:49
Declarative Mixpanel Helper Allows you to declare tracking of onClick event on any type of DOM element.
# 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 / controller_template.js
Last active August 29, 2015 13:57
angular unit test blog post
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 / activity.js
Last active August 29, 2015 14:00
MozActivity example
new MozActivity({
name: 'send',
data: {
type: 'text/plain',
text: 'Hello Android, I am a web app!'
}
});
@joshdover
joshdover / README.md
Last active September 28, 2023 21:38
Idiomatic React Testing Patterns

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 / ExtendedRichUtils.js
Last active July 30, 2021 12:58
Example of how to add metadata to blocks for handling text alignment correctly
import { Modifier, EditorState, RichUtils } from 'draft-js';
import getCurrentlySelectedBlock from './getCurrentlySelectedBlock';
export const ALIGNMENTS = {
CENTER: 'center',
JUSTIFY: 'justify',
LEFT: 'left',
RIGHT: 'right'
};
@joshdover
joshdover / 01_python_flamegraphs.md
Last active November 27, 2022 20:38
Python flamegraphs

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 / pointer.patch
Created June 2, 2018 03:20
bochs for Mac OS 10.14
--- 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());
}