Skip to content

Instantly share code, notes, and snippets.

View troygoode's full-sized avatar
🤓
Building nerdy stuff.

Troy Goode troygoode

🤓
Building nerdy stuff.
View GitHub Profile
using System;
using System.Linq;
using System.IO;
using System.Xml.Linq;
using System.Threading;
namespace TumblrAPI.ConsoleApp
{
class Program
{
require 'rake'
def foo(task, name, *args)
args || args = []
args.insert 0, task
body = lambda {
puts 'Hello, ' + name
}
public ActionResult UpdateProfile(ProfileInputModel input, Individual individual){
if(!ModelState.IsValid)
return View(new ProfileInputModel());
Mapper.Map<ProfileInputModel, Individual>(input, individual);
foreach(var email in input.Emails)
individual.UpdateEmailAddress(email.Key, email.Value);
return RedirectToAction("ViewProfile");
}
public class IndividualController : BaseController{
[HttpPost]
public ActionResult UpdateProfile(UpdateProfileInputModel inputModel)
{
return Form(inputModel, View("UpdateSucceeded"), View("UpdateFailed"));
}
}
public class UpdateProfileInputModelHandler : IFormHandler<UpdateProfileInputModel>
{
@troygoode
troygoode / MySurvey2010.cs
Created January 21, 2011 18:25
Example of versionned survey object.
// survey definitions
public abstract class SurveyDefinition{
public string Id{ get; set; }
public string Survey{ get; set; }
public string Version{ get; set; }
public abstract Survey Generate();
}
public class MySurvey2010 : SurveyDefinition{
@troygoode
troygoode / app.js
Created May 14, 2011 14:28
Number type is broken in Mongoose 1.3.3
// Setup Schema
// ------------
var
mongoose = require('mongoose'),
Schema = mongoose.Schema;
mongoose.model('Bug', new Schema({
someNumber: Number
}));
var Bug = mongoose.model('Bug');
@troygoode
troygoode / pagedlist_example.cs
Created June 29, 2011 04:03
PagedList Example
const int pageSize = 10;
var allProducts = database.Products.All(); //15 products
//products 1-10
var firstPage = allProducts.ToPagedList(0, pageSize);
Assert.Equal(10, firstPage.Count);
Assert.False(firstPage.HasPreviousPage);
Assert.True(firstPage.HasNextPage);
//products 11-15
@troygoode
troygoode / pagedlist_mvc_examples.cshtml
Created June 29, 2011 04:23
PagedList MVC Examples
<h2>Out-of-the-box Pager Configurations</h2>
<h3>Default Paging Control</h3>
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfProducts, page => Url.Action("Index", new { page = page }))
<h3>Minimal Paging Control</h3>
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfProducts, page => Url.Action("Index", new { page = page }), PagedListRenderOptions.Minimal)
<h3>Minimal Paging Control w/ Page Count Text</h3>
@Html.PagedListPager((IPagedList)ViewBag.OnePageOfProducts, page => Url.Action("Index", new { page = page }), PagedListRenderOptions.MinimalWithPageCountText)
@troygoode
troygoode / MyRenderOptions.cs
Created June 29, 2011 04:35
PagedList Custom RenderOptions
public class MyRenderOptions : PagedList.Mvc.PagedListRenderOptions{
public MyRenderOptions() : base(){
DisplayLinkToFirstPage = false;
DisplayLinkToLastPage = false;
DisplayLinkToIndividualPages = false;
LinkToPreviousPageFormat = "< Go Back";
LinkToNextPageFormat = "Go Forward >";
}
}
@troygoode
troygoode / generic_buy_signal.js
Created July 6, 2011 16:57
Generic Buy Signal
function(contact, activities, config){
var sortByActivityDateDescending = function(activity1, activity2){
if (activity1.activityDate > activity2.activityDate) return -1;
if (activity1.activityDate < activity2.activityDate) return 1;
return 0;
};
if(config.timeframe)
var earliestDateToProcess = new Date().setDate(newDate().getDate() - config.timeframe);
var sortedActivities = activities.sort(sortByActivityDateDescending);