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
internal class CustomGraphicsView : GraphicsView | |
{ | |
// TODO workaround since binding doesn't work yet on IDrawable/GraphicsView | |
// https://github.com/dotnet/maui/issues/20991 | |
protected override void OnBindingContextChanged() | |
{ | |
base.OnBindingContextChanged(); | |
if (BindingContext is not null) | |
{ |
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
public async Task<TokenResponse> GetTokenResponse() | |
{ | |
var raw = Task.Run(async () => await SecureStorage.GetAsync(KeyTokenResponse)).Result | |
?? throw new InvalidOperationException($"'{nameof(TokenResponse)}' not found"); | |
using var stream = new MemoryStream(Encoding.UTF8.GetBytes(raw), false); | |
return await JsonSerializer.DeserializeAsync<TokenResponse>(stream) | |
?? throw new InvalidOperationException($"Cannot deserialize '{nameof(TokenResponse)}'"); | |
} |
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 SecretSong { | |
constructor(items) { | |
this.items = items || []; | |
this.lyrics = ''; | |
this.itemsGiven = []; | |
} | |
init() { | |
let when = atob('T24gdGhl'); | |
let verb = atob('ZGF5IG9mIENocmlzdG1hcyBteSB0cnVlIGxvdmUgc2VudCB0byBtZTo='); | |
const from = atob('ZG92ZXMsIGE='), to = atob('ZG92ZXMsIGFuZCBh'); |
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
using System.Numerics; | |
string ToWords(BigInteger number) | |
{ | |
var ones = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; | |
var teens = new string[] { "ten", "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; | |
var xty = new string[] { "twenty", "thirty", "fourty", "fifty", "sixty", "seventy", "eighty", "ninety" }; | |
var suffixes = new string[] { | |
"", "thousand", "million", "billion", "trillion", | |
"quadrillion", "quintillion", "sextillion", "septillion", |
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
string[] ones = { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten" }; | |
string[] teens = { "eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "eighteen", "nineteen" }; | |
string[] tens = { "", "", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety" }; | |
string[] suffixes = { "thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion" }; | |
string NumberToWords(ulong number) | |
{ | |
if (number >= 1 && number <= 10) | |
{ | |
return ones[number - 1]; |
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
string ToOnes(long number) | |
{ | |
if (number == 0) | |
{ | |
return ""; | |
} | |
var words = new string[] { "one", "two", "three", "four", "five", "six", "seven", "eight", "nine" }; | |
return words[number - 1]; |
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
fun tryEncode(url: String): URL { | |
val schemeSeparator = "://" | |
val schemeIndex = url.indexOf(schemeSeparator) | |
val scheme: String | |
val urlWithoutScheme: String | |
if (schemeIndex > 0) { | |
scheme = url.substring(0, schemeIndex) | |
urlWithoutScheme = url.substring(schemeIndex + schemeSeparator.length) | |
} | |
else { |
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
public static class BindableHelper | |
{ | |
private const string KnownPropertyPattern = "Property"; | |
public static BindableProperty CreateProperty<T>( | |
T? defaultValue = default, | |
BindingMode mode = BindingMode.TwoWay, | |
BindableProperty.BindingPropertyChangedDelegate? propertyChanged = null, | |
[CallerMemberName] string? propertyName = null) | |
{ |
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
// interface | |
interface IActivityInstanceProvider { | |
fun updateInstance(activity: Activity) | |
fun <TActivity: Activity> get(): TActivity? | |
} | |
// class | |
class ActivityInstanceProvider: IActivityInstanceProvider { | |
private val activityInstance: HashSet<WeakReference<Activity?>> = hashSetOf() |
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
internal class ObservableCollectionAndItems<TModel> where TModel : INotifyPropertyChanged | |
{ | |
private readonly ObservableCollection<TModel> collection = new(); | |
public event EventHandler<EventArgs>? ItemChanged; | |
public event EventHandler<NotifyCollectionChangedEventArgs>? CollectionChanged; | |
public ObservableCollectionAndItems() | |
{ | |
collection.CollectionChanged += Collection_CollectionChanged; |
NewerOlder