Skip to content

Instantly share code, notes, and snippets.

View bduyng's full-sized avatar

Duy Bao Nguyen bduyng

View GitHub Profile
@bduyng
bduyng / book-animation.tsx
Created November 17, 2025 15:31
# 3D Book Flip Animation — Conceptual Explanation This gist describes the animation logic behind a lightweight **3D book-flip effect** created using **Expo + React Native Reanimated**. Although everything is made of flat 2D views, the animation produces a convincing 3D illusion by rotating pages around a simulated **inner spine cylinder**.
import Slider from '@react-native-community/slider';
import type React from 'react';
import { useEffect } from 'react';
import { Dimensions, type StyleProp, Text, View, type ViewStyle } from 'react-native';
import 'react-native-reanimated';
import Animated, {
Extrapolation,
interpolate,
type SharedValue,
useAnimatedStyle,
@bduyng
bduyng / String+fromNow.swift
Created March 16, 2016 09:58
Extension of String to convert timestamp string into "from now" version
extension String {
func fromNow() -> String {
guard Double(self) != nil else {
return "Invalid Date"
}
let from = NSDate(timeIntervalSince1970: Double(self)!)
let now = NSDate()
let cal = NSCalendar.currentCalendar()
@bduyng
bduyng / UIColor+Hex.swift
Last active March 16, 2016 09:54
Extension of UIColor that support HEX color which also included alpha value
extension UIColor {
class func hex(string: String) -> UIColor {
var hex = string.hasPrefix("#")
? String(string.characters.dropFirst())
: string
guard hex.characters.count == 3 || hex.characters.count == 6 || hex.characters.count == 8
else { return UIColor.whiteColor().colorWithAlphaComponent(0.0) }
if hex.characters.count == 3 {