Skip to content

Instantly share code, notes, and snippets.

View MRdNk's full-sized avatar

Duncan Angus Wilkie MRdNk

View GitHub Profile

map:

function (doc) {
  if (doc.type == 'game' && doc.state == 'closed') {
    emit(['winner', doc.winner, doc.loser], 1);
  }
}

reduce:

@MRdNk
MRdNk / VSCode on OSX.md
Last active August 29, 2015 14:21
VS Code - OSX Notes
@MRdNk
MRdNk / package.json
Last active December 10, 2015 17:39
Node.js Package.json : Setting your test scripts runner
{
"name": "Demo",
"version": "0.0.0",
"description": "description",
"main": "app.js",
"directories": {
"test": "test"
},
"dependencies": {
},
@MRdNk
MRdNk / Behave.md
Last active December 11, 2015 17:28

In 'git bash'

mkdir behave && cd behave
git init
git pull https://github.com/jakiestfu/Behave.js.git master

Copy behave.js, into your local project.

C# List delegate

A delegate allows you perform an action on a list type, FindAll - returns a new list, based on the conditions you put into the delegate.

List<KeyValueBool<int, String>> list = disp.List.FindAll (delegate (KeyValueBool<int, string> kvb) {
  return kvb.Boolean == true;
});
@MRdNk
MRdNk / msnodesql DataTable.md
Last active December 11, 2015 22:18
msnodesql - DataTable

DataTable

var DataTable = function (opts) {
  this.columns = [];
  for (key in opts) {
    if (opts.hasOwnProperty(key)) {
      // this.columns.push (opts[key]);
      this.columns.push (opts[key]);
@MRdNk
MRdNk / Table event listener.md
Last active December 11, 2015 22:28
Example of the output with the new 'table' event emitter. For node.js - msnodesql

Table event listener

var stmt = sql.query(conn_str, "SELECT * from tbl1");
stmt.on('table', function (table) {
  console.log('table', table);
})

An alternative to doing C# List Delegates (https://gist.github.com/4654896) is to use a Predicate / Lambda Expression...

private List<KeyValueBool<TKey, TValue>> _list;

public Boolean Exists (TKey ID) {
  return _list.Exists (item => EqualityComparer<TKey>.Default.Equals (item.Key, ID));
}

public TValue GetValue (TKey ID) {
@MRdNk
MRdNk / Is number type.sql
Created February 8, 2013 15:26
Integer and decimal check in SQL
ISNUMERIC(zipcode + '.0e0') --integer
ISNUMERIC(zipcode + 'e0') --decimal
-- DATE ONLY ELEMENT
SELECT DATEADD(dd, 0,DATEDIFF(dd, 0, GETDATE()))

-- DATE TO NEAREST MINUTE
SELECT DATEADD(mi, DATEDIFF(mi, 0, GETDATE()),0)

-- CONVERT TO TIME as Varchar
SELECT CONVERT(VARCHAR(5), GETDATE(), 108)