Skip to content

Instantly share code, notes, and snippets.

View txdv's full-sized avatar

Andrius Bentkus txdv

View GitHub Profile
@txdv
txdv / gitwiki.cs
Created March 16, 2011 23:01
manos memory leak
using Manos;
using System.IO;
using LibGit2Sharp.Core;
namespace GitWiki
{
public class GitWiki : ManosApp
{
static string repodir = "testrepo.git/.git/";
@txdv
txdv / test.cs
Created July 1, 2011 07:21
A showcase how to create an IRC bot with a web frontend (all in 1 thread)
using System;
using System.Collections;
using System.Collections.Generic;
// Modified version of SmartIrc4Net available at: https://github.com/txdv/smartirc4net
using Meebey.SmartIrc4net;
using Manos.Http;
public class Test
{
@txdv
txdv / gist:1064211
Created July 5, 2011 03:23
RandomGenerator for C#
using System.Security.Cryptography;
namespace Awesome
{
public static class RandomGenerator
{
private static RNGCryptoServiceProvider global =
new RNGCryptoServiceProvider();
[ThreadStatic]
@txdv
txdv / gist:1064214
Created July 5, 2011 03:29
Proposed boundary extensions
using Manos;
using Manos.IO;
using Manos.Threading;
using Manos.IO.Managed;
using System.Threading;
namespace Manos
{
public static class BoundaryExtensions
@txdv
txdv / gist:1067063
Created July 6, 2011 12:00
Manos Udp proposal
using System;
using System.Text;
using Manos.IO;
namespace Test
{
public static class ByteBufferExtensions
{
public static string GetString(this ByteBuffer buffer, Encoding encoding)
@txdv
txdv / gist:1083740
Created July 14, 2011 23:45
DNS dislove
void ParseHost(string host, TimeSpan timeSpan, Action<Exception, string, IPAddress> callback)
{
IPAddress ipaddress;
if (IPAddress.TryParse(host, out ipaddress)) {
callback(null, host, ipaddress);
} else {
bool timeout = false;
Context.CreateTimerWatcher(timeSpan, delegate {
callback(new Exception("Timeout while resolving"), null, null);
timeout = true;
@txdv
txdv / gist:1086482
Created July 16, 2011 15:57
API example of my Manos BinaryStreamReader.
namespace NiceParsing
{
class MainClass
{
public static void Main(string[] args)
{
var packetWrapper = new {
Length = 3,
Number = typeof(byte)
};
@txdv
txdv / gist:1093861
Created July 19, 2011 22:08
Manos.MySql API proposals
public static void Proposal1(Context context)
{
// Old school C# style!
// Has the ability to actually remove those events afterwards!.
MySqlConnector.Connect(context, "test", "test", "password", (stream) => {
var cmd = stream.Query("SELECT name, surname FROM people where city = 'Aachen'");
cmd.OnRow += (row) => {
Console.WriteLine("{0} {1}", row.name, row[1]);
});
cmd.OnEnd += () => {
@txdv
txdv / Epoch.cs
Created July 20, 2011 16:04
Epoch class for handling unix times
using System;
namespace Epoch
{
public class Epoch
{
static readonly DateTime epochStart = new DateTime(1970, 1, 1, 0, 0, 0);
static readonly DateTimeOffset epochDateTimeOffset = new DateTimeOffset(1970, 1, 1, 0, 0, 0, TimeSpan.Zero);
@txdv
txdv / ByteBufferCollection.csproj
Created August 6, 2011 21:54
ByteBufferCollection
<?xml version="1.0" encoding="utf-8"?>
<Project DefaultTargets="Build" ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>10.0.0</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{34F9CC9C-7FA8-4C7C-B21B-139A0C1B56FD}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ByteBufferCollection</RootNamespace>