Skip to content

Instantly share code, notes, and snippets.

View tsnieman's full-sized avatar
🗿
living.

Tyler Nieman tsnieman

🗿
living.
View GitHub Profile
@tsnieman
tsnieman / spec_helper.rb
Last active August 29, 2015 14:05
Rails 4 controller test example with RSpec 3, devise
RSpec.configure do |config|
...
config.include Devise::TestHelpers, :type => :controller
...
end
@tsnieman
tsnieman / devise.rb
Created June 10, 2015 20:38
ldap_authenticatable module for devise that checks if a member is in a group.
# add this to the Devise.setup block
config.warden do |manager|
manager.default_strategies(:scope => :admin).unshift :ldap_authenticatable
end
// This is a stateless functional component which
// largely acts like a 'normal' Class-based component's
// `render()` function.
var Hello = function(props) {
return <div>Hello, {props.name}</div>;
}
// Shorthand.
var Hello = props => <div>Hello, {props.name}</div>;
@tsnieman
tsnieman / form-component-task.js
Last active January 4, 2016 06:49
Form component task.js
// In the parent component ...
render() {
let myOnSuccessFunction = function({word, color}) {
alert('word: ', word)
alert('color: ', color)
}
return (
<ColorWordForm
onSave={myOnSuccessFunction}
@tsnieman
tsnieman / BernieSandersConsistency.md
Created December 12, 2015 14:49
Bernie Sanders: consistency and foresight.

Now that he's in the national spotlight he's getting a lot of unwarranted hate. There's a rush to discredit him, as if he either doesn't have technical details for his plans (he does) or that he doesn't know how to pay for his proposals (he does). Sanders' campaign is based on the same principle his whole career has been; ethics in politics. The difference between him and most other leftist politicians is that he has the record to back up his rhetoric; he's shown consistency in both message and accuracy for decades.

Here are some old C-Span videos of Bernie ranting about things in Congress -- you might notice how often he's on point long before most of America catches up.

  • [Bernie Sanders opposes the Iraq War and que
@tsnieman
tsnieman / ParentComponent.js
Last active January 7, 2016 15:35
A PostForm component that will use its input box values for a live preview in a Post component.
class ParentComponent extends Component {
constructor(props) {
super(props);
this.state = {
// Default state can be defined here.
post: {
title: '',
content: '',
author: '',
@tsnieman
tsnieman / Auth.js
Created January 12, 2016 16:48
An auth component for React.js.
// Basics
import { Component, PropTypes } from 'react';
import { connect } from 'react-redux';
import actions from 'actions/index';
class Auth extends Component {
constructor(props) {
super(props);
}
@tsnieman
tsnieman / symbols-for-complex-keys.js
Last active January 13, 2016 01:17
ES6 Symbols for complex keys (like addresses)
const address = 'Space Needle, 400 Broad St, Seattle, WA 98109';
const globalAddressSymbol = Symbol.for(address); // Search global Symbol registry for existing & return it, otherwise create it in the global registry.
const uniqueAddressSymbol = Symbol(address); // Creates Symbol(uniqueAddressSymbol), a guaranteed unique key.
console.log(globalAddressSymbol !== uniqueAddressSymbol); // Symbols created outside of the global registry are ALWAYS unique.
console.log(globalAddressSymbol === Symbol.for(address)); // because `Symbol.for` accesses the global Symbol registry
const addressesIndex = {
[globalAddressSymbol]: { // Address can be used as a key via Symbol (i.e. for normalization)
'prettyAddress': address,
'latLng': [47.6204, -122.3491],
},
@tsnieman
tsnieman / object-literal-property-value-shorthand.md
Last active February 13, 2016 01:55
JSX "Object Literal Property Value Shorthand"

Common problem...

<SomeComponent propVariable={propVariable} />

I repeat "propVariable". I find myself doing this a lot... like, several times for one JSX object (usually a React component) is not uncommon.

Proposed solution...

<SomeComponent [propVariable] />
@tsnieman
tsnieman / remove-composes.js
Created July 30, 2016 22:26
Custom loader to remove 'composes' from CSS modules. Created for testing because of this bug https://github.com/istarkov/babel-plugin-webpack-loaders/issues/97
// Custom webpack loader which simply removes any use of 'composes'.
// This is because this bug https://github.com/istarkov/babel-plugin-webpack-loaders/issues/97
// causing issues with testing.
module.exports = function removeComposes(source) {
if (process.env.NODE_ENV === 'test') {
const hasComposes = source.indexOf('composes') > 0;
if (!hasComposes) return source;
var numOfOccurences = source.match(/composes/g).length;