Skip to content

Instantly share code, notes, and snippets.

View PetreVane's full-sized avatar
🍃

Petre Vane PetreVane

🍃
View GitHub Profile
@PetreVane
PetreVane / Remove Local Docker Images.sh
Created November 19, 2021 15:59
This script will remove all your local Docker images. Useful when day-dreaming of the lost drive space, because of Docker 😬
#!/bin/bash
echo "This script will delete all your local Docker images! "
docker images | cut -c 45-59 |grep -v "IMAGE ID" > /tmp/images.names
for image in $(cat /tmp/images.names); do
docker rmi -f $image;
done
@PetreVane
PetreVane / Conditional Show or Hide components.swift
Created June 20, 2020 20:00
This is a countinuation of "Form embedded in a NavigationView" code snippet. This screen contains now 4 different Sections, each with a different component.
import SwiftUI
struct ContentView: View {
@State private var pickerSelectedIndex = 0
@State private var toggleOn = false
@State private var textFieldValue = ""
var treats = Treat.demoTreats
var body: some View {
@PetreVane
PetreVane / Form embedded in a NavigationView.swift
Created June 20, 2020 19:59
Example of a Form, embedded in a NavigationView, which has a Section and Picker. When Selecting an item, a new window slides in allowing you to select something. The selected value is passed back to the original screen.
import SwiftUI
struct ContentView: View {
@State private var pickerSelectedIndex = 0
var treats = Treat.demoTreats
var body: some View {
NavigationView {
Form {
@PetreVane
PetreVane / List with Section.swift
Created June 20, 2020 19:59
This is an example of a List (UITableView) with a section Header and Footer and GroupedStyle
import SwiftUI
struct ContentView: View {
var body: some View {
List {
Section(header: Text("This is a Header"), footer: Text("This is a footer")) {
ForEach(0 ..< 5) {
Text("\($0)").tag($0)
@PetreVane
PetreVane / ForEach example + PickerView.swift
Created June 20, 2020 19:59
Two examples of iterating over a list of elements, with ForEach. See bellow how to add a PickerView
import SwiftUI
struct ContentView: View {
let tips = ["Dream of mice", "Make some Origami", "Get the dog juggling", "Eating candies", "Sniffing weird stuff"]
var body: some View {
// Simple iteration where there list contains only a bunch of Strings
ForEach(tips, id: \.self) { tip in
VStack {
var body: some View {
VStack(alignment: .center) {
Image("paris")
.resizable()
.aspectRatio(contentMode: .fill)
.frame(width: 300)
.clipShape(Capsule())
.opacity(0.9)
.overlay(
@PetreVane
PetreVane / StarWars text like.swift
Created June 20, 2020 19:58
How to add StarWars text like and heart that changes size and color when pressed
import SwiftUI
struct ContentView: View {
@State private var colorChange = false
@State private var sizeChange = false
var body: some View {
VStack(alignment: .center, spacing: 30) {
@PetreVane
PetreVane / Toggle and DatePicker.swift
Created June 20, 2020 19:58
Adding a Toggle and a DatePicker in SwiftUI
import SwiftUI
struct ContentView: View {
private var isActivatedMessage: String {
return "CatNip mode is " + (isActivated ? "Activated" : "Deactivated")
}
private var dateFormater: DateFormatter {
let dateFormater = DateFormatter()
@PetreVane
PetreVane / Stepper.swift
Created June 20, 2020 19:57
How to initialize a Stepper in SwiftUI
import SwiftUI
struct ContentView: View {
@State private var orderCount = 0
var body: some View {
VStack {
// Initializing a Stepper
@PetreVane
PetreVane / CAShapeLayer Shapes.swift
Created April 1, 2020 09:25
Creates rectangles, triangles and ovals
extension CAShapeLayer {
static func rectangle(roundedRect: CGRect, cornorRadius: CGFloat, color: UIColor) -> CAShapeLayer {
let path = UIBezierPath(roundedRect: roundedRect, cornerRadius: cornorRadius)
let shape = CAShapeLayer()
shape.path = path.cgPath
shape.fillColor = color.cgColor
return shape
}
}