Skip to content

Instantly share code, notes, and snippets.

View RosayGaspard's full-sized avatar
🪐
Travelling the universe.

Gaspard Rosay RosayGaspard

🪐
Travelling the universe.
View GitHub Profile
extension CameraViewController : UIViewControllerRepresentable{
public typealias UIViewControllerType = CameraViewController
public func makeUIViewController(context: UIViewControllerRepresentableContext<CameraViewController>) -> CameraViewController {
return CameraViewController()
}
public func updateUIViewController(_ uiViewController: CameraViewController, context: UIViewControllerRepresentableContext<CameraViewController>) {
}
}
override func viewDidLoad() {
previewView = UIView(frame: CGRect(x:0, y:0, width: UIScreen.main.bounds.size.width, height: UIScreen.main.bounds.size.height))
previewView.contentMode = UIView.ContentMode.scaleAspectFit
view.addSubview(previewView)
cameraController.prepare {(error) in
if let error = error {
print(error)
}
func displayPreview(on view: UIView) throws {
guard let captureSession = self.captureSession, captureSession.isRunning else { throw CameraControllerError.captureSessionIsMissing }
self.previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)
self.previewLayer?.videoGravity = AVLayerVideoGravity.resizeAspectFill
self.previewLayer?.connection?.videoOrientation = .portrait
view.layer.insertSublayer(self.previewLayer!, at: 0)
self.previewLayer?.frame = view.frame
}
func prepare(completionHandler: @escaping (Error?) -> Void){
func createCaptureSession(){
self.captureSession = AVCaptureSession()
}
func configureCaptureDevices() throws {
let camera = AVCaptureDevice.default(.builtInWideAngleCamera, for: AVMediaType.video, position: .front)
self.frontCamera = camera
try camera?.lockForConfiguration()
@RosayGaspard
RosayGaspard / CameraController.swift
Created January 28, 2020 09:13
Simple camera controller to show the front camera in Swift
class CameraController: NSObject{
var captureSession: AVCaptureSession?
var frontCamera: AVCaptureDevice?
var frontCameraInput: AVCaptureDeviceInput?
var previewLayer: AVCaptureVideoPreviewLayer?
enum CameraControllerError: Swift.Error {
case captureSessionAlreadyRunning
case captureSessionIsMissing
case inputsAreInvalid
struct ContentView: View {
var body: some View {
VStack{
Image("lock")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 200.0, height: 200.0)
.cornerRadius(90.0)
Text("I am protected by a login page.")
}
struct LoginView: View {
@State private var username: String = ""
@State private var password: String = ""
var body: some View {
GeometryReader { geometry in
VStack{
Image("lock")
.resizable()
@RosayGaspard
RosayGaspard / swiftui-view-fullwidth.swift
Created January 22, 2020 08:25
Frame setting to make view take full width in SwiftUI
Text("My text")
.frame(minWidth: 0, maxWidth: .infinity, alignment: .leading)
@RosayGaspard
RosayGaspard / PlayerMovement.cs
Created January 23, 2019 14:52
Custom 3rd person character controller for Unity
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class PlayerMovement : MonoBehaviour {
private CharacterController characterController;
private Animator animator;
private float moveSpeed;
private bool hasJumped;
@RosayGaspard
RosayGaspard / .hyper.js
Last active April 25, 2018 09:44
Hyper configuration file to use with WSL
// Future versions of Hyper may add additional config options,
// which will not automatically be merged into this file.
// See https://hyper.is#cfg for all currently supported options.
module.exports = {
config: {
// choose either `'stable'` for receiving highly polished,
// or `'canary'` for less polished but more frequent updates
updateChannel: 'stable',