Skip to content

Instantly share code, notes, and snippets.

@yannxou
yannxou / ForegroundTextColor.swift
Created December 23, 2020 09:55
Foreground text color based on background color #SwiftUI
// Taken from Apple's App Dev Training: https://developer.apple.com/tutorials/app-dev-training/
/// This color is either black or white, whichever is more accessible when viewed against the scrum color.
var accessibleFontColor: Color {
var red: CGFloat = 0
var green: CGFloat = 0
var blue: CGFloat = 0
UIColor(self).getRed(&red, green: &green, blue: &blue, alpha: nil)
return isLightColor(red: red, green: green, blue: blue) ? .black : .white
}
@nyx-code
nyx-code / FileUpload.js
Last active November 25, 2022 20:50
This NodeJS API which will upload files onto the AWS S3 Bucket. Video -> https://youtu.be/TtuCCfren_I
require('dotenv/config')
const express = require('express')
const multer = require('multer')
const AWS = require('aws-sdk')
const uuid = require('uuid/v4')
const app = express()
const port = 3000
@liamnichols
liamnichols / sign_in_with_apple.yml
Created February 21, 2020 14:53
Localisations of the "Sign in with Apple" string taken from Xcode 11.1
SIGN_IN_WITH_APPLE:
- de: Mit Apple anmelden
- he: התחברות באמצעות Apple
- en_AU: Sign in with Apple
- ar: تسجيل الدخول باستخدام Apple
- el: Σύνδεση μέσω Apple
- ja: Appleでサインイン
- en: Sign in with Apple
- uk: Увійти з Apple
- es_419: Iniciar sesión con Apple
@RoLYroLLs
RoLYroLLs / DeviceConstant.swift
Created December 31, 2019 19:03
A list of all Apple device names easily accessible through enums. particularly useful for PreviewProvider in Swift
//
// DeviceConstants.swift
// SampleApp
//
// Created by RoLY roLLs on 12/31/19.
// Copyright © 2019 RoLYroLLs Enterprises, LLC. All rights reserved.
//
/// Taken from https://developer.apple.com/documentation/swiftui/securefield/3289399-previewdevice
@SatoTakeshiX
SatoTakeshiX / convert.swift
Last active June 6, 2024 12:25
Take capture a view by SwiftUI
//
// ContentView.swift
// TryGeometryReader
//
// Created by satoutakeshi on 2019/12/07.
// Copyright © 2019 satoutakeshi. Licensed under MIT.
//
import SwiftUI
@shakemno
shakemno / UIColor+HumanEyePleasing.swift
Last active January 31, 2023 16:50 — forked from klein-artur/complementaryColor.swift
UIColor + HumanEyePleasing - contrasting color extension (complementary or perceptive luminance)
extension UIColor {
// get a complementary color to this color
// https://gist.github.com/klein-artur/025a0fa4f167a648d9ea
var complementary: UIColor {
let ciColor = CIColor(color: self)
// get the current values and make the difference from white:
let compRed: CGFloat = 1.0 - ciColor.red
@nbasham
nbasham / Data+Extensions.swift
Last active January 21, 2024 14:57
Get a random date between two values. Swift 4.2+ uses Random(in:).
import Foundation
extension Date {
static func randomBetween(start: String, end: String, format: String = "yyyy-MM-dd") -> String {
let date1 = Date.parse(start, format: format)
let date2 = Date.parse(end, format: format)
return Date.randomBetween(start: date1, end: date2).dateString(format)
}
@norsez
norsez / JSONSaveLoad.swift
Created May 7, 2018 04:47
Load and Save JSON objects into a local file (written in Swift)
import Foundation
/**
Extension to save/load a JSON object by filename. (".json" extension is assumed and automatically added.)
*/
extension JSONSerialization {
static func loadJSON(withFilename filename: String) throws -> Any? {
let fm = FileManager.default
@deepakpk009
deepakpk009 / media.json
Created November 8, 2017 14:02
sample free video urls
{
"categories": [
{
"name": "Movies",
"videos": [
{
"description": "Big Buck Bunny tells the story of a giant rabbit with a heart bigger than himself. When one sunny day three rodents rudely harass him, something snaps... and the rabbit ain't no bunny anymore! In the typical cartoon tradition he prepares the nasty rodents a comical revenge.\n\nLicensed under the Creative Commons Attribution license\nhttp://www.bigbuckbunny.org",
"sources": [
"http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4"
],
@hfossli
hfossli / NodeTask.swift
Last active January 2, 2024 00:27
Start a node.js server using NSTask in Swift.
import Foundation
import Cocoa
class NodeTask: NSObject {
private let processIdentifier = NSProcessInfo.processInfo().processIdentifier
private let nodeTask = NSTask()
private let readPipe = NSPipe()
private let errorPipe = NSPipe()
private let queue = dispatch_queue_create("NodeTask.output.queue", DISPATCH_QUEUE_SERIAL)