Skip to content

Instantly share code, notes, and snippets.

@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:
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 / 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] } )
//
// Intervals and method for testing overlapping conditions between two intervals
// Copyright (c) bysy.io
//
public enum IntervalOverlappingCondition
{
Different,
Same,
Overlapping,
/// <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)
{
/// 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)
{
@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
@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 / jscpd
Last active September 17, 2015 21:15
jscpd options for c#
fix by adding following line
-------------
options.exclude = options.exclude.split ','
in cli.coffee
(Windows path: C:\Users\xxx\AppData\Roaming\npm\node_modules\jscpd\src\cli\)
jscpd -g csharp -o report.txt --exclude **/*.Designer.cs,**/XsdGeneratedClasses.cs
@cobysy
cobysy / JS-LINQ.js
Created December 18, 2015 15:17 — forked from DanDiplo/JS-LINQ.js
JavaScript equivalents of some common C# LINQ methods. To help me remember!
// JS array equivalents to C# LINQ methods - by Dan B.
// Here's a simple array of "person" objects
var people = [
{ name: "John", age: 20 },
{ name: "Mary", age: 35 },
{ name: "Arthur", age: 78 },
{ name: "Mike", age: 27 },
{ name: "Judy", age: 42 },
{ name: "Tim", age: 8 }