Skip to content

Instantly share code, notes, and snippets.

View philjones88's full-sized avatar

Phil Jones philjones88

View GitHub Profile
public List<foo> Get_Empty()
{
return new List<foo>();
}
@philjones88
philjones88 / gist:1601338
Created January 12, 2012 16:08
RavenDB Patch Delete
store.DatabaseCommands.DeleteByIndex("Foos/QueryByBar",
new IndexQuery
{
Query = "Id:*"
}, allowStale: false);
@philjones88
philjones88 / gist:1634476
Created January 18, 2012 17:56
RavenDB Paging
public static class QueryableExtensions
{
public static IQueryable<T> Paging<T>(this IQueryable<T> query, int currentPage, int defaultPage, int pageSize)
{
return query
.Skip((currentPage - defaultPage) * pageSize)
.Take(pageSize);
}
}
@philjones88
philjones88 / gist:1669683
Created January 24, 2012 11:16
WTF SagePay
'** Doubles up single quotes to stop breakouts from SQL strings **
Public Shared Function SQLSafe(ByVal strRawText As String) As String
Dim strCleanedText As String = ""
Dim iCharPos As Integer = 1
Do While iCharPos <= Len(strRawText)
'** Double up single quotes, but only if they aren't already doubled **
If Mid(strRawText, iCharPos, 1) = "'" Then
strCleanedText = strCleanedText & "''"
@philjones88
philjones88 / gist:1868911
Created February 20, 2012 11:51
Blog: deletebyindex example
store.DatabaseCommands.DeleteByIndex("Enquiries/MyEnquiryIndexName",
new IndexQuery
{
Query = "Id:*"
}, allowStale: false);
@philjones88
philjones88 / gist:1868915
Created February 20, 2012 11:52
Blog: delete hilop example
store.DatabaseCommands.Delete("Raven/Hilo/enquiries", null);
@philjones88
philjones88 / gist:2398753
Created April 16, 2012 13:26
ASP.NET SMTP SpecifiedPickupDirectory
<system.net>
<mailSettings>
<smtp deliveryMethod="SpecifiedPickupDirectory">
<specifiedPickupDirectory pickupDirectoryLocation="D:\Projects\temp" />
<network host="localhost" />
</smtp>
</mailSettings>
</system.net>
@philjones88
philjones88 / gist:5468369
Created April 26, 2013 16:00
For @rippo on AngularJS services and promises, also shows routing and resolve :)
var app = angular.module('sample', ['ngSanitize'], function ($routeProvider) {
var $base = "/admin/partial?path=Admin/PartialViews/";
$routeProvider
.when("/offer", {
templateUrl: $base + 'Offer/list.cshtml', controller: OfferListController, resolve: {
model: function (offerService) {
return offerService.list();
}
}
@philjones88
philjones88 / gist:5728559
Created June 7, 2013 11:06
Paging in AngularJS
// Route, notice reloadOnSearch is set to false
.when('/enquiry', {
templateUrl: $base + 'Enquiry/list.cshtml', controller: EnquiryListController, reloadOnSearch: false, resolve: {
items: function ($route, enquiryService) {
var page = $route.current.params.page;
if (page == undefined) page = 1;
return enquiryService.list(page);
}
@philjones88
philjones88 / gist:5729135
Created June 7, 2013 13:11
ugly angularjs pager generator
app.directive("pager", function ($compile) {
function generate(currentPage, totalPages, click) {
// How many adjacent pages should be shown on each side?
var adjacents = 2;
//previous page is page - 1
var prev = currentPage - 1;
//next page is page + 1
var next = currentPage + 1;