Skip to content

Instantly share code, notes, and snippets.

View danielpowell4's full-sized avatar

Daniel Powell danielpowell4

View GitHub Profile
@danielpowell4
danielpowell4 / AnimatedComponent.jsx
Last active August 9, 2018 15:46
Example reusable scss mixin of a slide in animation for a React component using CSSTransitionGroup
import React from "react";
import ReactCSSTransitionGroup from "react-addons-css-transition-group";
import SomeOtherComponentOrChild from "./SomeOtherComponentOrChild" // more likely defined inline
// Great for list items or quick, inline forms!
const AnimatedComponent = props =>
<ReactCSSTransitionGroup
transitionName="transition-name" // creates class that is passed to scss mixin
transitionEnterTimeout={400}
@danielpowell4
danielpowell4 / starterAuth.js
Last active July 6, 2018 17:08
react-router and several other demos offer up a "fakeAuth". This is a starterAuth that sends an email and password to an external API and then stores the returned auth_token JWT in localStorage. Main benefit of doing so is to persist login between page refreshes.
import fetch from "cross-fetch";
const apiUrl = "//localhost:5000"; // or where ever your api lives!
const checkStatus = response => {
if (response.status >= 200 && response.status < 300) {
return response;
}
const error = new Error(`${response.statusText}`);
error.status = response.statusText;
error.response = response;
@danielpowell4
danielpowell4 / user_meta_tag.rb
Created April 1, 2018 00:32
User meta tag for Ruby on Rails app. Here used to feed Honeybadger user context information through a common application pack
# securely set current_user (likely in ApplicationController.rb or similar extended concern)
class ApplicationController < ActionController::Base
protect_from_forgery
helper_method :logged_in?, :current_user
def current_user
user = User.find_by(auth_token: cookies[:auth_token]) if cookies[:auth_token] # or from something like a user_id in session
user ? user.person : NullUser.new
end
@danielpowell4
danielpowell4 / asyncPromise.js
Last active January 17, 2018 22:19
Drop in stub/mock for a fetch while the backend Api is still being development
const expectedResponse = { key: "value" };
export const fetchObjects = parentId =>
new Promise((resolve, reject) => {
setTimeout(() => resolve(expectedResponse), 1000);
});
@danielpowell4
danielpowell4 / off_button_for_ONLY_FULL_GROUP_BY.md
Created January 3, 2018 21:13
Turning off ONLY_FULL_GROUP_BY mode in MySQL 5.7

Turn off ONLY_FULL_GROUP_BY

If you're like me you know that it should be on, that's the default it makes SQL work properly yada yada.

You also have an app to run and it hasn't been working unexpectedly to date. In moving from 5.6 to 5.7 the strategy is something along the lines of "monkey patch for now and ... hopefully fix the handful of odd queries later"

Create a /etc/my.cnf file

Deep in your OS X computer there is a /etc directory.

@danielpowell4
danielpowell4 / noteStoreShape.js
Created October 24, 2017 14:56
Starting shape of new react/redux note app
notes: {
byId: { // object keyed by Id
noteId: {
id: noteId,
content: noteContent,
...
}
},
creationForm: {
@danielpowell4
danielpowell4 / react_redux_rails_configs_with_babel_env_jest_and_prettier.md
Last active January 17, 2018 00:05
Babelrc env preset for rails app with React + Redux without webpacker using Prettier, Jest and Browserify for create-react-app like setup

package.json

Here I've placed what I see as essentials. Feel free to add or substract if your see overkill for your sitruation! sinon seems like the only potential overkill to me at the time of this writing.

{
  "name": "app-name",
  "jest": {
    "verbose": true,
@danielpowell4
danielpowell4 / export_records_in_model_to_csv.rb
Created March 9, 2017 22:49
Exports records from a sample users model to csv by means of a controller action and `.csv` format. Ruby on Rails app
# Synchronously creates and sends records for download
# For scale, this would be better done async via a rake task, chron job, or something similar
# borrowed from https://gorails.com/episodes/export-to-csv
# sample controller
class UsersController < ApplicationController
def index
@users = User.all
@danielpowell4
danielpowell4 / query_to_csv.rb
Created March 9, 2017 22:16
This ruby script runs a SQL query and writes it as a CSV in the tmp folder using ruby's CSV library in a Ruby on Rails app
# run from console with `rails runner /path/to/this/file.rb`
# a timestamped file is placed in a Rails' app's tmp folder
require 'csv'
def file_path(name_of_file)
Rails.root.join('tmp', "#{name_of_file}_#{sanitize_time(Time.zone.now)}.csv") # don't edit name set on line 22
end
def sanitize_time(time)
@danielpowell4
danielpowell4 / paper_clip_extensions.rb
Created March 2, 2017 19:32
Verbose paperclip file extensions Basic: csv, pdf, txt | Microsoft: doc, docx, ppt, pptx, xls, xlsx | Images: gif, jpg, jpeg, png | Apple: pages, numbers
# If you want to add to your list, you can sniff using a binding.pry
# Look at the ActionDispatch::Http::UploadedFile object's Content-Type in the @header variable
validates_attachment :attachment,
allow_blank: false,
content_type: { content_type: ['image/jpg', #image
'image/jpeg', #image
'image/gif', #image
'image/png', #image
'application/pdf', #pdf