Skip to content

Instantly share code, notes, and snippets.

@fuxingloh
fuxingloh / Dockerfile
Last active January 24, 2021 12:53
Nuxt.js & AWS S3 Deployment for Rolling Deployment
FROM node:8.12.0-alpine
# Installing AWS CLI
RUN apk add --no-cache --virtual .build-deps
RUN apk add bash
RUN apk add make && apk add curl && apk add openssh
RUN apk add git
RUN ln -sf /usr/share/zoneinfo/Etc/UTC /etc/localtime
RUN apk -Uuv add groff less python py-pip
RUN pip install awscli
@fuxingloh
fuxingloh / build.gradle
Created July 15, 2018 09:52
Build and publish non java docker image in gradle
version = '1.2'
// For publishing to AWS ECR
ext.dockerRegistryUrl = '_.dkr.ecr.ap-southeast-1.amazonaws.com/'
// Alternative Version to Publish
ext.dockerRegistryVersion = '1.0'
ext.dockerTag = dockerRegistryUrl + rootProject.name + '/' + project.name + ':'
task buildImage {
doLast {
@fuxingloh
fuxingloh / UILabelSize.swift
Last active March 29, 2024 07:26
iOS Swift: How to find text width, text height or size of UILabel.
extension UILabel {
func textWidth() -> CGFloat {
return UILabel.textWidth(label: self)
}
class func textWidth(label: UILabel) -> CGFloat {
return textWidth(label: label, text: label.text!)
}
class func textWidth(label: UILabel, text: String) -> CGFloat {
@fuxingloh
fuxingloh / DateFormatter.swift
Created March 25, 2018 05:30
Swift date time formatting
let inFormatter = DateFormatter()
inFormatter.dateFormat = "HH:mm"
let outFormatter = DateFormatter()
outFormatter.dateFormat = "HHmm"
"12:00".replacingOccurrences(of: ":", with: "")
let open = inFormatter.date(from: "12:00")
let open1 = outFormatter.string(from: open!)
@fuxingloh
fuxingloh / CirclePolygon.swift
Created March 25, 2018 05:30
Converting geo circle to polygon points. latLng and radius to list of latLng points
import Foundation
let d2r = Double.pi / 180.0
let r2d = 180 / Double.pi
let earthRadius = 6371.0
let lat = 1.350309
let lng = 103.848237
let radius = 1.0 // Km
let points = 10 // Points in polygon
@fuxingloh
fuxingloh / Main.java
Last active February 7, 2018 01:13
UncheckedExecutionException Guice Java 9
// How to log uncaught exception from Guice 9
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
logger.error("Uncaught Exceptions: ", e.getCause());
});
Injector injector = Guice.createInjector(new MyModule());
@fuxingloh
fuxingloh / swap.sh
Last active July 12, 2017 16:40
Adding 512MB of Swap Space on AWS AMI
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=512
sudo /sbin/mkswap /var/swap.1
sudo chmod 600 /var/swap.1
sudo /sbin/swapon /var/swap.1
sudo swapon -s
@fuxingloh
fuxingloh / artifactory.sh
Last active March 9, 2021 13:05
Install Artifactory on AWS AMI and register as service to auto start and then starts it. Test on lightsail. Register as startup script.
#!/bin/bash
# Upgrade to Java-8
sudo yum install java-1.8.0
sudo yum remove java-1.7.0-openjdk
# Installing Artifactory
wget https://bintray.com/jfrog/artifactory-rpms/rpm -O bintray-jfrog-artifactory-rpms.repo
sudo mv bintray-jfrog-artifactory-rpms.repo /etc/yum.repos.d/
sudo yum install jfrog-artifactory-oss
@fuxingloh
fuxingloh / ContentTypeError.java
Last active January 14, 2020 06:10
Read the content type of file with file contents or file name.
/**
* Created By: Fuxing Loh
* Date: 28/10/2016
* Time: 8:10 PM
* Project: munch-utils
*/
public class ContentTypeError extends Exception {
/**
* Content-Type not found
@fuxingloh
fuxingloh / Gradient.swift
Created June 23, 2017 15:17
How to add gradient on top and bottom of image view.
// Call this in layoutSubView or viewDidLoad
self.imageView.layer.sublayers?.forEach { $0.removeFromSuperlayer() }
let width = self.bounds.width
let height = self.bounds.height
let sHeight:CGFloat = 60.0
let shadow = UIColor.black.withAlphaComponent(0.6).cgColor
// Add gradient bar for image on top
let topImageGradient = CAGradientLayer()