Skip to content

Instantly share code, notes, and snippets.

@kimschles
kimschles / README-Template.md
Created March 17, 2017 15:58 — forked from PurpleBooth/README-Template.md
A template to make good README.md

Project Title

One Paragraph of project description goes here

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

--
-- PostgreSQL database dump
--
-- Dumped from database version 9.5.4
-- Dumped by pg_dump version 9.5.4
--
-- Name: student; Type: TABLE; Schema: public; Owner: kimschlesinger
--

How to Preview a Mailer

Ruby on Rails's Action Mailer allows you to preview an email view. It's a bit tricky, but if you'd like to see an email before it is sent to a user, follow the instructions below.

Step 1: Set Up Your Development Environment

Step 2: Determine Which Email You'd Like to Preview

fetch(url)
.then(response => response.json())
.then()
.catch(console.error)
// Thank you, Dan Levy
function domReady(f, o, m) {
(o = document), (m = 'addEventListener');
o[m] ? o[m]('DOMContentLoaded', f) : ((o = window), o.attachEvent('onload', f));
}
// example usage:
domReady(function() {
//general:
COPY table_name TO 'location/here.csv' DELIMITER ',' CSV HEADER;
//specific:
COPY products_273 TO '/tmp/products_199.csv' DELIMITER ',' CSV HEADER;
@kimschles
kimschles / node-multiple-calls-render.js
Created March 27, 2018 02:31 — forked from magalhini/node-multiple-calls-render.js
Example on how to render multiple responses into a route in node.js
const express = require('express')
const app = express()
const path = require('path')
const fetch = require('node-fetch')
const PORT = process.env.PORT || 3000
app.get('/api/user', (req, res) => {
res.json({ name: 'Richard' });
});
const environment = process.env.NODE_ENV || 'development';
const config = require('./knexfile');
const environmentConfig = config[environment];
const knex = require('knex');
const connection = knex(environmentConfig);
module.exports = connection;

How to setup a postgres db with knex

  1. Create a db on my computer
  • createdb <name_of_database>
  1. Create tables in the db using the migration files
  • knex migrate:latest
  1. Add data to the database and tables
  • knex seed:run