Skip to content

Instantly share code, notes, and snippets.

View AlexShkor's full-sized avatar

Alex Shkor AlexShkor

View GitHub Profile
@AlexShkor
AlexShkor / Global.asax.cs
Created April 11, 2013 17:50
SignalR LowerCamelCaseContractResolver repro
var serializer = new MyJsonSerializer();
GlobalHost.DependencyResolver.Register(typeof(IJsonSerializer), () => serializer);
@AlexShkor
AlexShkor / Global.asax.cs
Created April 12, 2013 10:33
correct SignalRContractResolver with CamelCasePropertyNamesContractResolver
var settings = new JsonSerializerSettings();
settings.ContractResolver = new SignalRContractResolver();
var serializer = new JsonNetSerializer(settings);
GlobalHost.DependencyResolver.Register(typeof (IJsonSerializer), () => serializer);
@AlexShkor
AlexShkor / ko.parse.js
Last active December 17, 2015 02:59
Parsing KnockoutJS model into flat key-value form data
var parseValues = function (data, callback, prefix, postfix) {
postfix = postfix || "";
prefix = prefix || "";
for (var key in data) {
if (data[key] == null) {
continue;
}
if ( Object.prototype.toString.call( data[key] ) === '[object Array]') {
parseValues(data[key], callback, prefix + key + postfix + "[", "]");
} else if (typeof data[key] == "object") {
@AlexShkor
AlexShkor / KnockoutHtmlHelper.cs
Created May 9, 2013 11:47
HtmlHelper for applying Knockout model
using Newtonsoft.Json;
namespace System.Web.Mvc
{
public static class HtmlHelperExt
{
private const string BaseApplyModelScriptString = @"<script type=""text/javascript"">
$(function () {{
var model = new AllMessagesModel({0});
ko.applyBindings(model);
@AlexShkor
AlexShkor / gist:6018730
Created July 17, 2013 08:16
Amazon S3 helper
public class AmazonS3Helper
{
private readonly string _amazonAccessKey;
private readonly string _amazonSecretKey;
private const string BucketName = "zertisedpm";
public AmazonS3Helper(string amazonAccessKey, string amazonSecretKey )
{
_amazonAccessKey = amazonAccessKey;
_amazonSecretKey = amazonSecretKey;
@AlexShkor
AlexShkor / gist:6250733
Created August 16, 2013 15:07
send json as plain form data
var sendJson = function(url, json, callback){
var data = {};
parseValues(json, function(key, value) {
data[key] = value;
});
$.post(url, data,callback);
};
var parseValues = function (data, callback, prefix, postfix) {
@AlexShkor
AlexShkor / gist:7115055
Created October 23, 2013 08:58
send model
var sendModel = function (url, model, successCallback, ignoreList) {
model.Loading(true);
var mapping = {
ignore: ignoreList
};
sendJson(url, ko.mapping.toJS(model,mapping), function(response) {
var defaultBehaviour = true;
if (successCallback) {
var result = successCallback(response);
if (result === false) {
@AlexShkor
AlexShkor / gist:7115182
Created October 23, 2013 09:09
JsonModel in BaseController
protected JsonResult JsonModel<T>(T model) where T : BaseViewModel
{
model.Errors = GetErorsModel().ToList();
return Json(model);
}
protected IEnumerable<ValidationError> GetErorsModel()
{
foreach (var state in ModelState)
{
[POST]
public JsonResult UploadImage(HttpPostedFileBase uploadedFile)
{
var cloudinary = new CloudinaryDotNet.Cloudinary(ConfigurationManager.AppSettings.Get("cloudinary_url"));
bool isValidImage;
if (uploadedFile != null)
{
isValidImage = uploadedFile.IsValidImage(250, 250);
}
@AlexShkor
AlexShkor / gist:cd089e0bf2d71ff22b7a
Created June 18, 2015 10:48
Location IBsonSerializable
public struct Location : IBsonSerializable
{
public const double LatitudeMinValue = -90;
public const double LatitudeMaxValue = 90;
public const double LongitudeMinValue = -180;
public const double LongitudeMaxValue = 180;
private const double PIx = 3.141592653589793;
public const double EarthRaduisInKm = 6378.16;
public const double EarthRaduisInMiles = 3959;