This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 |
This file has been truncated, but you can view the full file.
This file contains hidden or 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
1635476713209:Ver:1596173960672524124772:VS-Code:3.27.2:1.32.7:2.15.0 | |
1635476713315:Req:{"jsonrpc"::"2.0","id"::0,"method"::"initialize","params"::{"processId"::7100,"clientInfo"::{"name"::"Visual Studio Code","version"::"1.61.2"},"locale"::"en-us","rootPath"::"c::\\src\\win32","rootUri"::"file::///c%3A/src/win32","capabilities"::{"workspace"::{"applyEdit"::true,"workspaceEdit"::{"documentChanges"::true,"resourceOperations"::["create","rename","delete"],"failureHandling"::"textOnlyTransactional","normalizesLineEndings"::true,"changeAnnotationSupport"::{"groupsOnLabel"::true}},"didChangeConfiguration"::{"dynamicRegistration"::true},"didChangeWatchedFiles"::{"dynamicRegistration"::true},"symbol"::{"dynamicRegistration"::true,"symbolKind"::{"valueSet"::[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26]},"tagSupport"::{"valueSet"::[1]}},"codeLens"::{"refreshSupport"::true},"executeCommand"::{"dynamicRegistration"::true},"configuration"::true,"workspaceFolders"::true,"semanticTokens"::{"refresh |
This file contains hidden or 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
void main() { | |
const address = -69795452; | |
const UINT32_MAX = 0xFFFFFFFF; | |
// Two's complement | |
print((UINT32_MAX - address.abs() + 1).toRadixString(16)); | |
} |
NewerOlder