tech

0

error: failed to push some refs to 'https://git.heroku.com/xxxx.git' git pull heroku main/master git push heroku main/master

Cancel auto correction on mac: System Preferences -> Keyboard -> Text

2021.09.08

1

Always forget how to delete remote git branch: git push -d origin xxx

Use <pre><\pre> to keep the line break in html.

2021.09.10

2

var directionalLayoutMargins: NSDirectionalEdgeInsets { get set }

Use this property to specify the desired amount of space (measured in points) between the edges of this view and its subviews. The leading and trailing margins are applied appropriately to the left or right margins based on the current layout direction. For example, the leading margin is applied to the right edge of the view in right-to-left layouts. For most views, the default layout margins are 8 points on each side. You can change these values as needed for your interface.

For the root view of a view controller, the default value of this property reflects the system minimum margins and safe area insets. For other subviews in your view hierarchy, the default layout margins are normally 8 points on each side, but the values may be greater if the view is not fully inside the safe area or if the preservesSuperviewLayoutMargins property is true.

Auto layout uses your margins as a cue for placing content. For example, if you specify a set of horizontal constraints using the format string “|-[subview]-|”, the leading and trailing edges of the subview are inset from the edge of the superview by the corresponding layout margins. When the edge of your view is close to the edge of the superview and the preservesSuperviewLayoutMargins property is true, the actual layout margins may be increased to prevent content from overlapping the superview’s margins.

2022.06.27

3

Official sample code snippet for local receipt validation:

#if DEBUG certificateName = @"StoreKitTestCertificate"; #else certificateName = @"AppleIncRootCertificate"; #endif

Should be noted that "StoreKitTestCertificate" only works if using a StoreKit configuration file. If running the app on a device, should force using "AppleIncRootCertificate".

2022.06.28

4

After an ASWebAuthenticationSession is completed, a UIAlertController asking for saving password might be presented. But as the WKWebView is dismissed quickly, the UIAlertController disappears as well in less than a second.

This is Apple's bug after iOS 13.0 and is yet to be fixed.

https://github.com/AzureAD/microsoft-authentication-library-for-objc/issues/848#issuecomment-790068352

2022.06.29

5

Tips to Make Don't Starve Together Mods

DST source code is in steamapps/common/Don't Starve Together/dontstarve_steam/Contents/data/databundles/scripts.zip.

To access the global environment in source code, use GlOBAL.XXX.

To communicate between servers and clients, use APIs for ModRPCHandler. When sending a command to the server, it will pass the local player entity automatically as the first parameter so no need to rewrite that.

Setting server_mod_only, client_mod_only, or all_clients_required_mod to false doesn't make much difference, have to set an option to true to make it work.

I'm pretty new to Lua so just need to remember to put then after an if condition and end after each block. And no { or } in the code. Lua is a scripting language so have to declare the method beyond the line where it's called.

If you use print(xxx) in the code, the output will be at Documents/Klei/DoNotStarveTogether/client_log.txt. It will also get shown in the game when you press the "`" button.

If you wrote files besides modmain.lua or modinfo.lua, use modimport(filename) to import them.

PS: It's more helpful to download other mods and look at their code than to search for answers in the forum.

Useful links: https://forums.kleientertainment.com/files/ https://forums.kleientertainment.com/forum/79-dont-starve-together-mods-and-tools/ https://forums.kleientertainment.com/forums/topic/118056-mod-functions-in-thenet/ https://forums.kleientertainment.com/forums/topic/122473-new-modding-rpcs-api/#comment-1379795 https://github.com/handsomematt/dont-starve-tools

2022.10.15

6

To add MKAnnotationView with callout, specify canShowCallout and accessory views in the method mapView(_ :, didAdd:), instead of mapView(_ :, viewFor:).

2022.11.02

7

Understandings of Swift Initializers

1. Super Class's Designated Initializer Can Be Executed Automatically

/// Code sample Class SuperClass { var name: String

init() { self.name = "Super's name" print("Super init called") } }

Class SubClass { var subName: String

init(subName: String) { self.subName = subName print("Sub init called") } }

let instance = SubClass(subName: "Sub's name") /// The output will be "Sub init called\nSuper init called\n".

When the super class has a single designated initializer that takes no input argument, this initializer will be called automatically in subclass's initializer. This has been the behaviour since Swift 1 but is still implicit to many developers.

2. Subclass's Initializer Must Call a Designated Initializer

A convenience initializer must call a designated initializer from its own class to ensure that all properties are configured, which is easy to understand. Then, a designated initializer must not call convenience initializers from its own class to avoid infinite loops. The tricky part is that, a designated initializer can neither call a convenience initializer from its super class, even though all convenience initializers will end up calling a designated initializer, which makes the chain sub designated init -> super convenience init -> super designated init reasonable. However, if the subclass provides implementation of all super class's designated initializers, it will automatically inherit all convenience initializers. Then, the chain above could actually be sub(inherited from super) convenience init -> sub designated init -> super convenience init -> sub designated init, an infinite loop. Moreover, if the subclass doesn't specify its super class's designated initializers, it will inherit all designated initializers automatically. Convenience initializers cannot be overridden.

3. When to Use Required Initializers

A required initializer is to ensure that all subclasses implement it. There's no need to use required if the class is marked as final. For simple projects, it's easy to determine if an initializer should be marked as required. But it gets harder as the complexity of classes increases. In most of the cases, the compiler will tell you something goes wrong and that's when a required might be needed.

Useful links: https://docs.swift.org/swift-book/documentation/the-swift-programming-language/initialization/

2023.08.02

8

Tips to Host a Website

Set up a local server, forward its port to a public port. Add an A DNS record matching the public IP and the domain name. Need to pay attention to DNS records' TTL. If using NAT, the server cannot be accessed through external IP/domain internally. Because after the server responds to the internal request, the firewall/router detects that the request comes from an internal IP, and will send the respond directly from an internal IP to another internal IP. The client receives the respond, but it is waiting for the respond from the external IP/domain, thus won't work. To fix this, could use NAT reflection(AKA NAT hairpinning or NAT loopback), split DNS, use internal IP directly instead of external one, or use VPN. Theories of these solutions are similar, however, most routers at home don't support NAT reflection.

Useful links: https://en.wikipedia.org/wiki/Network_address_translation

2023.08.03

9

Renewing SSL certificates will trigger a challenge on public port 80. Need to ensure port 80 is clear before renewing.

Need to redirect "http" server to "https" server automatically, so that users won't have to type "https://" manually to visit the secure website. Use app.all('*', redirectFunction) to redirect at top of routing calls.

It's better to have two servers listening to both ports 80 and 443.

2024.04.12