Skip to content

Instantly share code, notes, and snippets.

@vkobel
vkobel / Lexer.fs
Last active August 29, 2015 14:01
Simple lexer for a minimalist asm-like language
module Lexer
open System
open System.IO
open System.Text.RegularExpressions
type Register =
| A // 8 bits
| B // 8 bits
| D // 16 bits (A + B)
@vkobel
vkobel / async_await.cs
Last active August 29, 2015 14:02
Simple Async Await remainder
using System;
using System.Threading.Tasks;
namespace AsyncAwaitTest {
class Program {
async static void DoIt() {
Console.WriteLine("Enter DoIt!");
await Task.Delay(2000);
Console.WriteLine("DoIt has ended!");
@vkobel
vkobel / KobInjector.cs
Last active August 29, 2015 14:05
Simple Dependency Injector (contructors only) in .NET C#
using System;
using System.Collections.Generic;
using System.Linq;
namespace KobInjector {
/// <summary>
/// Simple Exeption to be thrown if a paramter cannot be resolved, it displays the whole injection stack
/// </summary>
public class InjectionStackException : Exception {
@vkobel
vkobel / underscoreCase.cs
Created August 7, 2014 14:22
Simple C# extension method to convert a camel case string to underscore notation without any regex
public static class ExtensionMethods {
public static string ToUnderscoreCase(this string str) {
return string.Concat(str.Select((x, i) => i > 0 && char.IsUpper(x) ? "_" + x.ToString() : x.ToString())).ToLower();
}
}
@vkobel
vkobel / links.js
Last active August 29, 2015 14:05
Retrieve links (ajax created) on a website for further processing using PhantomJS (http://phantomjs.org/)
@vkobel
vkobel / web.config
Created September 4, 2014 01:52
Symfony web.config for IIS
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<rewrite>
<rules>
<rule name="Imported Rule 1" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" ignoreCase="false" negate="true" />
</conditions>
@vkobel
vkobel / groupbytimespan.cs
Created October 9, 2014 11:24
Group datetimes by duration. Here it will make 3 groups of 15 minutes each
using System;
using System.Linq;
namespace GroupbyTimespan {
class Program {
static void Main(string[] args) {
DateTime[] dateTimes = new[]{
new DateTime(2010, 8, 24, 0, 5, 0),
new DateTime(2010, 8, 24, 0, 10, 0),
@vkobel
vkobel / index.html
Last active August 29, 2015 14:07
invaders pure js
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body{
background-color: #333;
text-align: center;
font-family: Helvetica;
color: #999;
}
@vkobel
vkobel / brainfuck.js
Last active August 29, 2015 14:07
Brainfuck interpreter [Work in progress]
function brainLuck(code, input){
function matchingBracket(code, instPtr){
var count = 1;
while(count > 0){
var c = code[++instPtr];
if(c === '[') count++;
else if(c === ']') count--;
}
return instPtr;
@vkobel
vkobel / depInj.js
Created November 4, 2014 10:47
Simple Dependency Injector in JavaScript
var DI = function (dependency) {
this.dependency = dependency;
};
// Should return new function with resolved dependencies
DI.prototype.inject = function (func) {
var startIdx = func.toString().indexOf('(');
var endIdx = func.toString().indexOf('{');
var paramsRaw = func.toString().substr(startIdx, endIdx - startIdx).trim();
var params = paramsRaw.substr(1, paramsRaw.length -2).replace(/ /g, '').split(',');