Skip to content

Instantly share code, notes, and snippets.

View clodal's full-sized avatar

clodal clodal

View GitHub Profile
@clodal
clodal / _plugin.js
Created January 20, 2017 03:23
Create jQuery plugin via prototype inheritance
/**
* Generate a jQuery plugin
* @param {String} name - Plugin name
* @param {{}} object - Class of the plugin
*
* @example
* import setPlugin from 'plugin';
*
* /// 1. Design an object representing the concept/behaviours to model
* // @type {{}}
@clodal
clodal / 1A_ajax_via_serializeArray.js
Created March 27, 2017 06:52
Yii ajax post to php
return $.ajax({
context: this,
type: 'post',
dataType: 'json',
url: this.$element.attr('action'),
data: $form.serializeArray(), // send data as a serialized array
});
@clodal
clodal / Bar.js
Created June 7, 2018 10:27
React Unit Tests: Jest + Enzyme Basic Patterns
import React from 'react'
import { Icon, Button, Segment } from 'semantic-ui-react'
class Bar extends React.Component {
state = {
isCool: false,
}
toggleCool = () => this.setState({ isCool: !this.state.isCool })
render() {
const { isCool } = this.state
@clodal
clodal / log.md
Last active July 23, 2018 07:12
Sequelize + Postgres DateTime UTC Behaviour

Sequelize v4 + Postgres DateTime UTC Behaviour

19 July 2018

  • Sequelize will save datetime with timezone in postgres.
  • Sequelize will always save datetime in UTC.
  • Sequelize will retrieve datetime based on server timezone settings.
  • Zeit Now.sh sfo1 servers are in UTC.
  • Amazon RDS us-west-1 database instances are in UTC.
  • When writing datetime to the database, sequelize will automatically convert the incoming client datetime to UTC, based on the timezone specified in sequelize.options.timezone.
  • When reading datetime from the database, sequelize will return datetime in UTC. The server or client is expected to be responsible for formatting this datetime back to the user's locale.

Deploying an AWS Elastic Beanstalk NodeJS instance

The following is a set of processes outlining my usual AWS workflow with elasticbeanstalk, rds and vpc

  1. Create eb application on aws console (Select Webserver -> NodeJS)
  2. Create eb environment with $ eb init --profile=<PROFILE_NAME>
  3. Select application
  4. Do $ eb deploy
  5. Update eb config:
    • nodejs v8.11.1
    • environment type: load balanced
@clodal
clodal / postgres-commands.md
Last active August 24, 2018 02:41
Postgres Commands

Postgres Dump & Restore Database

pg_dump -h <DB_HOSTNAME> -U <DB_USERNAME> -f dump.sql <DB_NAME>

pg_restore -d <DB_NAME> <DUMP_FILE>
// OR
psql -d <DB_NAME> -f <DUMP_FILE>
@clodal
clodal / aws-rds.md
Last active August 1, 2018 04:17
AWS RDS Tips

How to drop RDS database?

  1. Connect to remote psql shell psql --host=<DB_HOST> --port=5432 --username=<DB_USER> --dbname=postgres
  2. Enter db password if prompted
  3. DROP DATABASE <DB_NAME>;
  4. CREATE DATABASE <DB_NAME>;

Note: This assumes AWS VPC does not block the connection. Check to ensure that you have access through this port.

@clodal
clodal / styled-components-ssr.md
Created August 3, 2018 06:13
Debug notes on: Getting styled-components to play nice with downstream isomorphic project when importing from an npm library
@clodal
clodal / sequelize-max-connections-debug-notes.md
Created August 15, 2018 15:09
Debug notes on sequelize max-connections issue

Debug Notes for Sequelize + PG max connections issue

The following are commands useful for debugging pool connections in a sequelize + pg setup:


Connect to local psql shell psql -d <DB_NAME>

Connect to remote psql shell psql --host= --port=5432 --username= --dbname=

➜ prod git:(master) ✗ now logs https://prod-lmnssdtqy.now.sh/ -n 100000 2018-08-19T07:20:11.692Z Mongoose: answers.find({ state: 'approved', question: ObjectId("5b5ead64528708004d570fd4") }, { fields: {} }) 2018-08-19T07:20:11.721Z Mongoose: answers.find({ state: 'approved', question: ObjectId("5b5eb95f528708004d571036") }, { fields: {} }) 2018-08-19T07:20:11.748Z Mongoose: answers.find({ state: 'approved', question: ObjectId("5b5ed47a528708004d571078") }, { fields: {} }) 2018-08-19T07:20:11.776Z Mongoose: answers.find({ state: 'approved', question: ObjectId("5b5ed56f528708004d571079") }, { fields: {} }) 2018-08-19T07:20:11.803Z Mongoose: answers.find({ state: 'approved', question: ObjectId("5b5ee267528708004d5710b0") }, { fields: {} }) 2018-08-19T07:20:11.831Z Mongoose: answers.find({ state: 'approved', question: ObjectId("5b5ee86e528708004d5710ba") }, { fields: {} }) 2018-08-19T07:20:11.858Z Mongoose: answers.find({ state: 'approved', question: ObjectId("5b5ef2c1528708004d5710c7") }, { fields: {} })