Skip to content

Instantly share code, notes, and snippets.

Ken Egozi kenegozi

Block or report user

Report or block kenegozi

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@kenegozi
kenegozi / untyped-mongodb.cs
Created Aug 28, 2012
Accessing mongodb using the official c# driver without types
View untyped-mongodb.cs
using System;
using MongoDB.Bson;
using MongoDB.Driver;
using MongoDB.Driver.Wrappers;
using Newtonsoft.Json;
namespace Mongothingies {
class Program {
static void Main() {
var server = MongoServer.Create();
View javascript-proxying-example.js
var x = {
doThis : function() { console.log('doThis'); },
whatIsThat : function(i) { console.log('whatIsThis'); return 'that is ' + i; },
name : 'I am x'
};
for (methodName in x) {
var method = x[methodName];
if (typeof method !== 'function') continue;
x[methodName] = (function(method, methodName) {
@kenegozi
kenegozi / static-latency-logging.cs
Created Jul 22, 2012
Statically logging method call latencies
View static-latency-logging.cs
interface IDoWork {
void DoThis();
string WhatsThat(int that);
}
class DoWork : IDoWork {
public void DoThis() {
Log.Action("DoWork.DoThis", () => DoThisImpl() );
}
@kenegozi
kenegozi / use_inheritance.cs
Created Oct 8, 2011
Pass compositioned data to views
View use_inheritance.cs
// adding GeneralView class with IsCurrentUserAdmin bool field,
// Derive LayoutView from GeneralView
// Derive HomepageView and PostPageView from LayoutView
public ActionResult ViewPost(string permalink) {
var post = magic.GetPostBy(permalink);
var view= new PostView {Post=post};
GetLayoutData(view);
view.Related = magic.GetContentRelatedTo(post);
Return View(view);
@kenegozi
kenegozi / IncludeInterfacesModelMetadataProvider.cs
Created Aug 22, 2011
Allowing MVC3 model validator to use interface attributes
View IncludeInterfacesModelMetadataProvider.cs
class IncludeInterfacesModelMetadataProvider : DataAnnotationsModelMetadataProvider {
protected override IEnumerable<Attribute> FilterAttributes(Type containerType, PropertyDescriptor propertyDescriptor, IEnumerable<Attribute> attributes) {
var validationAttributesOnInterfaces =
from i in containerType.GetInterfaces()
from p in i.GetProperties()
where p.Name == propertyDescriptor.Name
from a in p.GetCustomAttributes(true).Cast<Attribute>()
where typeof(ValidationAttribute).IsAssignableFrom(a.GetType())
select a;
@kenegozi
kenegozi / RandomAd.cs
Created Jul 5, 2011
Super dumbed-down ad server - serving a random image every-time.
View RandomAd.cs
using Manos;
using System;
using System.IO;
public class RandomAd : ManosApp {
public RandomAd () {
var ads = Directory.GetFiles(".", "*.gif");
var random = new Random();
Route ("/", ctx=> {
@kenegozi
kenegozi / ParallelHttpRequests.cs
Created Mar 15, 2011
Demonstrating the use of WebClient.DownloadStringAsync to parallelize http requests
View ParallelHttpRequests.cs
class ParallelHttpRequests
{
static void Main()
{
var count = 300;
var root = "http://files.kenegozi.com/temp/";
ServicePointManager.DefaultConnectionLimit = 1000;
@kenegozi
kenegozi / fix_crlf.bat
Created Sep 16, 2010
fixing text files to DOS style line endings (CRLF)
View fix_crlf.bat
c:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe fix_crlf.cs
fix_crlf.exe
You can’t perform that action at this time.