Skip to content

Instantly share code, notes, and snippets.

Avatar

Robert N. sushihangover

View GitHub Profile
@sushihangover
sushihangover / ClearableEditText.cs
Created Feb 23, 2018
Xamarin.Android translation of DroidParts ClearableEditText
View ClearableEditText.cs
// 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 Nov 23, 2017 — 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.
View EasyLayout.cs
//
// 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 Nov 16, 2017
Xamarin iOS CIFilter / CIColorKernel Replace one color with another color (with threshold parameter to catch those stray variants)
View ColorReplaceFilter.cs
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 / Dynamic.cs
Last active Jun 28, 2018
Xamarin.iOS : Create a @dynamic property that can be used as a CoreAnimation / CALayer custom property within CAAction/CAAnimation
View Dynamic.cs
// 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 / gist:e30e516a0081ea9abe493c6d07dfd24a
Created Nov 4, 2017
AVAssetExportSession / Log all combinations of an asset with an AVFoundation file type (UTI) and an export preset if it is a valid combination
View gist:e30e516a0081ea9abe493c6d07dfd24a
//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 Dec 12, 2016
Cakebuid cake Rewrite existing AssemblyInfo
View gist:3a0b22603819a9d4c14ef84f8f6d5a9a
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 Sep 19, 2016 — forked from brendanzagaeski/TestAppViewController.cs
Obtaining the subnet mask of network interfaces on Xamarin.iOS and Xamarin.Mac
View TestAppViewController.cs
// 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 Aug 31, 2016 — 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.
View ParentViewController.Keyboard.cs
using System;
using Foundation;
using UIKit;
using TwinCoders.TouchUtils.Extensions;
using CoreGraphics;
namespace SalesForce.Touch.Views
{
public abstract partial class ParentViewController
{
@sushihangover
sushihangover / XamarinScrollableListView.cs
Created Aug 8, 2016 — forked from PiMaker/XamarinScrollableListView.cs
A custom ListView for Xamarin.Android that enables scrolling via moving a DragShadow to the top or bottom.
View XamarinScrollableListView.cs
// File: XamarinScrollableListView.cs
// Created: 27.07.2016
//
// This class represents a custom View. It inherits from ListView but adds automatic Drag and Drop scrolling.
using Android.Content;
using Android.Runtime;
using Android.Util;
using Android.Views;
using Android.Widget;
View neo4j-fsharp-basics.fs
open System
open Neo4jClient
open System.Linq
[<CLIMutable>]
type Person = { Name:string; Twitter:string }
[<CLIMutable>]
type Knows = { How:string }
You can’t perform that action at this time.