Skip to content

Instantly share code, notes, and snippets.

View danielrose7's full-sized avatar

Daniel Rose danielrose7

View GitHub Profile
@danielrose7
danielrose7 / Router.js
Last active May 24, 2019 18:49
useServerRender React hook that fetches DOM from the server and places it (dangerously) into the view. Helpful for migrating legacy applications
// I put this in app/index.js but you do you!
import React, { Suspense, lazy } from "react";
import PropTypes from "prop-types";
import { Route, Switch } from "react-router-dom";
import { SharedProvider } from "../../../modules/something/context"; // to easily share state without going full redux
import SharedHeader from "../../widgets/employees/Header"; // some shared header
import SomeMenu from "./SomeMenu"; // some shared navigation
import { ThreeDotLoader } from "../../shared"; // simple loader
@danielrose7
danielrose7 / google_sheet_report_writer.rb
Last active November 15, 2023 11:37
Write reports straight to google sheets! We use this in our Rails app to run queries and share the data outside the app.
require 'google/apis/sheets_v4'
require 'google/apis/drive_v3'
require 'googleauth'
require 'fileutils'
class GoogleSheetReportWriter
def initialize(notification_email:)
@creds = build_credentials
@notification_email = notification_email
end
@danielrose7
danielrose7 / 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}
@danielrose7
danielrose7 / 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;
@danielrose7
danielrose7 / 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
@danielrose7
danielrose7 / 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);
});
@danielrose7
danielrose7 / 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.

@danielrose7
danielrose7 / 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: {
@danielrose7
danielrose7 / 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,
@danielrose7
danielrose7 / 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