Skip to content

Instantly share code, notes, and snippets.

View sotheavuthnguon's full-sized avatar

sotheavuthnguon

View GitHub Profile
@sotheavuthnguon
sotheavuthnguon / HTTPStatusCode.swift
Created July 15, 2023 02:30 — forked from ollieatkinson/HTTPStatusCode.swift
HTTP status codes as a Swift enum.
/// This is a list of Hypertext Transfer Protocol (HTTP) response status codes.
/// It includes codes from IETF internet standards, other IETF RFCs, other specifications, and some additional commonly used codes.
/// The first digit of the status code specifies one of five classes of response; an HTTP client must recognise these five classes at a minimum.
enum HTTPStatusCode: Int, Error {
/// The response class representation of status codes, these get grouped by their first digit.
enum ResponseType {
/// - informational: This class of status code indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
case informational
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
@sotheavuthnguon
sotheavuthnguon / UIViewPropertyAnimator.swift
Created April 11, 2021 11:15 — forked from marmelroy/UIViewPropertyAnimator.swift
A quick example of UIViewPropertyAnimator
// Create a UIViewPropertyAnimator object. Here's a simple one with a UIKit animation curve:
let colorChange = UIViewPropertyAnimator(duration: 0.3, curve: .easeIn, animations: { [weak self] in
self?.view.backgroundColor = UIColor(red: 255.0/255.0, green: 80.0/255.0, blue: 43.0/255.0, alpha: 1.0)
})
// There's also support for easy spring-based animations - all you need to set is a damping ratio (a value between 0 and 1). Alternatively, you can create your own curves by adopting the UITimingCurveProvider protocol.
let alphaChange = UIViewPropertyAnimator(duration: 0.3, dampingRatio: 0.6, animations: { [weak self] in
self?.circleView.alpha = 0.0
})
@sotheavuthnguon
sotheavuthnguon / String+CheckEmoji.swift
Created April 10, 2021 09:48 — forked from krummler/String+CheckEmoji.swift
Emoji checking, with some legacy code
import Foundation
extension UnicodeScalar {
/// Note: This method is part of Swift 5, so you can omit this.
/// See: https://developer.apple.com/documentation/swift/unicode/scalar
var isEmoji: Bool {
switch value {
case 0x1F600...0x1F64F, // Emoticons
0x1F300...0x1F5FF, // Misc Symbols and Pictographs
0x1F680...0x1F6FF, // Transport and Map
import Foundation
import Reachability
//Reachability
//declare this property where it won't go out of scope relative to your listener
fileprivate var reachability: Reachability!
protocol ReachabilityActionDelegate {
func reachabilityChanged(_ isReachable: Bool)
class ReachabilityHandler: ReachabilityObserverDelegate {
//MARK: Lifecycle
required init() {
try? addReachabilityObserver()
}
deinit {
removeReachabilityObserver()
@sotheavuthnguon
sotheavuthnguon / Reachability.swift
Created February 7, 2021 15:58 — forked from saeid-rez/Reachability.swift
Network Reachability class in swift 4
import Foundation
import SystemConfiguration
class Reachability
{
var hostname: String?
var isRunning = false
var isReachableOnWWAN: Bool
var reachability: SCNetworkReachability?
var reachabilityFlags = SCNetworkReachabilityFlags()
/**
* Copyright (c) 2017 Razeware LLC
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
@sotheavuthnguon
sotheavuthnguon / theme.swift
Created February 7, 2021 15:40 — forked from arx8x/theme.swift
Theme, ThemeManager, Themeable
//
// Theme.swift
// SHSH Host
//
// Created by ninja on 31/12/19.
// Copyright © 2019 arx8x.net. All rights reserved.
//
import UIKit