Skip to content

Instantly share code, notes, and snippets.

@peterdee
peterdee / default.conf
Created December 11, 2019 07:09
NGiNX Configuration for Vue-Router in HTML5 Mode
server {
listen 80 default_server;
listen [::]:80 default_server;
root /your/root/path;
index index.html;
server_name you.server.com;
@peterdee
peterdee / terminal-git-branch-name.md
Last active November 14, 2019 07:27 — forked from joseluisq/terminal-git-branch-name.md
Add Git Branch Name to Terminal Prompt (Mac)

Add Git Branch Name to Terminal Prompt (Mac)

image

Open ~/.bash_profile in your favorite editor and add the following content to the bottom.

# Git branch in prompt.

parse_git_branch() {
@peterdee
peterdee / state-abbreviations.json
Created October 11, 2019 07:42 — forked from 75th/state-abbreviations.json
US state abbreviations in JSON
{
"al": { "full": "alabama", "other": ["ala"] },
"ak": { "full": "alaska", "other": ["alas"] },
"az": { "full": "arizona", "other": ["ariz"] },
"ar": { "full": "arkansas", "other": ["ark"] },
"ca": { "full": "california", "other": ["calif", "cal"] },
"co": { "full": "colorado", "other": ["colo", "col"] },
"ct": { "full": "connecticut", "other": ["conn"] },
"de": { "full": "delaware", "other": ["del"] },
"dc": { "full": "district of columbia", "other": ["washington dc", "wash dc"] },
module.exports = {
up: function (queryInterface, Sequelize) {
return [
queryInterface.addColumn('User', 'name', {
type: Sequelize.STRING
}),
queryInterface.addColumn('User', 'nickname', {
type: Sequelize.STRING,
})
];
@peterdee
peterdee / node-cron-timezones.md
Created July 31, 2019 06:36
Timezones for node-cron (with offset values)
{
  "Africa/Abidjan": 0,
  "Africa/Accra": 0,
  "Africa/Addis_Ababa": -180,
  "Africa/Algiers": -60,
  "Africa/Asmara": -180,
  "Africa/Asmera": -180,
  "Africa/Bamako": 0,
  "Africa/Bangui": -60,
@peterdee
peterdee / how-to-copy-aws-rds-to-local.md
Created July 12, 2019 13:51 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored
@peterdee
peterdee / promisification.md
Created July 8, 2019 18:06
Some promisification with error handling
function createPromises(length) {
    const promises = [];
    for (let i = 0; i < length; i += 1) {
        const value = Math.random();
        promises.push(new Promise((resolve, reject) => setTimeout(() => {
            if (value < 0.1) reject('exception');
            resolve(value);
        }, value * 1000)));
 }
@peterdee
peterdee / iterators.md
Created July 8, 2019 18:04
Nested iterator
function* iterate(length) {
    for (let i = 1; i <= length; i += 1) yield i;
}

function* pow2(array) {
    for (let i in array) yield array[i] ** 2;
}

const res = [...pow2([...iterate(10)])]; // (10) [1, 4, 9, 16, 25, 36, 49, 64, 81, 100]
@peterdee
peterdee / snake-camel.md
Created July 8, 2019 17:58
Snake case to camel case for objects (no recursion)
function camel(object) {
    const keys = Object.keys(object);
    return keys.reduce((o, k) => {
        if (k.includes('_')) {
            const words = k.split('_');
            const capitalized = words.map((word, i) => {
                if (word.length > 0) {
                    const capital = i > 0 ? `${word[0].toUpperCase()}${word.substr(1)}` : word;
 return capital; 
@peterdee
peterdee / timezones
Created June 11, 2019 09:41 — forked from ykessler/timezones
JSON list of time zones (Based on Olson tz database)
[
{"group":"US (Common)",
"zones":[
{"value":"America/Puerto_Rico","name":"Puerto Rico (Atlantic)"},
{"value":"America/New_York","name":"New York (Eastern)"},
{"value":"America/Chicago","name":"Chicago (Central)"},
{"value":"America/Denver","name":"Denver (Mountain)"},
{"value":"America/Phoenix","name":"Phoenix (MST)"},
{"value":"America/Los_Angeles","name":"Los Angeles (Pacific)"},
{"value":"America/Anchorage","name":"Anchorage (Alaska)"},