Skip to content

Instantly share code, notes, and snippets.

@LoganBarnett
LoganBarnett / index.js
Last active May 10, 2016 22:23
Example test with db-api agnostic usage
const R = require('ramda');
const dbFn = require('./sql-db');
const shipmentModelFn = require('shipment-model');
const db = dbFn();
const shipmentModel = shipmentModelFn(db.create);
// provide shipmentModel to the controller or something...
@LoganBarnett
LoganBarnett / ObjectTypeEditorContainer.js
Created April 13, 2016 23:40
Redux container testing example
// @flow
import React from 'react';
import R from 'ramda';
import { fieldFn } from '../field';
import { addField, onSave } from '../actions/object-type-editor';
import type {
ObjectTypeEditorFormArg,
ObjectTypeEditorFormComp,
} from '../components/ObjectTypeEditorForm';
const mapIdx = R.addIndex(R.map);
@LoganBarnett
LoganBarnett / create-list-item.js
Created December 17, 2015 22:54
React fp-style wrap-in-li function
const createListItem = (key, C, props, i) => {
return <li key={key + '-' + i}> <C {...props} /> </li>;
};
@LoganBarnett
LoganBarnett / no-mocks.js
Created November 18, 2015 18:00
Showing how you can use higher order functions to remove the need for mocks
// the way you'd normally think to do it. This requires mocking out writeFileSync to test
var fs = require('fs');
function writeXmlToFile(fileName, data) {
// do stuff with data
// make data into xml
var xml = toXml(data);
fs.writeFileSync(fileName, {encoding: 'utf-8'}, xml);
}
@LoganBarnett
LoganBarnett / corsHeader.java
Last active December 16, 2016 04:10
Example of how to add a CORS header using Jersey.
package com.myapp.filters;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
describe('my category', function() {
beforeEach(module('LocalForageModule'));
it('does stuff', function() {
inject(function($localForage) {
// test stuff goes here
});
});
});
@LoganBarnett
LoganBarnett / gulpfile.js
Last active September 18, 2015 22:25
Gulp file for doing lots of cool stuff I want in all of my projects.
/*******************************************************************************
The MIT License (MIT)
Copyright (c) 2015 Logan Barnett ([email protected])
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@LoganBarnett
LoganBarnett / di.js
Last active September 5, 2015 06:29
Example of DI, and not DI.
// how it was done before we saw the light
var hats = ['cone', 'horse'];
var buzzers = ['foo', 'bar', 'bazz'];
var drinkFn = function() {
drunkify();
}
var partyObj = {};
partyObj.throw = function() {
// reach outside of our local scope to get what we need. Ick!
@LoganBarnett
LoganBarnett / 2015-react-rally.md
Last active February 25, 2016 14:01
Notes from the 2015 React Rally conference.
@LoganBarnett
LoganBarnett / translation_test.js
Last active August 29, 2015 14:26
Finds templates, scans for things that are obviously not translated and builds a report with a failed test.
it("check for untranslated strings", function() {
// WIP for the new version
const textRegexp = /.+/;
const templateBindingRegexp = /^({{.+}})$/;
const results = _.map(tmplArray, $tc.get) // load the template from the path
.map(angular.element) // process the template data into Angular's DOM
.map((e) => e.text()) // remove all markup - only text should remain
.map((t) => t.trim()) // remove whitespace
// strip out bindings - they are dynamic and thus translated. Probably.
.map((t) => t.replace(templateBindingRegexp, ''))