Skip to content

Instantly share code, notes, and snippets.

@vkobel
vkobel / wiki.go
Created November 29, 2013 14:05
Simple Go Lang tutorial -> create a wiki
package main
import(
"html/template"
"io/ioutil"
"net/http"
"regexp"
)
type Page struct {
@vkobel
vkobel / RxDragDrop.cs
Last active August 10, 2020 05:04
Simple Drag & Drop with Reactive Extensions
using System;
using System.Reactive.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
namespace RxDragAndDrop {
public partial class MainWindow : Window {
@vkobel
vkobel / GetKeys.cs
Created May 27, 2013 08:55
Simple method to retrieve the keys of an entity in EF. The thing here is to convert the dumb DbContext into a much more powerful ObjectContext.
public IEnumerable<string> GetPrimaryKeyNames<T>() {
ObjectSet<T> objCtx = (ctx as IObjectContextAdapter).ObjectContext.CreateObjectSet<T>();
return objCtx.EntitySet.ElementType.KeyMembers.Select(k => k.Name);
}
@vkobel
vkobel / gitignore.sh
Created May 14, 2013 07:25
git commands to update a non-working .gitignore file on the repository.
git rm -r --cached .
git add .
git commit -m ".gitignore is now working"
@vkobel
vkobel / GenericPropertyMethods.cs
Created May 13, 2013 12:33
Simple extension methods for objects, generic and list of objects to get and set properties (and related stuff).
using System;
using System.Collections.Generic;
using System.Reflection;
namespace Vkobel.ExtensionMethods {
public static class GenericPropertyMethods {
public static PropertyInfo GetProperty(this object obj, string name) {
return obj.GetType().GetProperty(name);
}
@vkobel
vkobel / IRepository.cs
Last active January 10, 2025 04:05
Generic C# .NET Repository pattern (interface + implementation)
using System;
using System.Linq;
using System.Linq.Expressions;
namespace Data.GenericRepo {
public interface IRepository<T> : IDisposable where T : class {
T[] GetAll();
IQueryable<T> Query(Expression<Func<T, bool>> predicate);
@vkobel
vkobel / example.fs
Created April 29, 2013 06:29
Example F# file from Microsoft
// This sample will guide you through elements of the F# language.
//
// *******************************************************************************************************
// To execute the code in F# Interactive, highlight a section of code and press Alt-Enter or right-click
// and select "Execute in Interactive". You can open the F# Interactive Window from the "View" menu.
// *******************************************************************************************************
//
// For more about F#, see:
// http://fsharp.net
//
@vkobel
vkobel / build.sbt
Created April 23, 2013 19:48
sbt build file for akka actors dependencies
name := "Akka actors"
version := "1.0"
scalaVersion := "2.10.1"
resolvers += "Typesafe Repository" at "http://repo.typesafe.com/typesafe/releases/"
libraryDependencies += "com.typesafe.akka" %% "akka-actor" % "2.1.2"
@vkobel
vkobel / futures.scala
Created April 23, 2013 19:43
Simple use of akka futures (now part of scala library)
package akkaActors
import scala.concurrent.Await // enable awaiting a future
import scala.concurrent.duration._ // enable convert in to ms n.seconds
import scala.concurrent.Future // Future function
import scala.concurrent.ExecutionContext.Implicits.global // import global execution context (implicit way)
object futureTest extends App {
// Create and begin execution of the Future
@vkobel
vkobel / akkaActors.scala
Created April 23, 2013 19:40
Example of how a simple system of actor and futures works in akka and scala
package akkaActors
import akka.actor.{ Actor, ActorSystem, Props, PoisonPill }
import akka.pattern.ask // enable the use of ? or ask that return a future from an actor
import akka.util.Timeout
import scala.concurrent.Await
import scala.concurrent.Future
import scala.concurrent.ExecutionContext.Implicits.global // import global execution context (implicit way)
class HelloActor extends Actor {