Skip to content

Instantly share code, notes, and snippets.

View kosperera's full-sized avatar
🏠
Working from home

Kosala (Nuwan) Perera kosperera

🏠
Working from home
View GitHub Profile
@kosperera
kosperera / DocumentSpec.cs
Created August 16, 2012 13:53
Blogged: Don't ask for anything - Code snippet 3
public class Document
{
private readonly Content html;
public Document(Content content)
{
html = content;
}
}
@kosperera
kosperera / WhenExecuteQuery.cs
Last active December 19, 2015 12:29
One minute unit test code for tombstoning - Code snippet 1
namespace Snikt.Specifications.DatabaseSpecs
{
[TestClass]
public class WhenExecuteQuery
{
[TestMethod]
public void ThenStrongTypedListIsReturned()
{
// Biuld
string nameOrConnectionString = "name=DefaultConnection";
@kosperera
kosperera / CategoryDAO.cs
Created August 31, 2013 13:05
Blogged : Yet another ORM - Code snippet 1 The old-school mapping query results to POCO.
using (IDataReader reader = command.ExecuteReader())
{
List<Category> cats = new List<Category>();
while (reader.Read())
{
int idOrdinal = reader.GetOrdinal("cid");
int nameOrdinal = reader.GetOrdinal("name");
if (!reader.IsDBNull(idOrdinal))
{
@kosperera
kosperera / CategoryDataAccess.cs
Last active December 22, 2015 01:48
Mapping SQL stored procedure query results to an enumerable.
using System;
using System.Data;
using ClassicDalHelpersSample.Business.Entities;
using System.Collections.Generic;
using System.Linq;
using Snikt;
namespace Snikt.Mock
{
public sealed class CategoryDataAccess
@kosperera
kosperera / ReverseArray.js
Created August 5, 2014 19:48
Reverse an array without using another array. This method is called Temporary Swap and it only runs for half of the array.
function reverse(arr)
{
var left = null;
var right = null;
var length = arr.length;
for (left = 0; left < length / 2; left += 1)
{
right = length - 1 - left;
var temporary = arr[left];
arr[left] = arr[right];
@kosperera
kosperera / fizz-buzz.kata.js
Last active August 19, 2018 07:54
Prints Fizz for multiples of 3, and Buzz and for multiples of 5, and FizzBuzz for multiples of both 3 and 5.
function goFizzBuzz(start, end) {
for (let i = start; i <= end; i++) {
if (i % 15 == 0) { console.log('FizzBuzz'); }
else if (i % 3 == 0) { console.log('Fizz'); }
else if (i % 5 == 0) { console.log('Buzz'); }
else { console.log(i); }
}
}
@kosperera
kosperera / selfystic-crash-course.md
Last active November 12, 2016 15:43
Selfystic ionic crash course

Selfystic crash course gists

Playground so we don't have to install anything, I meant, ANYTHING! Ionic is all about Angular and Cordova.

angularjs

<!-- index.html -->

<div class="list" ng-controller="Hello">
@kosperera
kosperera / string.reverse.js
Last active May 2, 2017 19:06
Reverse a string value in JavaScript.
String.prototype.reverse = () => {
return this.split('').reverse().join('');
};
@kosperera
kosperera / missing-indexes-on-tables.sql
Created March 27, 2018 12:09
Find out missing indexes for queries running on the database.
SELECT TOP 20
total_worker_time/execution_count AS Avg_CPU_Time
,Execution_count
,total_elapsed_time/execution_count as AVG_Run_Time
,total_elapsed_time
,(SELECT
SUBSTRING(text,statement_start_offset/2+1,statement_end_offset
) FROM sys.dm_exec_sql_text(sql_handle)
) AS Query_Text
FROM sys.dm_exec_query_stats
@kosperera
kosperera / .npmrc
Last active June 7, 2019 10:09
Clean code style guide examples.
save=true
save-exact=true
loglevel=error
package-lock=false