Skip to content

Instantly share code, notes, and snippets.

View nirinchev's full-sized avatar

Nikola Irinchev nirinchev

  • Realm
  • Copenhagen
View GitHub Profile
@nirinchev
nirinchev / UITableViewExtensions
Last active August 29, 2015 14:15
An extension method to dequeue a cell for use in UITableViewController.GetCell
public static T DequeueReusableCell<T> (this UITableView tableView) where T : UITableViewCell
{
var identifier = typeof(T).Name;
var cell = tableView.DequeueReusableCell (identifier);
if (cell == null)
{
// Nib with the class name MUST exist in the name bundle
var nib = UINib.FromName (identifier, NSBundle.MainBundle);
tableView.RegisterNibForCellReuse (nib, identifier);
@nirinchev
nirinchev / ApiDefinition.cs
Created March 13, 2015 21:18
Additional code to bind tokenizeCard:completion:
[BaseType (typeof (NSObject))]
interface Braintree
{
/* existing methods */
delegate void CompletionCallback (string nonce, NSError error);
[Export ("tokenizeCard:completion:")]
[Async]
void TokenizeCard (BTClientCardTokenizationRequest request, CompletionCallback callback);
}
@nirinchev
nirinchev / Program.cs
Created June 12, 2015 20:20
Haskell course application, problem 3: name matching
using System;
using System.Linq;
namespace Haskell
{
public class Program
{
public static void Main(string[] args)
{
var countData = Console.ReadLine().Split(' ');
@nirinchev
nirinchev / Program.cs
Created June 12, 2015 21:05
Haskell course application, problem 2: language game
using System;
using System.Linq;
namespace Haskell
{
public class Program
{
public static void Main(string[] args)
{
var pattern = Console.ReadLine();
@nirinchev
nirinchev / Program.cs
Created June 12, 2015 22:31
Haskell course application, problem 1: help hass
using System;
using System.Linq;
using System.Collections.Generic;
namespace Haskell
{
public class Program
{
public static void Main(string[] args)
{
public class MyEntity
{
// This will be used for EF queries
public DbGeography Location { get; set; }
// This will be used by OData
public GeographyPoint Coordinates
{
get
{
public class MyContext : DbContext
{
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Entity<MyEntity>()
.Ignore(e => e.Coordinates);
}
}
public class GeoDistanceVisitor : ExpressionVisitor
{
private static readonly MethodInfo distanceMethod = typeof(GeographyOperationsExtensions).GetMethod("Distance");
private static readonly MethodInfo distanceMethodDb = typeof(DbGeography ).GetMethod("Distance");
private static PropertyInfo constantExpressionValuePropertyInfo;
protected override Expression VisitMethodCall(MethodCallExpression node)
{
if (node.Method == distanceMethod)
public class MyComplexEntity
{
public DbGeography FirstPointLocation { get; set; }
public GeographyPoint FirstPointCoordinates { /* ... */ }
public DbGeography SecondPointLocation { get; set; }
public GeographyPoint SecondPointCoordinates { /* ... */ }
}
public class VisitorActionFilterAttribute : ActionFilterAttribute
{
private static readonly GeoDistanceVisitor geoDistanceVisitor = new GeoDistanceVisitor();
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
if (actionExecutedContext.Response != null && actionExecutedContext.Exception == null)
{
var objectContent = actionExecutedContext.Response.Content as ObjectContent;
if (objectContent != null)