Skip to content

Instantly share code, notes, and snippets.

View ChunAllen's full-sized avatar

Allen Chun ChunAllen

  • Singapore
View GitHub Profile
@ChunAllen
ChunAllen / make.log
Created February 22, 2024 03:22
Error on installation ruby-3.0.1 using rvm
+__rvm_make:0> make -j10
BASERUBY = /Users/allenchun/.rvm/rubies/ruby-3.2.2/bin/ruby --disable=gems
CC = gcc -fdeclspec
LD = ld
LDSHARED = gcc -fdeclspec -dynamiclib
CFLAGS = -O3 -I/opt/homebrew/opt/libyaml/include -I/opt/homebrew/opt/libksba/include -I/opt/homebrew/opt/readline/include -I/opt/homebrew/opt/zlib/include -I/opt/homebrew/opt/openssl@1.1/include -fno-common -pipe -m64
XCFLAGS = -D_FORTIFY_SOURCE=2 -fstack-protector-strong -fno-strict-overflow -fvisibility=hidden -DRUBY_EXPORT -I. -I.ext/include/arm64-darwin23 -I./include -I. -I./enc/unicode/12.1.0
CPPFLAGS = -D_XOPEN_SOURCE -D_DARWIN_C_SOURCE -D_DARWIN_UNLIMITED_SELECT -D_REENTRANT
DLDFLAGS = -L/opt/homebrew/opt/libyaml/lib -L/opt/homebrew/opt/libksba/lib -L/opt/homebrew/opt/readline/lib -L/opt/homebrew/opt/zlib/lib -L/opt/homebrew/opt/openssl@1.1/lib -Wl,-undefined,dynamic_lookup -install_name /Users/allenchun/.rvm/rubies/ruby-3.0.1/lib/libruby.3.0.dylib -compatibility_version 3.0 -current_version 3.0.1 -fstack-protector-strong -fram
@ChunAllen
ChunAllen / Unit Test for Model
Last active January 26, 2024 08:00
Unit Test Ruby on Rails app with RSpec
RSpec.describe Event, type: :model do
describe "validations" do
let(:event) { build(:event) }
it { should validate_presence_of(:title) }
it { should validate_presence_of(:category) }
it { should validate_presence_of(:location) }
it { should validate_presence_of(:start_date) }
it { should validate_presence_of(:end_date) }
it { should validate_presence_of(:status) }
@ChunAllen
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
function:
foo:
handler: index.handler
# Ways to reference function in serverless.yml
FunctionName: !Sub arn:aws:lambda:${AWS::Region}:${AWS::AccountId}:function:${self:service.name}-${self:provider.stage}-foo
FunctionName: !GetAtt FooLambdaFunction.Arn
FunctionName: !Sub "${AWS::StackName}-foo"
FunctionName: ${self:service.name}-${self:provider.stage}-foo
@ChunAllen
ChunAllen / gist:d7d5be86c1516966bdaa7dd2b4151970
Last active August 1, 2022 05:45
Encrypting RSAOAEP256 password
// 1) Import this forge.min.js from browser console
var script = document.createElement('script');script.src = "https://cdnjs.cloudflare.com/ajax/libs/forge/1.3.1/forge.min.js";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();
encrypt.setPublicKey(publicKey);
@ChunAllen
ChunAllen / index.js
Created April 29, 2022 04:31
Importing CSV to DynamoDB table
const fs = require('fs')
const parse = require('csv-parse/lib/sync')
const AWS = require('aws-sdk')
var credentials = new AWS.SharedIniFileCredentials({ profile: '<aws-profile>' });
AWS.config.update({
region: 'ap-southeast-1',
credentials: credentials
});
@ChunAllen
ChunAllen / S3.txt
Last active July 29, 2021 11:07
AWS CLI Commands
// 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 March 9, 2021 04:29
Restarting Puma and Delayed Job Workers
#!/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 June 1, 2020 07:59
Uploading to npm packages to private registry
  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 September 20, 2022 16:50
Encryption using AES-256-CBC with Rails
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 April 10, 2019 10:26 — forked from DreaMinder/A Nuxt.js VPS production deployment.md
Deployment manual for a real-world project built with nuxt.js + koa + nginx + pm2

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: