Skip to content

Instantly share code, notes, and snippets.

using System;
public class Test
{
public static void Main()
{
var amount = 39.105;
Console.WriteLine(Math.Round(amount, 2, MidpointRounding.AwayFromZero)); // 39.1
}
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.3.0/knockout-min.js"></script>
<meta charset="utf-8">
<title>JS Bin</title>
</head>
<body>
<div id="currentPerson" >
ko.numericObservable = function(initialValue) {
var _actual = ko.observable(initialValue);
var result = ko.computed({
read: function() {
return _actual();
},
write: function(newValue) {
var parsedValue = parseFloat(newValue);
_actual(isNaN(parsedValue) ? newValue : parsedValue);
@jmarmolejos
jmarmolejos / gitfu
Created August 13, 2015 16:09
Some git commands I keep forgetting.
git diff upstream/develop -- **/Partial/Path/To/File.cs
@jmarmolejos
jmarmolejos / GET.cs
Last active September 13, 2015 15:30
public async Task<List<Notification>> Get()
{
var uriBuilder = GetCouchUrl();
using (var client = new MyCouchClient(uriBuilder.Build()))
{
var notifications = await client.Views.QueryAsync<Notification>(new QueryViewRequest("notifications-doc", "all-notifications"));
return notifications.Rows.Select(r => r.Value).ToList();
}
}
function (doc) {
emit(doc._id, doc);
}
public async Task<List<Notification>> Get()
{
var uriBuilder = GetCouchUrl();
using (var client = new MyCouchClient(uriBuilder.Build()))
{
var notifications = await client.Views.QueryAsync<Notification>(new QueryViewRequest("notifications-doc", "all-notifications"));
return notifications.Rows.Select(r => r.Value).ToList();
}
}
private MyCouchUriBuilder GetCouchUrl()
{
// assuming you're using cloudant
return new MyCouchUriBuilder("https://[username].cloudant.com/")
.SetDbName("notifications")
.SetBasicCredentials("[usename]", "[password]");
}
namespace CouchWebApi.Models
{
public class Notification
{
public string Alert { get; set; }
public int Count { get; set; }
}
}
public async Task<Notification> Post(Notification notification)
{
var uriBuilder = GetCouchUrl();
using (var client = new MyCouchClient(uriBuilder.Build()))
{
var response = await client.Entities.PostAsync(notification);
return response.Content;
}