Skip to content

Instantly share code, notes, and snippets.

View jonpryor's full-sized avatar

Jonathan Pryor jonpryor

View GitHub Profile
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));
}
}
$ cat ofs.cs
using System;
using System.Runtime.InteropServices;
[StructLayout (LayoutKind.Explicit)]
struct Embedded {
[FieldOffset (0)] IntPtr b;
[FieldOffset (0)] int c;
}
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);
@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
using System;
class Test {
public static void Main ()
{
var v = Environment.OSVersion;
Console.WriteLine (" Platform: {0}", v.Platform);
Console.WriteLine (" Service Pack: {0}", v.ServicePack);
Console.WriteLine (" Version: {0}", v.Version);
Console.WriteLine ("Version String: {0}", v.VersionString);
<?xml version="1.0" encoding="utf-8"?>
<ArrayOfItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Item Completed="true">
<DoItem>fds</DoItem>
</Item>
<Item Completed="false">
<DoItem>Find</DoItem>
</Item>
</ArrayOfItem>
using System;
namespace Total
{
class Total
{
static void Main()
{
int Total = 0;
for (int counter = 0; counter < 10; ++counter) {
$ csharp
Mono C# Shell, type "help;" for help
Enter statements below.
csharp> class X { public int Foo {get;set;} }
csharp> var x = typeof(X);
csharp> x.GetProperty("Foo").GetGetMethod().IsVirtual;
false
// from: http://pastebin.com/Hg8vkNAu
//
// Suggested improvement:
static readonly Dictionary<Type, Func<byte[], object>> Decoders = new Dictionary<Type, Func<byte[], object>>() {
{ typeof (string), x => Encoding.UTF8.GetString(x) },
{ typeof (byte[]), x => x },
};
public void Add<T>(string cmd, MessageReceiver<T> receiver)
{
class Memoization<T, TResult> {
internal Memoization (Func<T, TResult> f, IDictionary<T, TResult> d)
{
Invoke = f;
Values = d;
}
public Func<TResult> Invoke {get; private set;}
public IDictionary<T, TResult> Values {get; private set;}