Skip to content

Instantly share code, notes, and snippets.

View patridge's full-sized avatar

Adam Patridge patridge

View GitHub Profile
@patridge
patridge / SuperAwesomeButton.cs
Last active January 22, 2016 21:10
Attempt at making a non-generic refactor-friendly BindableProperty. (Some back-story on the deprecation and my motivation: https://twitter.com/PatridgeDev/status/690620310870106112.)
public class SomeButton : Button {
public string ExampleThing {
get { return (string)GetValue(ExampleThingBindableProperty); }
set { SetValue(ExampleThingBindableProperty, value); }
}
public static readonly BindableProperty ExampleThingBindableProperty =
BindableProperty.Create(nameof(ExampleThing), typeof(string), typeof(Button), default(string));
}

Keybase proof

I hereby claim:

  • I am patridge on github.
  • I am patridge (https://keybase.io/patridge) on keybase.
  • I have a public key ASCKUpBrk6PnSerOrfBdBcjh8ZjyzZeQzEU8UP-Q2q0tago

To claim this, I am signing this object:

@patridge
patridge / gist:10499338
Last active August 23, 2018 15:52
Xamarin: get a random color
// Xamarin.iOS (using MonoTouch.UIKit;)
static Random rand = new Random();
public static UIColor GetRandomColor() {
int hue = rand.Next(255);
UIColor color = UIColor.FromHSB(
(hue / 255.0f),
1.0f,
1.0f);
return color;
}
@patridge
patridge / gist:8984934
Created February 13, 2014 22:08
One approach for handling keyboard show/hide in Xamarin.iOS.
NSObject keyboardShowObserver;
NSObject keyboardHideObserver;
public override void ViewWillAppear(bool animated) {
base.ViewWillAppear(animated);
keyboardShowObserver = NSNotificationCenter.DefaultCenter.AddObserver(UIKeyboard.WillShowNotification, (notification) => {
NSValue nsKeyboardBounds = (NSValue)notification.UserInfo.ObjectForKey(UIKeyboard.BoundsUserInfoKey);
RectangleF keyboardBounds = nsKeyboardBounds.RectangleFValue;
float height = View.Bounds.Height - keyboardBounds.Height;
if (NavigationController != null && NavigationController.TabBarController != null && NavigationController.TabBarController.TabBar != null) {
@patridge
patridge / markdown.json
Created April 3, 2020 20:32
Microsoft Docs/Learn Markdown snippets
{
"Microsoft Docs image": {
"prefix": [ "image", "img" ],
"body": [
":::image source=\"$1\" alt-text=\"$0\":::"
],
"description": "Microsoft Docs-style image syntax (':::image …:::')."
},
"Microsoft Docs decorative/icon image": {
"prefix": [ "image", "img" ],
@patridge
patridge / samples.sh
Created May 4, 2020 16:48
Command line reference
# Command line calls that don't fit elsewhere (e.g., PowerShell Experiments: https://github.com/patridge/PowerShellExperiments)
# Check for global NPM packages with updates available
npm outdated -g --depth=0
#
// e.g., inject something whenever iterating a list
const arr = [ 1, 2, 3 ];
arr[Symbol.iterator] = function () {
let i = 0;
let arr = this;
return {
next: function () {
if (i >= arr.length) {
return { done: true };
} else {
@patridge
patridge / .gitignore
Last active April 2, 2021 19:59
FlatRedBall .gitignore
# FlatRedBall (FRB) .gitignore
# https://gist.github.com/patridge/46a9e6f410499e47fdbfc6d81c7c92f0/
*.Generated.cs
*.csvSettings
*.cachefile
*.Generated.Event.cs
*.gvwx
*.aeproperties
@patridge
patridge / gist:2556a7b8cb90f3efe6cf103fea417193
Last active July 12, 2022 04:03
My current Git aliases
# To view any current aliases, run this:
git config --get-regexp alias
# `git tree` (and press Q to quit): Display a nice tree with branches.
git config --global alias.tree "log --graph --decorate --pretty=oneline --abbrev-commit --all"
# `git showtrackedignored`: Display normally tracked files currently being ignored.
git config --global alias.showtrackedignored "ls-files -i --exclude-standard"
# Push the current branch to my personal remote name choice (by default, technically configurable, but everyone should push to patridge too, apparently)
alias.pushu !git push --set-upstream ${1-patridge} $(git branch --show-current)
@patridge
patridge / NetworkHelpers.cs
Created October 31, 2022 22:08
Meadow: Network helper methods (NTP, WiFi discovery, requests, etc.)
public static class NetworkHelpers
{
public static async Task GetWebPageViaHttpClient(string uri)
{
Console.WriteLine($"Requesting {uri} - {DateTime.Now}");
using (var client = new HttpClient())
{
try
{