Skip to content

Instantly share code, notes, and snippets.

View brendanzagaeski's full-sized avatar

Brendan Zagaeski brendanzagaeski

  • Microsoft
  • Boston, MA, United States
View GitHub Profile
@brendanzagaeski
brendanzagaeski / JSCoreiOSViewController.cs
Created October 25, 2013 19:17
Use P/Invoke to call JavaScriptCore's C API functions in iOS.
using System;
using MonoTouch.UIKit;
using MonoTouch;
using System.Runtime.InteropServices;
namespace JintiOS
{
unsafe public partial class JintiOSViewController : UIViewController
{
JSContextRef* context;
@brendanzagaeski
brendanzagaeski / Android.Webkit.WebViewClientClassicExt.cs
Created November 9, 2013 01:04
Simplified WebViewClientExt class
using System;
using Android.Runtime;
namespace Android.Webkit {
[global::Android.Runtime.Register ("android/webkit/WebViewClientClassicExt", DoNotGenerateAcw=false)]
public class WebViewClientClassicExt : Android.Webkit.WebViewClient {
public WebViewClientClassicExt () {}
protected WebViewClientClassicExt (IntPtr javaReference, JniHandleOwnership transfer) : base (javaReference, transfer) {}
}
}
@brendanzagaeski
brendanzagaeski / Main.cs
Created November 11, 2013 21:09
Subclassing NSMutableAttributedString causes an error "[CustomNSAttributedString initWithAttributedString:]: unrecognized selector sent to instance 0x4418b0"
using System;
using MonoMac.Foundation;
using MonoMac.CoreText;
using MonoMac.AppKit;
namespace SubclassingTest
{
public class Program
{
static void Main (string[] args)
@brendanzagaeski
brendanzagaeski / fixconfig.sh
Last active December 28, 2015 17:09
Fix the `config` file within an existing `.pkg` to work around https://bugzilla.xamarin.com/show_bug.cgi?id=16250
#!/bin/sh
PACKAGEPATH="$(ls $1/*.pkg)"
TEMPDIR="$(mktemp -d /tmp/repackage.XXXXXX)"
rmdir "$TEMPDIR"
pkgutil --expand "$PACKAGEPATH" "$TEMPDIR"
APPDIR="$(mktemp -d /tmp/repackage.XXXXXX)"
PAYLOADPATH="$(ls $TEMPDIR/*.pkg/Payload)"
pushd "$APPDIR"
pax -rzf "$PAYLOADPATH"
sed -i "" -e "s:libc.dylib:/usr/lib/libc.dylib:" *.app/Contents/MonoBundle/config
@brendanzagaeski
brendanzagaeski / com.xamarin.mtvs.buildserver.plist
Created November 19, 2013 23:25
Modified /Library/LaunchAgents/com.xamarin.mtvs.buildserver.plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Disabled</key>
<true/>
<key>KeepAlive</key>
<false/>
<key>Label</key>
<string>com.xamarin.mtvs.buildserver</string>
modprobe tg3
echo 14e4 1686 >/sys/module/tg3/drivers/pci:tg3/new_i
@brendanzagaeski
brendanzagaeski / add_play_services.bat
Created December 4, 2013 01:34
Windows translation of add_play_services.sh. Pseudo-batchfile.
mkdir google-play-services_lib
cd google-play-services_lib
xcopy C:\Users\_your_username_\AppData\Local\Android\android-sdk\extras\google\google_play_services\libproject\google-play-services_lib .
C:\Users\_your_username_\AppData\Local\Android\android-sdk\tools\android update project -p .
REM Get Ant from http://ant.apache.org/bindownload.cgi
set PATH="%PATH%";"C:\Program Files (x86)\Java\jdk1.6.0_39\bin"
C:\_path_\_to_\ant.bat release
@brendanzagaeski
brendanzagaeski / gist:7817256
Last active December 30, 2015 10:39
Two common build errors about missing properties for new projects in Xamarin.iOS

"Error Application Name is not set in iOS Application Property Page"

"Error Identifier is not set in iOS Application Property Page"

To fix this problem, open the Project Properties, and under the "iOS Application" tab, fill in the "Application Name", "Identifier", and "Version" fields (see also the screenshot of the "Project Properties" -> "iOS Application" settings in the Xamarin docs)

@brendanzagaeski
brendanzagaeski / SafariHistoryPlist.cs
Created December 10, 2013 17:35
Read Safari History.plist using NSPropertyListSerialization in Xamarin C#. See https://github.com/animetrics/PlistCS or http://www.codeproject.com/Tips/406235/A-Simple-PList-Parser-in-Csharp for pure C# alternatives.
var plistFile = System.IO.File.OpenRead("/Users/anyuser/Library/Safari/History.plist");
NSPropertyListFormat format = NSPropertyListFormat.Binary;
NSError error;
NSData plistXml = NSData.FromStream(plistFile);
plistFile.Close();
var plistObject = (NSDictionary)NSPropertyListSerialization.PropertyListWithData (
plistXml,
NSPropertyListReadOptions.MutableContainersAndLeaves,
@brendanzagaeski
brendanzagaeski / FetchRepositoriesWithCompletionArgsNamed.cs
Created January 10, 2014 06:12
Example of a generated Task return value for `[Async (ResultTypeName = "FetchRepositoriesWithCompletionArgs")]` using a named delegate. The names of the return values match the names of the delegate's arguments.
public class FetchRepositoriesWithCompletionArgs {
public bool Success { get; set; }
public NSError Error { get; set; }
public NSArray Repositories { get; set; }
public FetchRepositoriesWithCompletionArgs (bool success, NSError error, NSArray repositories) {
this.Success = success;
this.Error = error;
this.Repositories = repositories;
}