Skip to content

Instantly share code, notes, and snippets.

View richardwei6's full-sized avatar
🤔

Richard Wei richardwei6

🤔
View GitHub Profile
func resetAllSettingsDefaults() {
let defaults = UserDefaults.standard
let dictionary = defaults.dictionaryRepresentation()
dictionary.keys.forEach { key in
defaults.removeObject(forKey: key)
}
}
extension String {
func getHeight(withConstrainedWidth width: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: width, height: .greatestFiniteMagnitude)
let boundingBox = self.boundingRect(with: constraintRect, options: .usesLineFragmentOrigin, attributes: [NSAttributedString.Key.font: font], context: nil)
return ceil(boundingBox.height)
}
func getWidth(withConstrainedHeight height: CGFloat, font: UIFont) -> CGFloat {
let constraintRect = CGSize(width: .greatestFiniteMagnitude, height: height)
#include <iostream>
using namespace std;
double dydx(double x, double y){
return x+y;
}
int main(){
double x, y, h, endX;
@richardwei6
richardwei6 / dataDeltaFinder.swift
Last active February 28, 2021 04:15
A simple class to find the delta between subsequent data variables
//
// imageDeltaFinder.swift
// Omegacam-ios
//
// Created by Richard Wei on 2/24/21.
//
import Foundation
import AVFoundation
@richardwei6
richardwei6 / multipartPacketProtocol.swift
Last active March 1, 2021 06:43
Multipart Packet implementation in Swift
//
// multipartPacketProtocol.swift
// Omegacam-ios
//
// Created by Richard Wei on 2/23/21.
//
import Foundation
class multipartPacketManager{
//
// AppUtility.swift
// AHS
//
// Created by Richard Wei.
//
import Foundation
import UIKit
struct AppUtility {
@richardwei6
richardwei6 / udpsocket.swift
Created March 8, 2021 05:53
Native Swift UDP Multicast socket using new iOS 14 network APIs
//
// udpsocket.swift
//
// Created by Richard Wei on 3/7/21.
//
import Foundation
import Network
// https://developer.apple.com/news/?id=0oi77447
@richardwei6
richardwei6 / UIColorHex.swift
Created April 4, 2021 07:11
UIColor Hex Parser
extension UIColor{
convenience init(hex: String, alpha: CGFloat = 1.0){
var hex_copy = hex;
let count = hex.count;
if (count != 6 && count != 7){
self.init();
return;
}
@richardwei6
richardwei6 / LongJumps.cpp
Created September 21, 2021 04:43
LongJumps.cpp
int solution(vector<int> a) {
int n = a.size();
vector<int> dp(n, 0); // init array of size n to 0
int mx = 0; // find max dp value
for (int i = n - 1; i > -1; i--) { // loop backwards from a
int t = a[i]; // this DP value
@richardwei6
richardwei6 / workshop.c
Last active October 17, 2021 03:21
Coding Club C Workshop 1
#include <stdio.h>
#include <stdbool.h>
#include <math.h>
int main(){
printf("Hello World\nNew line\nTest");