Skip to content

Instantly share code, notes, and snippets.

@dax70
dax70 / gist:1126337
Created August 4, 2011 21:33
KnockoutJS updating observables
function Model(){
this.selectedItems = ko.observableArray();
this.selectNone = function () {
this.selectedItems().length = 0;
this.selectedItems.valueHasMutated();
}
this.hasItemsSelected = ko.dependentObservable(function () {
return this.selectedItems().length > 0;
}, this);
}
html {
background: #f6f6f6;
padding: 24px;
text-align: center;
}
a {
border-radius: 4px;
display: inline-block;
@dax70
dax70 / dabblet.css
Created May 5, 2012 05:59
Image/Profile look
html {
background: #f6f6f6;
padding: 24px;
text-align: center;
}
a {
border-radius: 4px;
display: inline-block;
@dax70
dax70 / dabblet.css
Created May 5, 2012 06:13 — forked from anonymous/dabblet.css
Image Shadow
img {
position: relative;
display: block;
content: "";
}
img:before {
display: block;
content: "";
position: absolute;
@dax70
dax70 / gist:2760197
Created May 21, 2012 01:18
Json.Net Settings example of ContractResolver
var settings = new JsonSerializerSettings
{
ContractResolver = new ConfigurableContractResolver()
}
JsonSerializer serializer = JsonSerializer.Create(settings);
serializer.Serialize(textWriter, valueToSerialize);
@dax70
dax70 / gist:2760442
Created May 21, 2012 03:30
A better IContractResolver for Json.NET
using System;
using System.Globalization;
using Newtonsoft.Json;
using Newtonsoft.Json.Serialization;
namespace MvcJson
{
public class ConfigurableContractResolver: DefaultContractResolver
{
public bool UseCamelCase { get; set; }
@dax70
dax70 / CSS Formatting
Created June 11, 2012 23:57
Example of CSS formatting ala Twitter Bootstrap
.border {
border: 1px solid #ccc;
border: 1px solid rgba(0, 0, 0, 0.15);
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
}
@dax70
dax70 / gist:2942507
Created June 16, 2012 21:03
JsonNetResult Logic
// Data (like the default JsonResult) is the Model being serialized.
Type type = this.Data.GetType();
// Wrap Enumerables to avoid potential Json Hijacking.
if (TypeHelper.TryWrappingForIEnumerableGenericOrSame(ref type))
{
this.Data = TypeHelper.GetTypeRemappingConstructor(type).Invoke(new object[] { this.Data });
}
using (JsonTextWriter jsonTextWriter = new JsonTextWriter(response.Output) { CloseOutput = false })
{
@dax70
dax70 / gist:2942515
Created June 16, 2012 21:14
EnumerableWrapper for JsonNET
using System;
using System.Collections.Generic;
using System.Linq;
namespace MvcJson.Net.Models
{
public class EnumerableWrapper<T>
{
public EnumerableWrapper(IEnumerable<T> items)
{
@dax70
dax70 / gist:2942622
Created June 16, 2012 21:57
Controller override for Json.NET
/// <summary>
/// Creates a System.Web.Mvc.JsonResult object that serializes the specified object to JavaScript Object Notation (JSON).
/// </summary>
/// <param name="data">The JavaScript object graph to serialize.</param>
/// <param name="contentType">The content type (MIME type).</param>
/// <param name="contentEncoding">The content encoding.</param>
/// <param name="behavior">The JSON request behavior</param>
/// <returns>
/// The JSON result object that serializes the specified object to JSON format.
/// The result object that is prepared by this method is written to the response