Skip to content

Instantly share code, notes, and snippets.

@rpheath
rpheath / jquery.infinitescroll.js
Created November 2, 2010 01:48
A jQuery plugin for bi-directional infinite scrolling
// A bi-directional infinite scrolling jQuery plugin
//
// Usage Example:
// $(window).infiniteScroll({ url: window.location.href })
(function($) {
$.scroller = {
// default settings
settings: {
url: null,
@drewjoh
drewjoh / custom.js
Created January 27, 2012 13:55
Dynamic (AJAX) loaded Bootstrap Modal (Bootstrap 2.1)
$(document).ready(function() {
// Support for AJAX loaded modal window.
// Focuses on first input textbox after it loads the window.
$('[data-toggle="modal"]').click(function(e) {
e.preventDefault();
var url = $(this).attr('href');
if (url.indexOf('#') == 0) {
$(url).modal('open');
} else {
@steelheaddigital
steelheaddigital / ExampleUsage
Created July 30, 2012 23:01
An extension of the ASP.NET MVC WebGrid HTML helper to add a total row
In the ViewModel or Controller, create a new TotalWebGrid and return it to the view, just like with the normal WebGrid.
public TotalWebGrid Grid
{
get
{
return new TotalWebGrid(
source: stagingBillLines,
rowsPerPage: 10,
ajaxUpdateContainerId: "BillLines");
@afsharm
afsharm / gist:5660844
Last active December 8, 2021 17:22
How to add a simple file upload functionality to CKEditor in ASP.NET MVC. Use CKEditor as CKEDITOR.replace('Description', { filebrowserImageUploadUrl: '/ControllerName/UploadImage' }); It is an updated version of http://arturito.net/2010/11/03/file-and-image-upload-with-asp-net-mvc2-with-ckeditor-wysiwyg-rich-text-editor/ For more information see
[AcceptVerbs(HttpVerbs.Post)]
public ActionResult UploadImage(HttpPostedFileBase upload, string CKEditorFuncNum, string CKEditor, string langCode)
{
//http://stackoverflow.com/a/4088194/167670
//http://arturito.net/2010/11/03/file-and-image-upload-with-asp-net-mvc2-with-ckeditor-wysiwyg-rich-text-editor/
//http://haacked.com/archive/2010/07/16/uploading-files-with-aspnetmvc.aspx
if (upload.ContentLength <= 0)
return null;
@bmancini55
bmancini55 / CookieTempDataProvider.cs
Created July 24, 2013 18:35
ASP.NET MVC CookieTempDataProvider
public class CookieTempDataProvider : ITempDataProvider
{
// Change cookie name to whatever you want it to be
const string TempDataCookieKey = "__TempData";
HttpContextBase httpContext;
#region Constructors
public CookieTempDataProvider(HttpContextBase httpContext)
{
@mkropat
mkropat / ui-router-logging.js
Last active July 31, 2016 19:38
Automatic trace logging of Angular.js events and ui-router state transitions
angular.module('your-module').config(['$provide', function ($provide) {
$provide.decorator('$rootScope', ['$delegate', function ($delegate) {
wrapMethod($delegate, '$broadcast', function (method, args) {
if (isNonSystemEvent(args[0]))
logCall('$broadcast', args);
return method.apply(this, args);
});
wrapMethod($delegate, '$emit', function (method, args) {
@benhysell
benhysell / Upload.cs
Created July 2, 2015 14:06
c# httpClient webapi post user created class object with zip file
//build zip file
using (var zip = new ZipFile(zipFilePath))
{
zip.AddDirectory("Zip files go here");
zip.Save(zipFilePath);
}
//create upload package
var uploadData = new NewObjectThatGoesAlongWithTheFile(SomeDataToCreateObject);
uploadData.ResultFileMd5 = CalculateMd5(zipFilePath); //calculate an md5 to compare on the other side
@benhysell
benhysell / BaseRepository.cs
Created July 6, 2015 14:40
c# Entity Framework Query With Cancellation
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Net.Http;
using System.Net.Http.Handlers;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
@benhysell
benhysell / WebApiPostWithProgress.cs
Last active February 13, 2024 16:51
c# web api post with progress reporting
//in setup define client and progress reporter
var httpProgressHandler = new ProgressMessageHandler();
httpProgressHandler.InnerHandler = new HttpClientHandler();
var client = new HttpClient(httpProgressHandler) { BaseAddress = new Uri(Settings.Default.ServerUrl) };
//register to use elsewhere in the application, note it is better to resuse for lifetime of application than create for every call
Mvx.RegisterSingleton(client);
Mvx.RegisterSingleton(httpProgressHandler);
@benhysell
benhysell / retry.cs
Created October 23, 2015 18:27
Polly - Back Off and Retry on Error http client
//Retry http with a back off on failure
await Policy.Handle<HttpRequestException>().WaitAndRetryAsync(3, retryAttempt => TimeSpan.FromSeconds(Math.Pow(2, retryAttempt)))
.ExecuteAsync(async () =>
{
var result = await httpClient.GetAsync("api/CallToServer/" + varibleToSendToServer, cancellationToken);
if (result.IsSuccessStatusCode)
{
returnValue = await result.Content.ReadAsAsync<List<Results>>(token);
}