Skip to content

Instantly share code, notes, and snippets.

View romeshniriella's full-sized avatar
🎯
Building blockchain infrastructure

Romesh Niriella romeshniriella

🎯
Building blockchain infrastructure
  • Melbourne, VIC, AU
View GitHub Profile
@romeshniriella
romeshniriella / BestPracticeDisposePattern.cs
Last active August 29, 2015 14:00
How to properly close and dispose using an extension method.
//http://www.niedermann.dk/2009/06/18/BestPracticeDisposePatternC.aspx
public class BestPracticeDisposePattern : IDisposable
{
private bool m_IsDisposed;
~BestPracticeDisposePattern()
{
Dispose(false);
}
@romeshniriella
romeshniriella / DynamicJsonConverter
Last active August 29, 2015 14:04
Dynamic Json Converter
// From: http://stackoverflow.com/a/3806407/959245
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Dynamic;
using System.Linq;
using System.Text;
using System.Web.Script.Serialization;
(function (ko, handlers, unwrap, extend) {
"use strict";
extend(handlers, {
href: {
update: function (element, valueAccessor) {
handlers.attr.update(element, function () {
return { href: valueAccessor() };
});
}
},
using System;
using System.IO;
using System.Web;
/// <summary>
/// Removes CSS from rendered HTML page.
/// </summary>
public class InlineCssModule : IHttpModule
{
@romeshniriella
romeshniriella / grouped-locations.json
Last active August 29, 2015 14:14
Select2 Grouped Static Data With AJAX Fallback
{
"results":[
{
"text":"Country",
"children":[
{
"id":11082,
"text":"SRI LANKA (LK)"
},
{
@romeshniriella
romeshniriella / ko.bindingHandlers.data.js
Last active August 29, 2015 14:17
knockout "data-" attribute binding handler
// Usage:
// <span data-bind="text: FromDate, data: { 'item' : ItemID}"></span> => 'data-item' has ItemID() value
// <span data-bind="text: FromDate, data: { 'value' : $data}"></span> => 'data-value' will be rendered as JSON
// <span data-bind="text: FromDate, data: { 'item' : ItemID, value' : $data}"></span> => more than one data attribute
//
// or something confusing as
// <span data-bind="text: FromDate, data: ItemID, name: 'item'"></span>
ko.bindingHandlers.data = {
@romeshniriella
romeshniriella / ko.binding-handlers.js
Created April 7, 2015 04:29
Binding handlers used in my App. Extracted from everywhere. Some of the original sources unknown.
ko.bindingHandlers.money = {
update: function (element, valueAccessor, allBindingsAccessor, viewModel) {
var value = valueAccessor();
var allBindings = allBindingsAccessor();
var valueUnwrapped = ko.utils.unwrapObservable(value) || 0;
var output = output = accounting.formatMoney(valueUnwrapped, OKLO.CurrencySign);
if ($(element).is("input") === true) {
@romeshniriella
romeshniriella / BingMailEasyPostApi.cs
Last active August 29, 2015 14:19
Bing-Mail Easy Post Api - Version 1.3
public class SessionObject
{
public string user { get; set; }
public string account { get; set; }
public string session_id { get; set; }
}
public class BingMailConfigOptions
{
public string AuthUserName { get; set; }
@romeshniriella
romeshniriella / Extensions.cs
Last active August 29, 2015 14:19
Extract all MVC / WebApi area/controller/actions
public static class Extensions{
public static TInner IfNotNull<T, TInner>(this T source, Func<T, TInner> selector, bool createNew = false)
where T : class
{
return source != null
? selector(source) : (createNew ? Activator.CreateInstance<TInner>() : default(TInner));
}
}
@romeshniriella
romeshniriella / random-colors.js
Created May 22, 2015 11:15
Random Background & eye-friendly Fore-color generation
function shadeColor2(color, percent, hash) {
var f=parseInt((hash? color.slice(1) : color),16),
t=percent<0?0:255,
p=percent<0?percent*-1:percent,
R=f>>16,
G=f>>8&0x00FF,
B=f&0x0000FF;
return (0x1000000
+(Math.round((t-R)*p)+R)*0x10000