Skip to content

Instantly share code, notes, and snippets.

View sushihangover's full-sized avatar

Robert N. sushihangover

View GitHub Profile
#!/bin/bash
read -r -d '' script <<'EOF'
on run argv
tell application "iTerm"
activate
set myterm to (make new terminal)
tell myterm
launch session "Default"
tell the last session
repeat with arg in argv
@sushihangover
sushihangover / Dynamic.cs
Last active June 28, 2018 03:47
Xamarin.iOS : Create a @dynamic property that can be used as a CoreAnimation / CALayer custom property within CAAction/CAAnimation
// https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/ObjCRuntimeGuide/Articles/ocrtPropertyIntrospection.html#//apple_ref/doc/uid/TP40008048-CH101
public static bool Property(Type clsType, string propertyName, Type encodeType)
{
// far from perfect, but prevents "some" brain-farts and misuse...
// This should fixed to allow non-wrapped NSValue types (CGRect/Size, etc... consult Appendix C / Key-Value Coding Extensions)
if (!(encodeType.IsSubclassOf(typeof(NSObject)) || encodeType.IsValueType))
{
// Eric Lippert's comment: https://stackoverflow.com/questions/2742276/how-do-i-check-if-a-type-is-a-subtype-or-the-type-of-an-object#comment2771730_2742288
throw new Exception("Only NSObject subclasses and Value types supported");
}
@sushihangover
sushihangover / AppController.cs
Created January 9, 2016 03:42 — forked from grexican/AppController.cs
Windowless Mac App with MonoMac
using System;
using MonoMac.Foundation;
using MonoMac.AppKit;
namespace StatusMenu
{
[Register("AppController")]
public partial class AppController : NSObject
{
public AppController()
@sushihangover
sushihangover / ClearableEditText.cs
Created February 23, 2018 22:57
Xamarin.Android translation of DroidParts ClearableEditText
// DroidParts is under Apache License 2.0
// https://github.com/droidparts/droidparts/blob/master/droidparts-misc/src/org/droidparts/widget/ClearableEditText.java
public class ClearableEditText : EditText, View.IOnTouchListener, View.IOnFocusChangeListener, ITextWatcher
{
public ClearableEditText(IntPtr javaReference, Android.Runtime.JniHandleOwnership transfer) : base(javaReference, transfer) { Initialize(); }
public ClearableEditText(Context context) : base(context) { Initialize(); }
public ClearableEditText(Context context, Android.Util.IAttributeSet attrs) : base(context, attrs) { Initialize(); }
public ClearableEditText(Context context, Android.Util.IAttributeSet attrs, int defStyleAttr) : base(context, attrs, defStyleAttr) { Initialize(); }
public ClearableEditText(Context context, Android.Util.IAttributeSet attrs, int defStyleAttr, int defStyleRes) : base(context, attrs, defStyleAttr, defStyleRes) { Initialize(); }
@sushihangover
sushihangover / EasyLayout.cs
Created November 23, 2017 20:05 — forked from praeclarum/EasyLayout.cs
EasyLayout makes writing auto layout code in Xamarin.iOS easier. See [the example](https://gist.github.com/praeclarum/8185036) for hints on how to use this library.
//
// Copyright (c) 2013-2015 Frank A. Krueger
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
@sushihangover
sushihangover / ColorReplaceFilter.cs
Last active November 16, 2017 21:32
Xamarin iOS CIFilter / CIColorKernel Replace one color with another color (with threshold parameter to catch those stray variants)
public class ColorReplaceFilter : CIFilter
{
const string filterName = "colorReplace";
const int numArgs = 4;
const string coreIageShaderProgram =
@"
kernel vec4 main(__sample s, __color o, __color r, float threshold) {
vec4 diff = s.rgba - o;
float distance = length( diff );
float alpha = compare( distance - threshold, 0.0, 1.0 );
@sushihangover
sushihangover / gist:e30e516a0081ea9abe493c6d07dfd24a
Created November 4, 2017 20:34
AVAssetExportSession / Log all combinations of an asset with an AVFoundation file type (UTI) and an export preset if it is a valid combination
//var bundleUrl = NSBundle.MainBundle.GetUrlForResource("anemone_coralmorphologic", "mp4");
var bundleUrl = NSBundle.MainBundle.GetUrlForResource("addf8-Alaw-GW", "wav");
var asset = AVAsset.FromUrl(bundleUrl);
foreach (var fileType in Enum.GetValues(typeof(AVFileTypes)))
{
foreach (var preset in AVAssetExportSession.AllExportPresets)
{
var UTIConstant = ((AVFileTypes)(Enum.Parse(typeof(AVFileTypes), fileType.ToString()))).GetConstant();
var ok = await AVAssetExportSession.DetermineCompatibilityOfExportPresetAsync(
preset,
@sushihangover
sushihangover / gist:3a0b22603819a9d4c14ef84f8f6d5a9a
Created December 12, 2016 03:56
Cakebuid cake Rewrite existing AssemblyInfo
Task("AssemblyInfoRewrite")
.Does (() =>
{
var assemblyInfoSettings = JsonConvert.DeserializeObject<AssemblyInfoSettings>(
JsonConvert.SerializeObject(
ParseAssemblyInfo("./CommonAssemblyInfo.cs")
)
);
assemblyInfoSettings.Company = "My Wicked New Company";
CreateAssemblyInfo("./NewCommonAssemblyInfo.cs", assemblyInfoSettings);
@sushihangover
sushihangover / TestAppViewController.cs
Created September 19, 2016 16:38 — forked from brendanzagaeski/TestAppViewController.cs
Obtaining the subnet mask of network interfaces on Xamarin.iOS and Xamarin.Mac
// Obtaining the subnet mask of network interfaces on Xamarin.iOS and Xamarin.Mac
//
// On Xamarin.iOS and Xamarin.Mac, `NetworkInterface.OperationalStatus` always
// returns: `OperationalStatus.Unknown`
// https://github.com/mono/mono/blob/f48ceb9860676c342f4c91fbc2e34ea600d839c6/mcs/class/System/System.Net.NetworkInformation/NetworkInterface.cs#L552-L556
//
// Additionally, on all "Linux-like" platforms, including iOS and Mac,
// `UnicastIPAddressInformation.IPv4Mask` is not implemented
// https://github.com/mono/mono/blob/f48ceb9860676c342f4c91fbc2e34ea600d839c6/mcs/class/System/System.Net.NetworkInformation/UnicastIPAddressInformation.cs#L165-L167
//
@sushihangover
sushihangover / ParentViewController.Keyboard.cs
Created August 31, 2016 13:06 — forked from redent/ParentViewController.Keyboard.cs
Parent view controller to handle keyboard notifications to center views in the screen. UIScrollView related methods moved to an extension class.
using System;
using Foundation;
using UIKit;
using TwinCoders.TouchUtils.Extensions;
using CoreGraphics;
namespace SalesForce.Touch.Views
{
public abstract partial class ParentViewController
{