Skip to content

Instantly share code, notes, and snippets.

View philjones88's full-sized avatar

Phil Jones philjones88

View GitHub Profile
@philjones88
philjones88 / gist:7b6d917e159a9fa75609
Last active August 29, 2015 14:08
Hypermedia Question
Assuming your web app supports deep linking, like an AngularJS one would.
Assume basic crud of Foo. So list, create, edit and delete.
If a user bookmarks in your app an edit page or simply refreshes the page, thanks to deep linking you now skip over the list part of navigation.
So the user's browser hits:
http://example.org/#/foos/1
@philjones88
philjones88 / gist:0e818ebcbcf08318b61f
Last active August 29, 2015 14:02
SignalR token authentication middleware (crappy quick coding)
public static class QueryStringTokenConverterExtension
{
public static IAppBuilder QueryStringTokenConverter(this IAppBuilder app, string queryStringParameterName = "authorization", string requestHeaderName = "Authorization")
{
return app.Use<QueryStringTokenConverter>(queryStringParameterName, requestHeaderName);
}
}
public class QueryStringTokenConverter
{
@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;
@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: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: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:1868915
Created February 20, 2012 11:52
Blog: delete hilop example
store.DatabaseCommands.Delete("Raven/Hilo/enquiries", null);
@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: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: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);
}
}