Skip to content

Instantly share code, notes, and snippets.

View csharpforevermore's full-sized avatar
🏠
Working from home

Randle csharpforevermore

🏠
Working from home
View GitHub Profile
@csharpforevermore
csharpforevermore / CustomersEntityFramework6.cs
Created January 10, 2015 15:57
The attributes prevent null errors affecting the ID field "sessionId".
public class Customers
{
[Key]
[DatabaseGenerated(DatabaseGeneratedOption.None)]
public long Sessionid { get; set; }
public long? Pers { get; set; }
}
@csharpforevermore
csharpforevermore / WebDownloadManager.cs
Created January 9, 2015 12:51
WebClient replacement that adds a timer (default is 1 minute)
using System;
using System.Net;
public class WebDownload : WebClient
{
/// <summary>
/// Time in milliseconds
/// </summary>
public int Timeout { get; set; }
@csharpforevermore
csharpforevermore / UserDetailsProvider.cs
Created January 9, 2015 08:18
Get user IP address. Whilst not 100% infallible, it works through proxies better than the "HTTP_X_FORWARDED_FOR" which is returned when a proxy is being used.
protected string GetIPAddress()
{
System.Web.HttpContext context = System.Web.HttpContext.Current;
string ipAddress = context.Request.ServerVariables["HTTP_X_FORWARDED_FOR"];
if (!string.IsNullOrEmpty(ipAddress))
{
string[] addresses = ipAddress.Split(',');
if (addresses.Length != 0)
{
// Vanilla JavaScript - trim Leading and Trailing - ES5
function TrimVanilla(str){
return str.trim();
}
// Older browsers - IE8 and before - using Polyfill. Call trim() method after running this.
function TrimPolyfill(){
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^\s+|\s+$/g, '');
@csharpforevermore
csharpforevermore / MultiUrlPickerHelper.cshtml
Last active August 29, 2015 14:11
Umbraco 7 Plugin - RJP Multi Url Picker
@{
var multiUrlPicker = Model.Content.GetPropertyValue<MultiUrls>("multiUrlPicker");
if (multiUrlPicker.Any())
{
<ul>
@foreach (var item in multiUrlPicker)
{
<li><a href="@item.Url" target="@item.Target">@item.Name</a></li>
}
</ul>
Here are all the classes from Bootstrap 3 (version 3.1.1).
Method of extraction:
1. Download Bootstrap 3 and rename bootstrap.css as "bootstrap.html"
2. Add the following 24 lines of code to the very bottom of the bootstrap.html file:
<script src="http://code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/lodash.js/2.4.1/lodash.min.js"></script>
<script>
@csharpforevermore
csharpforevermore / main.js
Last active August 29, 2015 14:09
Replaces all missing images with a placeholder image
$(window).load(function() {
$('img').error(function () {
var width = $(this).width();
var height = $(this).height();
if ((width > 0) && (height > 0)) {
$(this).attr('src', '//placehold.it/' + width + 'x' + height);
// Or, hide them
// $(this).hide();
}
});
@csharpforevermore
csharpforevermore / UmbracoNav.cshtml
Created November 4, 2014 02:40
Umbraco navigation using Razor
@*
NESTED NAVIGATION WITH START AND FINISH LEVELS
=======================================
This snippet makes it easy to do navigation based lists! It'll automatically produce a nested list all children of a page within certain
levels in the hierarchy that's published and visible (it'll filter out any pages with a property named "umbracoNaviHide"
that's set to 'true'.
Based on the inbuilt Navigation script in Umbraco 4.7
How to Customize for re-use (only applies to Macros, not if you insert this snippet directly in a template):
- If you add a Macro Parameter with the alias of "StartLevel" you can define the starting level for which nodes will be displayed
@csharpforevermore
csharpforevermore / Controller.cs
Created November 2, 2014 18:26
MVC Controller - handle unknown action using override HandleUnknownAction(string actionName)
public class HomeController : Controller
{
//
// GET: /Home/
public ActionResult Index()
{
return View();
}
protected override void HandleUnknownAction(string actionName)
@csharpforevermore
csharpforevermore / UmbracoChangeDocTypeParent
Last active August 29, 2015 14:08 — forked from drift/UmbracoChangeDocTypeParent
Umbraco use of version 6's ContentTypeService
@using Umbraco.Core.Models;
@using Umbraco.Core.Services;
var contentTypeService = ApplicationContext.Current.Services.ContentTypeService;
var contentType = contentTypeService.GetContentType(4200);
contentType.ParentId=3130;
contentTypeService.Save(contentType);