Skip to content

Instantly share code, notes, and snippets.

View clodal's full-sized avatar

clodal clodal

  • Singapore
View GitHub Profile
@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>

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 / 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.
@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 / 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 / _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 {{}}