Skip to content

Instantly share code, notes, and snippets.

View caophuocthanh's full-sized avatar
🐢
More better

Cao Phuoc Thanh caophuocthanh

🐢
More better
View GitHub Profile
@caophuocthanh
caophuocthanh / UIHoverView.swift
Created September 12, 2024 16:52
UIHoverView
//
// ColorButtonView.swift
// MenuPopover
//
// Created by Cao Phuoc Thanh on 31/12/2020.
// Copyright © 2020 Cao Phuoc Thanh. All rights reserved.
//
import UIKit
import UIKit
import AVFoundation
import Photos
import MobileCoreServices
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
startVideoToGIFProcess()
@caophuocthanh
caophuocthanh / DateFormatter.swift
Created August 19, 2023 09:24 — forked from yycking/DateFormatter.swift
list DateFormatter result
import Cocoa
extension DateFormatter.Style {
static public var allCases: [DateFormatter.Style] = [
.none,
.short,
.medium,
.long,
.full,
]
import Combine
import UIKit
public protocol CombineCompatible {}
// MARK: - UIControl
public extension UIControl {
final class Subscription<SubscriberType: Subscriber, Control: UIControl>: Combine.Subscription where SubscriberType.Input == Control {
private var subscriber: SubscriberType?
private let input: Control
@caophuocthanh
caophuocthanh / Combine+Publisher+weakAssign.swift
Last active May 29, 2023 03:19
Conbine Publisher weakAssign
extension Publisher where Failure == Never {
func weakAssign<T: AnyObject>(
to keyPath: ReferenceWritableKeyPath<T, Output>,
on object: T
) -> AnyCancellable {
sink { [weak object] value in
object?[keyPath: keyPath] = value
}
}
}
// Run from the dev tools console of any Youtube video
// Accurate as of July 2, 2020.
//
// Copy and paste this into the dev console in a browser with the desired video loaded.
//
// NOTE: Some Youtube videos do not directly expose the video url in the response.
// This script doesn't currently attempt to handle those. It will work for most other general video types though.
(async () => {
const html = await fetch(window.location.href).then((resp) => resp.text()).then((text) => text);
// MARK: CustomLayoutInvalidationContext
class CustomLayoutInvalidationContext: UICollectionViewLayoutInvalidationContext {
var invalidatedBecauseOfBoundsChange: Bool = false
}
// MARK: CustomCollectionViewLayout
class CustomCollectionViewLayout: UICollectionViewLayout {
private enum ContentUpdateValue{
case fixed(value: CGFloat)
@caophuocthanh
caophuocthanh / node-folder-structure-options.md
Created June 20, 2018 04:06 — forked from lancejpollard/node-folder-structure-options.md
What is your folder-structure preference for a large-scale Node.js project?

What is your folder-structure preference for a large-scale Node.js project?

0: Starting from Rails

This is the reference point. All the other options are based off this.

|-- app
|   |-- controllers
|   |   |-- admin
@caophuocthanh
caophuocthanh / Node_AWS_Linux.md
Created July 20, 2017 15:15 — forked from nrollr/Node_AWS_Linux.md
Install Node.js on Amazon Linux (EC2)

##Installing Node.js on Amazon Linux AMI

The following will guide you through the process of installing Node.js on an AWS EC2 instance running Amazon Linux AMI 2016.09 - Release Notes

For this process I'll be using a t2.micro EC2 instance running Amazon Linux AMI (ami-d41d58a7). Once the EC2 instance is up-and-running, connect to your server via ssh

@caophuocthanh
caophuocthanh / install-redis.sh
Created April 27, 2017 05:36 — forked from FUT/install-redis.sh
Install Redis on EC2
1. Install Linux updates, set time zones, followed by GCC and Make
sudo yum -y update
sudo ln -sf /usr/share/zoneinfo/America/Indianapolis \
/etc/localtime
sudo yum -y install gcc make
2. Download, Untar and Make Redis 2.8 (check here http://redis.io/download)