Skip to content

Instantly share code, notes, and snippets.

import clr
clr.AddReference('CorDebug')
from System.Reflection import Assembly
ipy = Assembly.GetEntryAssembly().Location
import sys
py_file = sys.argv[1]
cmd_line = "\"%s\" -D \"%s\"" % (ipy, py_file)
from System.Threading import AutoResetEvent
open System.IO
open System.Net
open System.Net.Sockets
open Microsoft.FSharp.Control
open Extensions
let rec relay_loop (http:HttpListener) (socket:Socket) =
async {
// Async.Any (http.AsyncGetContext(), socket.AsyncReceive())
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style>
.twitter_user
{
font-weight: bold;
}
#tweets
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<style type="text/css">
.twitter_user
{
font-weight: bold;
}
#tweets
@devhawk
devhawk / XML2JSON.js
Created May 3, 2012 23:02
simple utility function to convert XML to JSON using TreeWalker
function XML2JSON(doc) {
function workhorse(tw) {
var curNode = tw.currentNode;
if (curNode.nodeType === 3) {
return curNode.nodeValue;
}
var obj = {}
@devhawk
devhawk / ResolveNamespace.cs
Created June 11, 2012 18:07
P/Invoke and wrapper method for RoResolveNamespace
using System;
using System.Linq;
using System.Runtime.InteropServices;
using System.Runtime.InteropServices.WindowsRuntime;
class WinRTInterop
{
public class ResolvedNamespaces
@devhawk
devhawk / gist:2913046
Created June 11, 2012 22:10
P/invoke for MetaDataGetDispenser
class WinRTInterop
{
public static IMetaDataDispenser GetMetadataDispenser()
{
var clsid = new Guid("{E5CB7A31-7512-11d2-89CE-0080C792E5D8}"); //CLSID_CorMetaDataDispenser
//var iid = new Guid("{31BCFCE2-DAFB-11D2-9F81-00C04F79A0A3}"); //IID_IMetaDataDispenserEx
var iid = new Guid("{809C652E-7396-11D2-9771-00A0C9B4D50C}"); //IID_IMetaDataDispenser
object ppv;
var hr = MetaDataGetDispenser(clsid, iid, out ppv);
@devhawk
devhawk / gist:2915352
Created June 12, 2012 05:33
Portable IMetaDataImport p/invoke definition
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MetadataReader
{
using HRESULT = System.UInt32;
@devhawk
devhawk / gist:2920743
Created June 12, 2012 23:12
p/invoke and wrapper method for RoGetMetaDataFile
//note, this wrapper funtion returns the metadata file name and token
//it immediately releases the importer pointer
static Tuple<string, UInt32> ResolveTypeName(string typename)
{
string path;
object importer = null;
UInt32 token;
try
{
@devhawk
devhawk / gist:2920749
Created June 12, 2012 23:12
P/Invoke and wrapper method for RoParseTypeName
static string[] ParseTypeName(string typename)
{
UInt32 partsCount;
IntPtr[] typeNameParts = null;
try
{
var hr = RoParseTypeName(typename, out partsCount, out typeNameParts);
var parts = partsCount == 0 ? new string[0] : typeNameParts.Select(p => WindowsRuntimeMarshal.PtrToStringHString(p)).ToArray();