Skip to content

Instantly share code, notes, and snippets.

View fuxingloh's full-sized avatar
🦆
Quack

Fuxing Loh fuxingloh

🦆
Quack
View GitHub Profile
@fuxingloh
fuxingloh / Image.md
Last active October 14, 2021 01:08
A list of minimal effort image storage, transformation and delivery.

Minimal effort image storage, transformation and delivery.

IaaS

  • Storage: You upload to S3
  • Delivery + Transformation: CloudFront -> API Gateway -> Lambda (Node, Sharp/Thumbor) -> S3
  • CloudFormation: 1 click and fill up some fields.
  • Only predefined S3 Bucket, no dynamic bucket routing.
  • Transformation is encoded into Base64 that can be generated by anyone. You can add Signed URL but it's quite troublesome.
@fuxingloh
fuxingloh / ProceduralGenerationModification.md
Last active February 2, 2020 10:10
An idea on procedural content generation for games with alteration/grieving/modification.

History

Basically the game No Man's Sky UPS was a world with infinite possibility. I was very excited about the release of such a game because it created new possibility in games and might even inspire some one to do it better. The game flopped on release but the concept was unique, I was excited of what's to come. Fast forward 3 years later, still very little innovation in such genre.

Two incident caught my attention recently, Minecraft 2b2t and Sky Citizen.

Minecraft 2b2t server is a good example of maintaining a world with infinite possibility. 4000 GB of data, and <100 players can be on it at a time.

@fuxingloh
fuxingloh / HorizontalSnapWidget.dart
Created January 16, 2020 07:18
Flutter horizontal snap widget with sampleBuilder to estimate the height of widget because widget height is dynamically generated.
import 'package:flutter/widgets.dart';
class HorizontalSnapWidget extends StatelessWidget {
final WidgetBuilder sampleBuilder;
final IndexedWidgetBuilder itemBuilder;
final int itemCount;
final double itemWidth;
final int initialPage;
final double spacing;
export const Day = {
mon: {
text: "Monday", isToday() {
return Day.isToday(Day.mon)
}
},
tue: {
text: "Tuesday", isToday() {
return Day.isToday(Day.tue)
}
const R = 6371; // Radius of the earth in km
function deg2rad(deg) {
return deg * (Math.PI / 180)
}
/**
*
* @param latLng1
* @param latLng2
@fuxingloh
fuxingloh / UICollectionViewFlowLayoutSnapping.swift
Last active January 14, 2020 14:00
UI collection view flow layout snapping.
//
// Created by Fuxing Loh on 2019-03-07.
// Copyright (c) 2019 Munch Technologies. All rights reserved.
//
import Foundation
import UIKit
class UICollectionViewFlowLayoutSnapping: UICollectionViewFlowLayout {
override func targetContentOffset(forProposedContentOffset proposedContentOffset: CGPoint, withScrollingVelocity velocity: CGPoint) -> CGPoint {
// Page width used for estimating and calculating paging.
@fuxingloh
fuxingloh / example.vue
Created January 13, 2020 16:00
A plugin for nuxtjs, changing browser url without overwriting query string or path.
<script>
export default {
mounted() {
// Replace place without changing querystring
this.$path.replace({path: '/path-name'})
// Replace query string without changing path
this.$path.replace({query: {'foo': 'bar'}})
}
}
@fuxingloh
fuxingloh / EntityPatcher.java
Last active December 25, 2019 17:58
How to patch entity in JPA Persistence. Json & RESTful API.
import com.fasterxml.jackson.databind.JsonNode;
import dev.fuxing.utils.JsonUtils;
import javax.persistence.EntityManager;
import javax.persistence.LockModeType;
import java.util.function.Consumer;
/**
* Created by: Fuxing
*/
@fuxingloh
fuxingloh / EnumValidator.java
Created June 25, 2019 19:13
Java Enum, @ValidEnum with Constraint that supports JsonIgnoreProperties if not registered. Basically: how to handle unknown enum values in swift & java.
import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
/**
* Created by: Fuxing
*/
public class EnumValidator implements ConstraintValidator<ValidEnum, Enum> {
@Override
public boolean isValid(Enum value, ConstraintValidatorContext context) {
if (value == null) return false;
@fuxingloh
fuxingloh / PostPatch.java
Created April 22, 2019 09:24
Don't build: Use Intellij
@Test
void patch() {
AirtableRecord record = new AirtableRecord();
record.putField("Name", TEST_NAME);
record = table.post(record);
record = new AirtableRecord();
record.setId(record.getId());
record.putField("Integer", "42");
record = table.patch(record, true);