Skip to content

Instantly share code, notes, and snippets.

@julesx
julesx / AndroidDocumentViewer.cs
Last active October 4, 2018 07:43
Xamarin Forms file opener
using Android.Content;
using Mobile.Core.Droid.NativeImplementations;
using Mobile.Core.Interfaces;
using Xamarin.Forms;
[assembly: Xamarin.Forms.Dependency(typeof(DocumentViewer))]
namespace Mobile.Core.Droid.NativeImplementations
{
public class DocumentViewer : IDocumentViewer
{
@Maverik
Maverik / ExchangePowershellQuery.cs
Last active January 3, 2018 16:08
Call Exchange Powershell Commands from C# using minimal module definitions only
static readonly SerializationTypeConverter Converter = new SerializationTypeConverter();
static readonly Command SelectSerializationDataCommand = new Command("Select-Object") { Parameters = { { "Property", "SerializationData" } } };
static IEnumerable<T> ExchangeSerializerCastTo<T>(IEnumerable<object> results) => results.Where(x => Converter.CanConvertFrom(x, typeof(T)))
.Select(x => Converter.ConvertFrom(x, typeof(T), CultureInfo.CurrentCulture, false))
.OfType<T>();
void Main()
{
var state = InitialSessionState.CreateDefault2();
//Exchange2010SP3.psm1 was created using `Export-PSSession -OutputModule Exchange2010SP3 -CommandName *` command
@mariusschulz
mariusschulz / ExternalJavaScriptFileAttribute.cs
Last active April 16, 2020 15:24
Here's the ExternalJavaScriptFileAttribute that I showed in my blog post "Generating External JavaScript Files Using Partial Razor Views" (see http://blog.mariusschulz.com/generating-external-javascript-files-using-partial-razor-views).
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Mvc;
namespace DemoApp
{
public class ExternalJavaScriptFileAttribute : ActionFilterAttribute
{
@johnnyreilly
johnnyreilly / DemoAreaRegistration.cs
Last active October 29, 2019 13:43
What you need to unit test MVC controllers using MOQ.
using System.Web.Mvc;
namespace DemoApp.Areas.Demo
{
public class DemoAreaRegistration : AreaRegistration
{
public override string AreaName
{
get
{
@johnpolacek
johnpolacek / gist:3827270
Last active January 20, 2023 15:46
Prevent FOUC
<!-- Prevent FOUC (flash of unstyled content) - http://johnpolacek.com/2012/10/03/help-prevent-fouc/ -->
<style type="text/css">
.no-fouc {display: none;}
</style>
<script type="text/javascript">
document.documentElement.className = 'no-fouc';
// add to document ready: $('.no-fouc').removeClass('no-fouc');
</script>
@scottrippey
scottrippey / jQuery.antiforgerytoken.js
Created August 22, 2012 18:21
ASP.NET MVC AntiForgeryToken + AJAX = jQuery to the rescue
// Setup CSRF safety for AJAX:
$.ajaxPrefilter(function(options, originalOptions, jqXHR) {
if (options.type.toUpperCase() === "POST") {
// We need to add the verificationToken to all POSTs
var token = $("input[name^=__RequestVerificationToken]").first();
if (!token.length) return;
var tokenName = token.attr("name");