Skip to content

Instantly share code, notes, and snippets.

@lancscoder
lancscoder / Todos.Html
Created May 12, 2012 10:52
Node.js implementation of Backbone.js Todos
<div id="credits">
Created by
<br />
<a href="http://jgn.me/">J&eacute;r&ocirc;me Gravel-Niquet</a>. <br />Cleanup, edits: <a href="http://addyosmani.com">Addy Osmani</a>.
</div>
@lancscoder
lancscoder / gist:2345816
Created April 9, 2012 19:19
Getting started with node.js
var http = require('http');
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end('Hello World\n');
}).listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
@lancscoder
lancscoder / Dapper.sql
Created March 18, 2012 11:41
DapperDinner The sql
DECLARE @finish int = 8,
@start int = 1,
@EventDate datetime = '2012-03-13T20:07:25'
SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY RsvpCount desc
) AS RowNumber FROM (
SELECT d.*, COUNT(r.DinnerID) AS RsvpCount
FROM Dinners d LEFT OUTER JOIN RSVP r ON d.DinnerID = r.DinnerID
WHERE EventDate >= @EventDate
@lancscoder
lancscoder / IDinnerRepository.cs
Created March 18, 2012 11:39
DapperDinner Part 3 Object State
public interface IDinnerRepository
{
Dinner NewDinner();
RSVP NewRsvp(int dinnerId);
PagedList<Dinner> FindByLocation(float latitude, float longitude, string orderBy = "DinnerID", int page = 1, int pageSize = 20);
PagedList<Dinner> FindUpcomingDinners(string orderBy = "DinnerID", int page = 1, int pageSize = 20);
PagedList<Dinner> FindUpcomingDinners(DateTime? eventDate, string orderBy = "DinnerID", int page = 1, int pageSize = 20);
PagedList<Dinner> FindDinnersByText(string q, string orderBy = "DinnerID", int page = 1, int pageSize = 20);
IEnumerable<Dinner> AllDinnersByUser(string name);
@lancscoder
lancscoder / GenericFindDinner.cs
Created March 1, 2012 20:44
DapperDinnerRepository Part 2
private PagedList<Dinner> FindDinners(string where, object parameters, string orderBy = "DinnerID", int page = 1, int pageSize = 20)
{
using (var connection = MvcApplication.GetOpenConnection())
{
var builder = new SqlBuilder();
var start = (page - 1) * pageSize + 1;
var finish = page * pageSize;
var selectTemplate = builder.AddTemplate(pagedQuery, new { start, finish });
@lancscoder
lancscoder / DapperDinnerRepository.cs
Created February 19, 2012 10:54
DapperDinnerRepository
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Dapper;
using System.Data.Common;
namespace DapperDinner.Models
{
public class DapperDinnerRepository : IDinnerRepository
@lancscoder
lancscoder / Delete.cs
Created February 14, 2012 19:54
Dapper Going Further
using (var connection = MvcApplication.GetOpenConnection()) {
connection.Delete<Post>( new Post { ID = 1 } );
}
@lancscoder
lancscoder / Delete.cs
Created February 14, 2012 19:28
Entity Framework Getting Started
// Entity Framework - Delete
using (var db = new BlogContext()) {
var post = db.Posts.Find(1);
db.Posts.Remove(post);
db.SaveChanges();
}
@lancscoder
lancscoder / Connection.cs
Created February 14, 2012 19:28
Dapper Getting Started
public class ConnectionFactory {
public static DbConnection GetOpenConnection() {
var connection = new SqlConnection("MyConnectionString");
connection.Open();
return connection;
}
}