Skip to content

Instantly share code, notes, and snippets.

View Sheeo's full-sized avatar

Michael Søndergaard Sheeo

View GitHub Profile
### Keybase proof
I hereby claim:
* I am sheeo on github.
* I am sheeo (https://keybase.io/sheeo) on keybase.
* I have a public key ASAsgdfQbU465HBWjqtKsmabv5UOF2And0qn1J9VBkQZ-go
To claim this, I am signing this object:
@Sheeo
Sheeo / foo.ts
Created December 26, 2016 22:39
export function CalculateIntegrationField(room: Room, goalName: string, goals: [number, number][]): IntegrationField {
if(!goals) throw new Error("No goals provided");
if(!room.memory.costField || room.memory.costFieldInvalid) {
CalculateCostField(room);
}
let pre = Game.cpu.getUsed();
let costField = room.memory.costField;
let integrationField: number[][] = [];
let openList: [number, number][] = [];
#!/usr/bin/env python3
"""
Usage:
server.py [--nodb | --db TYPE]
Options:
--nodb Don't use a database (Use a mock.Mock). Caution: Will break things.
--db TYPE Use TYPE database driver [default: QMYSQL]
"""
@Sheeo
Sheeo / gist:3789611
Created September 26, 2012 18:13
Improved runtests
#!/bin/bash
progname=$(basename $0)
print_short_help() {
cat <<EOF
Usage: $progname [-1] [-f] [-r] [-p phases] [-c compiler] <tests-dir>
EOF
}
(** Additions to weedingast.ml, bottom **)
let type_decl_members td = match td.type_decl with
| Class d -> d.class_members
| Interface i -> i.interface_members
let decl_name decl = match decl.decl with
| Field f -> f.field_name.Ast.identifier
| Method m -> m.method_name.Ast.identifier
| Constructor c -> c.constructor_name.Ast.identifier
@Sheeo
Sheeo / gist:3371002
Created August 16, 2012 15:23
Sql Server SSI
public override void CreateNewOutputRows()
{
string strCurrency;
string flRate;
XmlDocument xm = new XmlDocument();
xm.Load(Variables.ECBRL.ToString());
XmlNodeList xnode = xm.GetElementsByTagName("Cube");
DateTime date = DateTime.Parse(xm.GetAttribute("time"));
using System;
using System.Security.Permissions;
using System.Threading;
class ThreadInterrupt
{
static void Main()
{
StayAwake stayAwake = new StayAwake();
Thread newThread =
let printMatrixRec2((mat : int[][])) =
let rec iterate r c =
match r, c with
| m,n when n = mat.[m].Length-1 && m = mat.Length-1 -> printf " %d" mat.[m].[n]; () // Base case, last entry: Stop recursion when r,c are at bounds of Mat int[][] array
| m,n when n = mat.[m].Length-1 -> printf " %d\n" mat.[m].[n]; iterate (m+1) 0 // Special case: last column of row m, print special and iterate next row
| m,n when n=0 -> printf "%d " mat.[m].[n]; iterate m (n+1) // Special case: first column of m
| m,n -> printf " %d " mat.[m].[n]; iterate m (n+1) // Normal case: entry m,n
iterate 0 0
mat
|> Array.iteri (fun m i -> Array.iter (fun n -> printfn "%d" mat.[m].[n]) mat.[m])
// vs
mat
|> Array.iteri (fun m i -> mat.[m]
|> (fun n -> printfn "%d" mat.[m].[n]))
// vs
@Sheeo
Sheeo / gist:1337590
Created November 3, 2011 19:50
Generic awesomeness in C#
public void Add<TEntity>(TEntity t) where TEntity : class
{
var properties = (from p in GetType().GetProperties()
select p.GetGetMethod(true));
var genericProperties = (from property in GetType().GetProperties()
let returntype = property.GetGetMethod(true).ReturnType
where returntype.IsGenericType
where returntype.GetGenericArguments().Length == 1
let argumenttype = returntype.GetGenericArguments().First()
where argumenttype == typeof (TEntity)