Skip to content

Instantly share code, notes, and snippets.

@sjlu
sjlu / Migrating from Amazon Linux to Amazon Linux 2 with Elastic Beanstalk and Node.js.md
Last active September 12, 2023 08:56
Migrating from Amazon Linux to Amazon Linux 2 with Elastic Beanstalk and Node.js

This file is a log of everything I've encountered when trying to migrate a Node.js, Elastic Beanstalk application from the Amazon Linux platform to the Amazon Liunx 2 platform. Here's why you should migrate:

  1. LTS support up to 2023 source
  2. The Amazon Linux AMI's end-of-life is December, 2020 source
  3. Amazon Linux 2 has some big package upgrades (GCC, Glibc, etc.)
  4. Elastic Beanstalk also has some upgrades on top of Amazon Linux 2 (e.g. faster deploys)

Challenges

Disabling NPM install

@sjlu
sjlu / Contentful.js
Last active June 3, 2019 19:44
This helps compile Jekyll posts from Contentful
var Promise = require('bluebird')
var _ = require('lodash')
var fs = require('fs')
var contentful = require('contentful')
var client = contentful.createClient({
space: '0eybfmw2qkbf',
accessToken: process.env.CONTENTFUL_ACCESS_TOKEN,
host: process.env.CONTENTFUL_HOST
})
@sjlu
sjlu / metabase
Created March 15, 2018 21:15
metabase init.d
#!/bin/sh
# /etc/init.d/metabase
### BEGIN INIT INFO
# Provides: Metabase
# Required-Start: $local_fs $network $named $time $syslog
# Required-Stop: $local_fs $network $named $time $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: Metabase analytics and intelligence platform
### END INIT INFO
0xbD08E418EB33ecC56b2234d860397f77143cD2F3
return request({
method: 'POST',
url: 'https://api.fastly.com/service/' + main.SERVICE_ID + '/version/' + this.number + '/vcl',
headers: {
'Fastly-Key': main.API_KEY
},
form: {
name: 'gulp-fastly-uploaded-vcl',
file: encodeURIComponent(String(file.contents))
}
@sjlu
sjlu / notes.md
Created October 19, 2015 16:52
CircleCI with automated Docker builds

CircleCI Docker Integration

Grab a service account API credential as a JSON file

cat .json | base64 | pbcopy

Add the following environment variables

GCE_URL
@sjlu
sjlu / notes.md
Created October 19, 2015 16:51
Kubernetes and Google Container Engine cheatsheet

Setting project:

gcloud config set project tidy-bindery-110323

Creating a cluster:

gcloud container clusters create web --num-nodes=1 --machine-type=g1-small --zone=us-east1-b
@sjlu
sjlu / Dockerfile
Created October 19, 2015 16:49
Dockerfile into installing Node.js from a compiled source
# Install base OS
FROM ubuntu:14.04
# Author
MAINTAINER Steven Lu <tacticalazn@gmail.com>
# Installing base packages that we need
# to run node with along with our code
RUN apt-get update && apt-get install -y --force-yes --no-install-recommends \
build-essential \
@sjlu
sjlu / coreos.json
Created October 19, 2015 14:15
CoreOS CloudFormation that includes its own VPC mapping
{
"Mappings": {
"RegionMap": {
"eu-central-1": {
"AMI": "ami-840a0899"
},
"ap-northeast-1": {
"AMI": "ami-6c5ac56c"
},
"us-gov-west-1": {

Lets take an example where we have to load a dyanmic set of files. Normally we would have to iterate through the array, grab one file, then the next, etc. PHP is a good example of this and it'd take it a really long time to access each file since the computer's disk is slower than the CPU. This is what we call I/O wait.

$files = array("file1.txt", "file2.txt")
for ($i = 0; $i < count($files); $i++) {
  $fh = fopen($myFile, 'r');