This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
### PowerShell template profile | |
### Version 1.03 - Tim Sneath <tim@sneath.org> | |
### From https://gist.github.com/timsneath/19867b12eee7fd5af2ba | |
### | |
### This file should be stored in $PROFILE.CurrentUserAllHosts | |
### If $PROFILE.CurrentUserAllHosts doesn't exist, you can make one with the following: | |
### PS> New-Item $PROFILE.CurrentUserAllHosts -ItemType File -Force | |
### This will create the file and the containing subdirectory if it doesn't already | |
### | |
### As a reminder, to enable unsigned script execution of local scripts on client Windows, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import WinSDK | |
// Call a simple Win32 function and pass in strings | |
MessageBoxA(nil, "Hello from Swift running on Windows", "Swift Message Box", UINT(MB_OK)) | |
// Call a Win32 function that passes a variable by pointer | |
var memorySizeInBytes: LONGLONG = 0 | |
GetPhysicallyInstalledSystemMemory(&memorySizeInBytes) | |
print("System has \(memorySizeInBytes / 1024 / 1024)GB of RAM installed."); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Adapted from Hacking with SwiftUI, credit to Paul Hudson (@twostraws). | |
// https://www.hackingwithswift.com/books/ios-swiftui/animating-gestures | |
import SwiftUI | |
struct ContentView: View { | |
@State private var dragAmount = CGSize.zero | |
var body: some View { | |
RoundedRectangle(cornerRadius: 10) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// Let's sort this array in reverse alphabetical order. Credit to @JoaquinAlori at @tryolabs for the idea. | |
let names = ["Mavericks", "Yosemite", "El Capitan", "Sierra", "High Sierra", | |
"Mojave", "Catalina", "Big Sur", "Monterey", "Ventura", "Sonoma"] | |
var reversedNames : [String] | |
/// ✅ Sort method returns true when the first element should be ordered before the second. | |
func backward(_ a: String, _ b: String) -> Bool { | |
return a > b | |
} | |
reversedNames = names.sorted(by: backward) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct ContentView: View { | |
@State private var switchSetting = true | |
@State private var stepperValue = 11 | |
@State private var dateValue = Date.now | |
var body: some View { | |
NavigationView { | |
Form { | |
Section { | |
Toggle("On or off: you choose", isOn: $switchSetting) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:math' as math; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/rendering.dart'; | |
import 'package:flutter/gestures.dart'; | |
const double kTwoPi = 2 * math.pi; | |
class SectorConstraints extends Constraints { | |
const SectorConstraints({ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Range<T extends num> { | |
final T from; | |
final T to; | |
num get magnitude => to - from; | |
Range(this.from, this.to); | |
factory Range.fromList(List<T> list) { | |
assert(list.length == 2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A simple example of records and patterns | |
(double x, double y) getLocation(String name) { | |
if (name == 'Nairobi') { | |
return (1.2921, 36.8219); | |
} | |
else { | |
return (0, 0); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abstract class Animal { | |
void makeNoise(); | |
} | |
class Dog extends Animal { | |
@override | |
void makeNoise() => print('Woof'); | |
} | |
class Cat extends Animal { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp(const MyApp()); | |
class MyApp extends StatelessWidget { | |
const MyApp({Key? key}) : super(key: key); | |
static const String _title = 'Flutter Code Sample'; | |
@override |
NewerOlder