Skip to content

Instantly share code, notes, and snippets.

View jonpryor's full-sized avatar

Jonathan Pryor jonpryor

View GitHub Profile
$ 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;}
int
Mono_Posix_Syscall_syslog (int priority, const char* message)
{
#ifdef __GCC__
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Werror=format-security"
#endif
syslog (priority, message);
$ adb shell pm list packages Scratch. | cut -c 9-
Scratch.AlertDialog
Scratch.AndroidSpecificLocale
Scratch.Deadlock
Scratch.DefaultTemplate
Scratch.ExceptionPropogation
Scratch.ExpandableListActivity
Scratch.FieldSetLrefOverflow
Scratch.Hello
Scratch.HttpsDownload
/*
## Mono JIT compiler version 2.10.9 (tarball Mon May 7 20:25:51 EDT 2012)
DynamicMethod creation: 0.0453009000ms
LINQ expressions creation: 0.0971724000ms
Delegate creation: 0.0044351000ms
DynamicMethod invocation: 0.0000612000ms
Expression invocation: 0.0000609000ms
MethodInfo invocation: 0.0007135000ms
Delegate invocation: 0.0000619000ms
+ public static Group [] getgrouplist (string username)
+ {
+ // Syscall to getpwnam to retrieve user uid
+ Passwd pw = Syscall.getpwnam (username);
+ if (pw == null)
+ return new Group [0];
+ // initialising the lngroups by 1 to get the group count
+ int ngroups = 1;
+ // allocating buffer to store group uid's
+ uint [] groups = new uint [ngroups];

How would I do the equivalent of 'in_dir=s' => \@in_dirs from Perl's Getopt::Long, i.e., a case where --in_dir was used multiple times.

Manually, by capturing values in an intermediate list:

var dirs    = new List<string> ();
var options = new OptionSet {
    { "in_dir=", v => dirs.Add (v) },
};
var unmatched = options.Parse(new[]{

"--in_dir", "A",

diff --git a/Makefile b/Makefile
index b127bed..e5b75ae 100644
--- a/Makefile
+++ b/Makefile
@@ -2,8 +2,6 @@ TARGET = bin/hello
# C library
CC = cc
-AR = ar cqs
-CLIB = bin/libhello.a
// Quick-and-dirty (and untested!) port of https://gist.github.com/3169945 to C#
Bitmap DecodeFile (string path)
{
var opts = new BitmapFactory.Options () {
InJustDecodeBounds = true,
};
using (var b = BitmapFactory.DecodeFile (path, opts)) {
// Ignore; we're filling `opts`
}
const int RequiredSize = 70;