Skip to content

Instantly share code, notes, and snippets.

View johnw86's full-sized avatar

John Walker johnw86

View GitHub Profile
@johnw86
johnw86 / Entity Framework snippets
Created May 11, 2012 10:07
Entity Framework connections for both SQL CE and SQL
//Sql CE - Database name will be set based on the DbContext inherited class
//If no App_Data folder exists you need to create it
Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0");
//Uses default conn string but setting a connection string in config with the name of the context will override conn string
Database.DefaultConnectionFactory = new SqlConnectionFactory();
@johnw86
johnw86 / RazorPaging.cshtml
Created May 15, 2012 11:01
Razor google style paging
@*Required variables,
Page - being the current page
PageCount - total pages
*@
@if (PageCount > 0)
{
var pagesEachWay = 2;
var pagesToShow = 5;
.NamedColors(@name, @color)
{
(~"body.@{name}") {
h1{
color: @color;
}
}
(~"li.@{name}"){
a{
background-image: ~'url("/media/@{name}_triangle.png")';
@johnw86
johnw86 / Controller
Created May 28, 2012 19:40
Working with Google Visualizations in C# MVC and Razor
public ActionResult Index()
{
ViewBag.Data = new Bortosky.Google.Visualization.GoogleDataTable(ExampleTable()).GetJson();
return View();
}
private static DataTable ExampleTable()
{
var dt = new DataTable();
@johnw86
johnw86 / IE Fixes
Created June 27, 2012 13:12
Fixes for IE issues
:after in IE7
#content blockquote:after,
#content blockquote .after {
background:url('/images/background/_sprite.png');
background-position:-259px -66px;
bottom:26px;
content:'';
display:block;
height:14px;
@johnw86
johnw86 / jQuery ajax content load
Created August 13, 2012 19:58
Basic ajax Jquery script for populating list page with next items
<script>
$(function() {
$('a.more').click(function(e) {
e.preventDefault();
var url = $(this).attr('href');
//Show loading symbol
$('.loader').show();
$.get(url, function(data) {
var $data = $(data);
@johnw86
johnw86 / CSS Snippets
Last active October 10, 2015 02:37
Snippets of helpful css to speed up dev
/*sprite bg*/
background:url('../images/background/_sprite.png') no-repeat 0px 0px;
/*border radius - each side*/
-webkit-border-radius: 5px 5px 5px 5px;
border-radius: 5px 5px 5px 5px;
/*border radius - equal sides*/
-webkit-border-radius: 5px;
border-radius: 5px;
@johnw86
johnw86 / JS Snippets
Created October 9, 2012 09:15
Snippets of helpful js to speed up dev
/* Faster get element by ID */
var a = $(document.getElementById("elementID"));
/* Email address regex */
^([\w-]+\.)*?[\w-]+@[\w-]+\.([\w-]+\.)*?[\w]+$
@johnw86
johnw86 / disqus.js
Last active August 29, 2015 13:59
Load Disqus comments on click
/* Disqus load comments */
$('#load-comments').on('click', function (e) {
e.preventDefault();
var loadBtn = $(this);
if (!loadBtn.hasClass('disabled')) {
loadBtn.addClass('disabled');
//Remove any old errors
$("#content").find('.comments_error').remove();
/* Basic equals expression */
//Line by line
ParameterExpression pe = Expression.Parameter(typeof(Object), "x");
Expression left = Expression.Property(pe, typeof(Object).GetProperty("PropertyName"));
Expression right = Expression.Constant("value");
Expression expression = Expression.Equal(left, right);
var lambda = Expression.Lambda<Func<Object, bool>>(expression, pe);
// Short hand