Skip to content

Instantly share code, notes, and snippets.

View tawman's full-sized avatar

Todd A. Wood tawman

View GitHub Profile
@tawman
tawman / Index.cshtml
Created February 19, 2012 01:51
PetaPocoPage View with a Table and DataTables Configuration
@{
ViewBag.Title = "Server-Side Paging with PetaPoco DataTables";
}
<table id="customers" class="table table-striped table-condensed">
<thead>
<tr>
<th style='width: 4%'>Id</th>
<th>Last</th>
<th>First</th>
@tawman
tawman / DataTableModelBinder.cs
Last active September 30, 2015 20:58
PetaPocoPage View IModelBinder to map the DataTable page request into a simple request object
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using PetaPocoPage.Models;
namespace PetaPocoPage.Helpers
{
public class DataTablesModelBinder : IModelBinder
@tawman
tawman / HomeController.cs
Created February 19, 2012 02:15
PetaPocoPage Home Controller made simple with IModelBinder and Response Helper
using System.Web.Mvc;
using PetaPocoPage.Helpers;
using PetaPocoPage.Models;
using PetaPocoPage.Services;
namespace PetaPocoPage.Controllers
{
public class HomeController : Controller
{
private readonly Repository _repository = new Repository();
@tawman
tawman / DataTableFormat.cs
Created February 19, 2012 02:18
PetaPocoPage Helper to format the JSON page response to DataTables
using System.Globalization;
using System.Linq;
using PetaPoco;
using PetaPocoPage.Models;
namespace PetaPocoPage.Helpers
{
public class DataTablesFormat
{
public static object PageResponse(DataTablesPageRequest pageRequest, Page<Customer> report)
@tawman
tawman / Repository.cs
Created February 19, 2012 02:35
PetaPocoPage Repository method to handle the PetaPoco Page<T> query based on the DataTables request object
using System.Collections.Generic;
using PetaPoco;
using PetaPocoPage.Models;
namespace PetaPocoPage.Services
{
public class Repository
{
private readonly Database _database = new Database("PetaPocoPageDb");
@tawman
tawman / StructureMapFilterProvider.cs
Created February 20, 2012 19:08
Glimpse Issue 146 Sample Code of Helper used to setup StructureMap for FilterAttribute Injection
using System.Collections.Generic;
using System.Linq;
using System.Web.Mvc;
using StructureMap;
namespace Sample.Web.Helpers
{
public class StructureMapFilterProvider : FilterAttributeFilterProvider
{
public StructureMapFilterProvider(IContainer container)
@tawman
tawman / SamplePetaPocoPageCustomSql.cs
Created March 19, 2012 19:57
Sample PetaPoco Page<T> Use Case for Pull Request to support Custom Count and Page SQL
public Page<SampleOption> GetAvailableSampleOptionsFor(int pageNumber, int pageSize, Guid companyId, Guid requirementId, string whereClause, string searchText, string orderBy)
{
// Build our own Paging Count(*) query to use
var countQuery = Sql.Builder.Append(@"
WITH pcr(Id, ParentSampleGroupId, GroupLevel) AS
(SELECT cg.Id, cg.ParentSampleGroupId, 0 as GroupLevel
FROM SampleGroup cg INNER JOIN SampleWidgetGroupLimit l ON l.SampleGroupId = cg.Id
WHERE l.SampleWidgetId = @1
union all
select np1.Id, np1.ParentSampleGroupId, GroupLevel + 1
@tawman
tawman / BashShell.txt
Created April 15, 2012 19:31
Sample Bash Shell Process Listing Command Output
kvothe:~ todd$ ps aux -u 9633
USER PID %CPU %MEM VSZ RSS TT STAT STARTED TIME COMMAND
todd 9633 0.0 0.7 961216 57948 ?? S 10:16AM 0:04.65 /Applications/Google Chrome.app/Contents/MacOS/Google Chrome -psn_0_7591741
kvothe:~ todd$ ps aux -u 9633 | file -
/dev/stdin: ASCII text
@tawman
tawman / PowerShell.txt
Created April 15, 2012 19:34
PowerShell Command Object Pipeline
PS C:\> Get-Process -id 5904
Handles NPM(K) PM(K) WS(K) VM(M) CPU(s) Id ProcessName
------- ------ ----- ----- ----- ------ -- -----------
1651 71 71700 74296 306 256.05 5904 chrome
PS C:\> Get-Process -id 5904 | Format-List *
__NounName : Process
Name : chrome
@tawman
tawman / git-flavor.sh
Created June 29, 2012 05:26
Flavor your git repository with some bacon!
#!/bin/bash
if [ ! -d $1/.git ]
then
echo "usage : $0 <repository root directory>"
exit
fi
declare -a baconbits=($(curl -s 'http://baconipsum.com/api/?type=all-meat&paras=5&start-with-lorem=1' | sed s/[^\ a-zA-Z\-]//g))
bitsize=${#baconbits[@]}
idx=0