Skip to content

Instantly share code, notes, and snippets.

View joeriks's full-sized avatar
💭
I may be slow to respond.

Jonas Eriksson joeriks

💭
I may be slow to respond.
View GitHub Profile
@joeriks
joeriks / TaskRun.cs
Last active August 29, 2015 13:56
C# async await the most basic example
void slowTask(){
Console.WriteLine("Prints after");
}
void Main()
{
Task.Run(()=>slowTask());
Console.WriteLine("Prints immediately");
}
@joeriks
joeriks / math_in_jquery
Created February 13, 2014 08:02
Excel like calculations are horrible with jquery - time to move to knockout/angular
function flt(fieldName) {
var parsedValue = parseFloat($('#' + fieldName).val().replace(",", "."));
if (isNaN(parsedValue)) parsedValue = 0;
$('#' + fieldName).val(parsedValue);
return parsedValue;
}
function recalculate(reset) {
var r1 = (flt("i1") * 1000 - 2 * flt("i4"));
$("#r1").val(Math.round(r1));
@joeriks
joeriks / OrigoGettingStarted.cs
Last active August 29, 2015 13:56
OrigoDb Gettingstarted
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using OrigoDB.Core;
using System.Collections.Generic;
using System.Linq;
namespace PlayingWithOrigoDB
{
[TestClass]
public class QuickStartGuide
@joeriks
joeriks / jamp.md
Last active August 29, 2015 13:56
thoughts about a web fw

(1) = exists in preview state (2) = planned next (3) = planned

main stuff

  • completely free and open source
  • convention over configuration
  • simple to use
  • reliable
@joeriks
joeriks / parallell.cs
Created February 4, 2014 10:14
Don't forget to test parallell actions
/* Lock dictionary between read and write */
public T Do(string key, Func<T,T> func){
lock (_dictionary) {
var originalValue = get<T>(key);
var newValue = func(originalValue);
set(key, newValue);
return newValue;
}
}
@joeriks
joeriks / MyHub.cs
Created February 3, 2014 14:53
SignalR and FnX.EsentStore
using System;
using System.Web;
using Microsoft.AspNet.SignalR;
using System.Collections.Generic;
namespace SignalRChat
{
public class ChatHub : Hub
{
@joeriks
joeriks / express_proxy.js
Last active January 4, 2016 19:29
Very simple nodejs+express proxy = servs all url's from the proxied to localhost:1235 - and it supports POST, PUT et c
var express = require('express'),
app = express.createServer(),
request = require('request');
app.listen(process.env.PORT || 1235);
app.use('/hello',function (req, res) {
res.send('This comes from node w express');
});
@joeriks
joeriks / 1_sample_typecode.text
Last active January 3, 2016 08:19
A second version of grammar for a simple domain type DSL experiment (using PEGjs) see also http://joeriks.com/2014/01/14/a-simple-dsl-code-generation-using-node/
Foo.BarBas
Project
Foo:string
Id:key
Name
Write project name :label
You need to state the project name:err
Address
@joeriks
joeriks / DomainTypeDSL.grammar
Created January 15, 2014 09:04
domain type DSL (peg grammar) version 2
// do not use result cache, nor line and column tracking
/* sample:
Project
Id :key
Name
Write project name:label
You need to state the project name:err
Address
SomeValue :num
@joeriks
joeriks / names.peg
Created January 15, 2014 08:06
peg grammar for simple name parsing
start = (fullname:fullname "\n"? {return fullname})*
name =
char:[A-Za-z]+ { return char.join(""); }
fullname =
firstName:name " " secondName:name {return {fn:firstName, sn:secondName}}
/* foo bar
baz bang */