Skip to content

Instantly share code, notes, and snippets.


Allen Chun ChunAllen

  • Manila / Singapore
View GitHub Profile
ChunAllen / serverless-function-reference-formats.yml
Created November 23, 2022 03:03 — forked from DavidWells/serverless-function-reference-formats.yml
Various ways to reference function name and ARN in serverless.yml
View serverless-function-reference-formats.yml
handler: index.handler
# Ways to reference function in serverless.yml
FunctionName: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${}-${self:provider.stage}-foo
FunctionName: !GetAtt FooLambdaFunction.Arn
FunctionName: !Sub "${AWS::StackName}-foo"
FunctionName: ${}-${self:provider.stage}-foo
ChunAllen / crypt.rb
Last active September 20, 2022 16:50
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)
ChunAllen / gist:d7d5be86c1516966bdaa7dd2b4151970
Last active August 1, 2022 05:45
Encrypting RSAOAEP256 password
View gist:d7d5be86c1516966bdaa7dd2b4151970
// 1) Import this forge.min.js from browser console
var script = document.createElement('script');script.src = "";document.getElementsByTagName('head')[0].appendChild(script);
// 2) Paste this method in browser console
function encryptPassword(psd, pem) {
try {
//using jsencrypt.js
/* var encrypt = new JSEncrypt();
ChunAllen / index.js
Created April 29, 2022 04:31
Importing CSV to DynamoDB table
View index.js
const fs = require('fs')
const parse = require('csv-parse/lib/sync')
const AWS = require('aws-sdk')
var credentials = new AWS.SharedIniFileCredentials({ profile: '<aws-profile>' });
region: 'ap-southeast-1',
credentials: credentials
ChunAllen / S3.txt
Last active July 29, 2021 11:07
AWS CLI Commands
View S3.txt
// Download object from S3
aws s3api get-object --bucket {{bucket_name}} --key {{}} {{}}
// 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 / restart-delayed-job
Created March 9, 2021 04:29
Restarting Puma and Delayed Job Workers
View restart-delayed-job
echo "Restarting Background Workers"
cd /srv/www/$project/current/
RAILS_ENV=uat bin/delayed_job restart -n 5
ChunAllen /
Created June 1, 2020 07:59
Uploading to npm packages to private registry
  1. Download all packages normally from npm or yarn
  2. Install 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 ./ to upload all the tarballs
ChunAllen / gist:b2ae4349db4e134b1d547e590a5d1869
Created January 21, 2018 16:14 — forked from jrochkind/gist:2161449
A Capistrano Rails Guide
View gist:b2ae4349db4e134b1d547e590a5d1869

A Capistrano Rails Guide

by Jonathan Rochkind,

why cap?

Capistrano automates pushing out a new version of your application to a deployment location.

I've been writing and deploying Rails apps for a while, but I avoided using Capistrano until recently. I've got a pretty simple one-host deployment, and even though everyone said Capistrano was great, every time I tried to get started I just got snowed under not being able to figure out exactly what I wanted to do, and figured I wasn't having that much trouble doing it "manually".

ChunAllen / A Nuxt.js VPS production
Created April 10, 2019 10:26 — forked from DreaMinder/A Nuxt.js VPS production
Deployment manual for a real-world project built with nuxt.js + koa + nginx + pm2
View A Nuxt.js VPS production

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 or 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 / userAvatar.js
Created November 22, 2018 05:49 — forked from SylarRuby/userAvatar.js
NodeJs AWS S3 Upload
View userAvatar.js
* This gist was inspired from which I wanted to work when uploading an image from
* a base64 string.
* This code is used in my startup, Zired.
* Web:
// You can either "yarn add aws-sdk" or "npm i aws-sdk"
const AWS = require('aws-sdk')