Skip to content

Instantly share code, notes, and snippets.

View jonpryor's full-sized avatar

Jonathan Pryor jonpryor

View GitHub Profile
@jonpryor
jonpryor / DiskCache.cs
Last active December 10, 2015 08:19
File system abstraction for use in PCL apps. `FileSystemOperations.cs` is usable in a PCL library that targets .NET 4.5 and .NET for Windows Store Apps. (Yes, this is _crazy_, but .NET 4.5 is required to access `System.IO.StreamWriter` (!) and other useful `System.IO` types. (Seriously, we need to target .NET 4.5 to use types present in .NET 1.0…
// "Port"/rewrite of: http://blog.neteril.org/blog/2012/12/17/memory-efficient-bitmap-caching-with-mono-for-android/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace Cadenza.IO
diff --git a/mono/io-layer/locking.c b/mono/io-layer/locking.c
index 57b18ca..eec2549 100644
--- a/mono/io-layer/locking.c
+++ b/mono/io-layer/locking.c
@@ -34,6 +34,11 @@ _wapi_lock_file_region (int fd, off_t offset, off_t length)
struct flock lock_data;
int ret;
+ if (offset < 0 || length < 0) {
+ SetLastError (ERROR_INVALID_PARAMETER);
$ cat ofs.cs
using System;
using System.Runtime.InteropServices;
[StructLayout (LayoutKind.Explicit)]
struct Embedded {
[FieldOffset (0)] IntPtr b;
[FieldOffset (0)] int c;
}
import java.util.Random;
class r {
public static void main(String[] args) {
Random x = new Random ();
for(int i=0; i<1000; i++) System.out.println(x.nextInt(2));
}
}
$ csharp
using SyMono C# Shell, type "help;" for help
Enter statements below.
csharp> using System.Text.RegularExpressions;
csharp> var r = new Regex (@"^\s*(?<name>[A-Za-z0-9_]+)\s*=\s*(?<value>[^\s]+)\s*;");
csharp> var m = r.Match ("Foo = Bar;");
csharp> m.Success;
true
csharp> var name = m.Groups ["name"].Value;
diff --git a/PluginExample/Program.cs b/PluginExample/Program.cs
index 7d45ae6..1e320f5 100644
--- a/PluginExample/Program.cs
+++ b/PluginExample/Program.cs
@@ -1,5 +1,6 @@
using System;
using System.Net;
+using System.IO;
using System.Security;
using System.Security.Permissions;
@jonpryor
jonpryor / gist:4635021
Last active December 11, 2015 17:29 — forked from anonymous/gist:4635005
static readonly IList<ViewModel> registeredEntities = new List<ViewModel>();
protected static IList<ViewModel> RegisteredViewModels
{
get
{
return registeredEntities;
}
}
using System;
using System.Linq;
using System.Threading;
class Test {
const int NumBusyWaiters = 10;
public static void Main ()
{
AppDomain.CurrentDomain.ProcessExit += (s, e) => {
csharp> var x = XElement.Parse("<MEMLOC loc= '0x55E155' />");
csharp> x.Descendants("MEMLOC");
{ }
csharp> x.DescendantsAndSelf("MEMLOC");
{ <MEMLOC loc="0x55E155" /> }
csharp> x.DescendantNodes();
{ }
csharp> x.DescendantNodesAndSelf();
{ <MEMLOC loc="0x55E155" /> }
csharp>
// To allow this project to build: https://dl.dropbox.com/u/15227809/Xamarin/HZLVBinding.zip
// Add a new file to the HZLVBinding project with these contents:
using Android.Runtime;
namespace Com.Devsmart.Android.UI {
partial class HorizontalListView {
protected override Java.Lang.Object RawAdapter {
get {return Adapter.JavaCast<Java.Lang.Object>();}