Skip to content

Instantly share code, notes, and snippets.

@cobysy
cobysy / XJsonMediaTypeFormatter.cs
Last active September 11, 2020 13:31
Fix of JsonMediaTypeFormatter (ASP.net WebAPI) that does not convert JSON to object when Request is in Chunked Transfer Encoding.
/// <summary>
/// Fix of JsonMediaTypeFormatter that does not convert JSON to object when Request is in Chunked Transfer Encoding.
/// </summary>
public class XJsonMediaTypeFormatter : JsonMediaTypeFormatter
{
/// <summary>
/// Replaces web api default JsonMediaTypeFormatter with this instance.
/// Usage:
/// protected void Application_Start()
/// {
@cobysy
cobysy / gist:59afed79262114a7fbed
Created July 14, 2015 11:37
mongodump (to bson) and bsondump (parse bson to json)
mongodump --host mongodb1.example.net \
--db db_name \
--collection collection_name \
--query '{ _id: { $gte: ObjectId("537c3ca7cfefc541c4a41a8e") } }' \
--out /tmp/mongodump
bsondump tmp/mongodump/Historic.bson/db_name/mongodump.bson
/// Ruthlessly inspired by from http://kozmic.net/2014/03/22/strongly-typed-app-settings-with-castle-dictionaryadapter/
public class AppSettingRequiredAttribute : Attribute
{
}
public class AppSettingWrapperAttribute : DictionaryBehaviorAttribute, IDictionaryPropertyGetter, IPropertyDescriptorInitializer
{
object IDictionaryPropertyGetter.GetPropertyValue(IDictionaryAdapter dictionaryAdapter, string key, object storedValue, PropertyDescriptor property, bool ifExists)
{
/// <summary>
/// "Fast"-implementation of building HashCode
/// </summary>
public static class HashCodeBuilder
{
internal const int Seedingprime = 42;
internal const int Hashingprime = 37;
public static int BuildHashCode(params object[] args)
{
//
// Intervals and method for testing overlapping conditions between two intervals
// Copyright (c) bysy.io
//
public enum IntervalOverlappingCondition
{
Different,
Same,
Overlapping,
@cobysy
cobysy / recursiveFlatMap.swift
Created April 15, 2015 11:55
recursiveFlatMap.swift
// Copyright (c) 2015 bysy.io. All rights reserved.
func recursiveFlatMap<TResult>(#root: AnyObject,
@noescape children: (AnyObject) -> [AnyObject]) -> [TResult]
{
var result = [TResult]()
if let value = root as? TResult {
result.append(value)
}
result += children(root).flatMap( { recursiveFlatMap(root: $0, children: children) as [TResult] } )
let fontFamilyNames = UIFont.familyNames()
for familyName in fontFamilyNames {
println("------------------------------")
println("Font Family Name = [\(familyName)]")
let names = UIFont.fontNamesForFamilyName(familyName as! String)
println("Font Names = [\(names)]")
}
@cobysy
cobysy / How to patch a library imported with Cocoapods
Created March 26, 2015 15:28
How to patch a library imported with Cocoapods
How to patch a library imported with Cocoapods
Forking the library, applying your patch, and pointing to your fork in the Podfile would be your best option.
If the library contains the podspec:
```
pod '<library>', :git => 'https://github.com/yourname/<library>.git'
```
If the library does not contain the podspec, you have to copy the podspec to a local path and adjust it:
// memoized Levenshtein Distance
// description given here: http://programmingpraxis.com/2014/09/12/levenshtein-distance/
import Foundation
// memoize for a two parameter recursive function
func memoize<T1: Hashable, T2: Hashable, U>(body: ((T1, T2) -> U, T1, T2) -> U) -> ((T1, T2) -> U) {
var memo = [T1: [T2: U]]()
var result: ((T1, T2) -> U)!
result = {
@cobysy
cobysy / AFNetworkingGDataXMLHTMLResponseSerializer.m
Last active August 29, 2015 14:04
An XML and HTML response serializer for AFNetworking 2.0, using GDataXML-HTML
//
// AFNetworkingGDataXMLHTMLResponseSerializer.m
//
// Created by _ on 17/07/14.
// Copyright (c) 2014 cobysy. All rights reserved.
//
#import "AFNetworkingGDataXMLHTMLResponseSerializer.h"
#import <GDataXML-HTML/GDataXMLNode.h>