Skip to content

Instantly share code, notes, and snippets.

@peterfriese
peterfriese / Color+Codable.swift
Created March 19, 2021 11:00
Making Swift's Color codable
//
// Color+Codable.swift
// FirestoreCodableSamples
//
// Created by Peter Friese on 18.03.21.
//
import SwiftUI
// Inspired by https://cocoacasts.com/from-hex-to-uicolor-and-back-in-swift
@echo off
title Activate Office 365 ProPlus for FREE - MSGuides.com&cls&echo ============================================================================&echo #Project: Activating Microsoft software products for FREE without software&echo ============================================================================&echo.&echo #Supported products: Office 365 ProPlus (x86-x64)&echo.&echo.&(if exist "%ProgramFiles%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles%\Microsoft Office\Office16")&(if exist "%ProgramFiles(x86)%\Microsoft Office\Office16\ospp.vbs" cd /d "%ProgramFiles(x86)%\Microsoft Office\Office16")&(for /f %%x in ('dir /b ..\root\Licenses16\proplusvl_kms*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul)&(for /f %%x in ('dir /b ..\root\Licenses16\proplusvl_mak*.xrm-ms') do cscript ospp.vbs /inslic:"..\root\Licenses16\%%x" >nul)&echo.&echo ============================================================================&echo Activating your Office...&cscript //nologo slmgr.vbs /ck
@oxlb
oxlb / xcode-uninstall.sh
Created July 23, 2020 06:25
SH file to uninstall Xcode from MacOS
killall Xcode
xcrun -k
xcodebuild -alltargets clean
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang/ModuleCache"
rm -rf "$(getconf DARWIN_USER_CACHE_DIR)/org.llvm.clang.$(whoami)/ModuleCache"
rm -rf /Applications/Xcode.app
rm -rf ~/Library/Caches/com.apple.dt.Xcode
rm -rf ~/Library/Developer
rm -rf ~/Library/MobileDevice
rm -rf ~/Library/Preferences/com.apple.dt.Xcode.plist
@vinaywadhwa
vinaywadhwa / adb_wifi_connect_all.sh
Created December 27, 2019 06:59
Android Debug Bridge (adb) Wireless Debugging Over Wi-Fi - Switch on wifi debugging in ALL devices connected (via USB, with USB debugging enabled) to your computer (tested on Mac OS)
for line in `adb devices | grep -v "List" |grep -v ":" | awk '{print $1}'`
do
device=`echo $line | awk '{print $1}'`
echo "Running commands for $device"
echo "Restarting $device in TCP mode on port 5555..."
adb -s "$device" tcpip 5555
echo "Waiting for $device to switch to TCP mode..."
sleep 7
ip_addr=$(adb -s "$device" shell ip route | grep wlan| grep -o ' 192.*$' | awk '{print $1":5555"}')
echo "Connecting to Device via WIFI on $ip_addr"
@yusuke024
yusuke024 / ViewController.swift
Created November 16, 2018 03:15
Recording video with AVAssetWriter
import UIKit
import AVFoundation
class ViewController: UIViewController {
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
switch AVCaptureDevice.authorizationStatus(for: .video) {
case .notDetermined:
enum Foo: String, Codable {
case a
case b
case c
}
extension RawRepresentable where RawValue == String, Self: Codable {
init(from decoder: Decoder) throws {
var container = try decoder.unkeyedContainer()
let rawValue = try container.decode(String.self)
@SeanLintern
SeanLintern / gist:3a78b3b40ee25561eb46f4e2044f5d26
Created April 28, 2017 14:17
AVCaptureAudioDataOutput Demo
import UIKit
import AVKit
import AVFoundation
import AssetsLibrary
func synchronized(_ object: AnyObject, block: () -> Void) {
objc_sync_enter(object)
block()
objc_sync_exit(object)
}
@ivanbruel
ivanbruel / SnakeCase.swift
Last active March 19, 2023 16:42
Camel case to snake case in Swift
extension String {
func snakeCased() -> String? {
let pattern = "([a-z0-9])([A-Z])"
let regex = try? NSRegularExpression(pattern: pattern, options: [])
let range = NSRange(location: 0, length: self.characters.count)
return regex?.stringByReplacingMatches(in: self, options: [], range: range, withTemplate: "$1_$2").lowercased()
}
}
@axldyb
axldyb / UIImage crop to square
Created April 29, 2015 09:42
Extension for cropping an UIImage to a square.
extension UIImage {
func cropsToSquare() -> UIImage {
let refWidth = CGFloat(CGImageGetWidth(self.CGImage))
let refHeight = CGFloat(CGImageGetHeight(self.CGImage))
let cropSize = refWidth > refHeight ? refHeight : refWidth
let x = (refWidth - cropSize) / 2.0
let y = (refHeight - cropSize) / 2.0
let cropRect = CGRectMake(x, y, cropSize, cropSize)
@cjaoude
cjaoude / gist:fd9910626629b53c4d25
Last active July 22, 2024 11:08
Test list of Valid and Invalid Email addresses
Use: for testing against email regex
ref: http://codefool.tumblr.com/post/15288874550/list-of-valid-and-invalid-email-addresses
List of Valid Email Addresses
email@example.com
firstname.lastname@example.com
email@subdomain.example.com
firstname+lastname@example.com