Skip to content

Instantly share code, notes, and snippets.

@bhameyie
bhameyie / gist:5663784
Last active December 17, 2015 19:58
using RestSharp and imdbapi.com to get movie data
public class Finder
{
RestClient client = new RestClient("http://www.imdbapi.com/");
public delegate void FindingMovie(string content);
public event FindingMovie OnMovieFound;
public void FindMovie(string title)
{
var request = new RestRequest(string.Format("?i=&t={0}&plot=full", title),Method.GET);
@bhameyie
bhameyie / gist:5663797
Last active December 17, 2015 19:58
deserializing using JSon.NET
void OnMovieFound(string content)
{
var movie = JsonConvert.DeserializeObject<Movie>(content);
if (movie != null && movie.Response == "True")
{
this.movieTitleTextBlock.Text = movie.Title;
this.plotTextBlock.Text = movie.Plot;
this.ratingTextBlock.Text = movie.Rating;
this.releasedDattetextBlock.Text = movie.Released;
@bhameyie
bhameyie / gist:5663837
Created May 28, 2013 15:58
Albacore goodness
require 'rubygems'
require "bundler/setup"
require 'fileutils'
require 'albacore'
require 'git'
$dir=Dir.pwd.gsub("/","\\")
$testdb="myTestDbConnectionString"
$proddb="MyProdDbConnectionString"
@bhameyie
bhameyie / gist:5663867
Created May 28, 2013 16:03
Conditional reference for mvc on mono
First, I had to add new configuration to my csproj file
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Mac|AnyCPU'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>AnyCPU</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
In my mapping class, the method signature would be similar to this:
public abstract class FluentMap<TEntity> {
protected MyMapStuff Map(Expression<Func<TEntity, object>> propertyExpression){
return this;
}
}
My Expression takes func where TEntity is a class such as ‘MyEntity’, and the return type is object, thus covering all various returns value seeing as every class inherit from System.Object.
@bhameyie
bhameyie / gist:5664333
Created May 28, 2013 17:08
Mochy git with ruby mocha
require "test/unit"
require "mocha"
require_relative '../lib'
require "git"
class GitWrapTest < Test::Unit::TestCase
def test_fails_if_untrackedFiles_present_before_pull
git = mock()
fakeStatus= mock()
fakeStatusCount = mock()
@bhameyie
bhameyie / gist:5666592
Created May 28, 2013 22:17
mvc enum helper
public static class EnumHelper
{
public static List<SelectListItem> GetEnumItems<T>(this T enumType)
{
var values = (T[]) Enum.GetValues(typeof (T));
return values.Select(e => new SelectListItem {Selected = enumType.Equals(e), Text = e.ToString(), Value = e.ToString()}).ToList();
}
public static string GetEnumStrings<T>()
@bhameyie
bhameyie / gist:5666602
Created May 28, 2013 22:18
knockoutjs with mvc
@using Charcoal.Core.Entities
@using Charcoal.Models
@model Charcoal.Models.StoryViewModel
<div class="modal-form" id="createStoryModal">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">
×</button>
<h3 id="myModalLabel">
Create Story</h3>
</div>
@bhameyie
bhameyie / gist:5666641
Created May 28, 2013 22:27
pivotaltrackerdotnet sample
//Getting the authentication token
var token = AuthenticationService.Authenticate(Constants.Username, Constants.Password);
//With the authentication token, retrieving those stories is trivial
var service = new StoryService(token);
var stories= service.GetCurrentStories(projectId);
//This will return a list of Story objects with their associated tasks. If you would prefer getting the Iterations, which contains a list of stories *without their associated tasks*, that is easy as well.
@bhameyie
bhameyie / gist:5666658
Created May 28, 2013 22:32
render view as string with mvc
protected string RenderPartialViewToString(string viewName, object model)
{
if (string.IsNullOrEmpty(viewName))
viewName = ControllerContext.RouteData.GetRequiredString("action");
ViewData.Model = model;
using (var sw = new StringWriter())
{
var viewResult = ViewEngines.Engines.FindPartialView(ControllerContext, viewName);