Skip to content

Instantly share code, notes, and snippets.

Avatar
🏡
Working from Home

Allen Chun ChunAllen

🏡
Working from Home
View GitHub Profile
@ChunAllen
ChunAllen / S3.txt
Last active Jul 29, 2021
AWS CLI Commands
View S3.txt
// Download object from S3
aws s3api get-object --bucket {{bucket_name}} --key {{object_from_s3.zip}} {{downloaded_file_name.zip}}
// Upload object to S3
aws s3api put-object --bucket {{bucket_name}} --key {{file_name}} --body {{actual_file}}
// Delete object from S3
aws s3api delete-object --bucket {{bucket_name}} --key {{file_name}}
@ChunAllen
ChunAllen / restart-delayed-job
Created Mar 9, 2021
Restarting Puma and Delayed Job Workers
View restart-delayed-job
#!/bin/bash
project="myapp"
echo "Restarting Background Workers"
cd /srv/www/$project/current/
RAILS_ENV=uat bin/delayed_job restart -n 5
@ChunAllen
ChunAllen / Readme.md
Created Jun 1, 2020
Uploading to npm packages to private registry
View Readme.md
  1. Download all packages normally from npm or yarn
  2. Install https://www.npmjs.com/package/node-tgz-downloader to download all the tarballs associated your package-lock.json
  3. Command is download-tgz package-lock package-lock.json this will generate a tarballs/ in the root of your project
  4. Upload the tgz to your private registry by defining first the .npmrc
  5. Run the script ./npmimport.sh to upload all the tarballs
@ChunAllen
ChunAllen / crypt.rb
Last active Mar 26, 2020
Encryption using AES-256-CBC with Rails
View crypt.rb
module Crypt
class << self
ENCRYPTION_KEY = Rails.application.secrets[:encryption_key]
ALGO = 'aes-256-cbc'.freeze
def encrypt(value)
crypt(:encrypt, value)
end
@ChunAllen
ChunAllen / A Nuxt.js VPS production deployment.md
Created Apr 10, 2019 — forked from DreaMinder/A Nuxt.js VPS production deployment.md
Deployment manual for a real-world project built with nuxt.js + koa + nginx + pm2
View A Nuxt.js VPS production deployment.md

Example of deployment process which I use in my Nuxt.js projects. I usually have 3 components running per project: admin-panel SPA, nuxt.js renderer and JSON API.

This manual is relevant for VPS such as DigitalOcean.com or Vultr.com. It's easier to use things like Now for deployment but for most cases VPS gives more flexebillity needed for projects bigger than a landing page.

UPD: This manual now compatible with nuxt@2.3. For older versions deployment, see revision history.


Let's assume that you have entered fresh installation of Ubuntu instance via SSH. Let's rock:

@ChunAllen
ChunAllen / userAvatar.js
Created Nov 22, 2018 — forked from SylarRuby/userAvatar.js
NodeJs AWS S3 Upload
View userAvatar.js
/**
* This gist was inspired from https://gist.github.com/homam/8646090 which I wanted to work when uploading an image from
* a base64 string.
* This code is used in my startup, Zired.
* Web: http://zired.io
*/
// You can either "yarn add aws-sdk" or "npm i aws-sdk"
const AWS = require('aws-sdk')
@ChunAllen
ChunAllen / express-server-side-rendering.md
Created Jun 24, 2018 — forked from joepie91/express-server-side-rendering.md
Rendering pages server-side with Express (and Pug)
View express-server-side-rendering.md

Terminology

  • View: Also called a "template", a file that contains markup (like HTML) and optionally additional instructions on how to generate snippets of HTML, such as text interpolation, loops, conditionals, includes, and so on.
  • View engine: Also called a "template library" or "templater", ie. a library that implements view functionality, and potentially also a custom language for specifying it (like Pug does).
  • HTML templater: A template library that's designed specifically for generating HTML. It understands document structure and thus can provide useful advanced tools like mixins, as well as more secure output escaping (since it can determine the right escaping approach from the context in which a value is used), but it also means that the templater is not useful for anything other than HTML.
  • String-based templater: A template library that implements templating logic, but that has no understanding of the content it is generating - it simply concatenates together strings, potenti
@ChunAllen
ChunAllen / webpack.config.js
Created Jun 12, 2018 — forked from learncodeacademy/webpack.config.js
Sample Basic Webpack Config
View webpack.config.js
var debug = process.env.NODE_ENV !== "production";
var webpack = require('webpack');
module.exports = {
context: __dirname,
devtool: debug ? "inline-sourcemap" : null,
entry: "./js/scripts.js",
output: {
path: __dirname + "/js",
filename: "scripts.min.js"
View Backup, restore postgres in docker container
Backup:
docker exec -t -u postgres your-db-container pg_dumpall -c > dump_`date +%d-%m-%Y"_"%H_%M_%S`.sql
Restore:
cat your_dump.sql | docker exec -i your-db-container psql -Upostgres
@ChunAllen
ChunAllen / autopgsqlbackup
Created Feb 21, 2018 — forked from matthewlehner/autopgsqlbackup
Auto PostgreSQL backup script.
View autopgsqlbackup
#!/bin/bash
#
# PostgreSQL Backup Script Ver 1.0
# http://autopgsqlbackup.frozenpc.net
# Copyright (c) 2005 Aaron Axelsen <axelseaa@amadmax.com>
#
# This script is based of the AutoMySQLBackup Script Ver 2.2
# It can be found at http://sourceforge.net/projects/automysqlbackup/
#
# The PostgreSQL changes are based on a patch agaisnt AutoMySQLBackup 1.9