Skip to content

Instantly share code, notes, and snippets.

View mattjcowan's full-sized avatar

MJC mattjcowan

View GitHub Profile
@mattjcowan
mattjcowan / web.config
Created January 16, 2017 17:46
letsencrypt .well-known acme-challenge (static file issue resolved when using ServiceStack)
<?xml version = "1.0" encoding="UTF-8"?>
<configuration>
<!-- PUT THIS FILE INSIDE THE .well-known directory to re-instate static file recognition -->
<system.webServer>
<staticContent>
<mimeMap fileExtension = ".*" mimeType="text/json" />
</staticContent>
<handlers>
<clear />
<add name="StaticFile" path="*." verb="*" type="" modules="StaticFileModule,DefaultDocumentModule,DirectoryListingModule" scriptProcessor="" resourceType="Either" requireAccess="Read" allowPathInfo="false" preCondition="" responseBufferLimit="4194304" />
@mattjcowan
mattjcowan / riotjs-custom-loader.js
Created May 5, 2016 04:23
auto load css, less, js files in same directory as riotjs tag, with same name with webpack
var riot = require('riot-compiler'),
loaderUtils = require('loader-utils'),
fs = require('fs'),
path = require('path');
module.exports = function (source) {
var content = source;
var options = loaderUtils.parseQuery(this.query);
public static bool AreIdenticalPaths(DirectoryInfo dir1, DirectoryInfo dir2)
{
return string.Compare(
dir1.FullName.TrimEnd('/', '\\'),
dir2.FullName.TrimEnd('/', '\\'),
StringComparison.InvariantCultureIgnoreCase) == 0;
}
public static string MapPath(string virtualPath)
// adapted from Umbraco and NopCommerce source
public static void RestartAppDomain()
{
if (GetTrustLevel() > AspNetHostingPermissionLevel.Medium)
{
//full trust
HttpRuntime.UnloadAppDomain();
TryWriteWebConfig();
public static void DeleteDirectory(string path, bool recurse = false)
{
try
{
if (Directory.Exists(path))
Directory.Delete(path, recurse);
}
catch (IOException)
{
Thread.Sleep(100);
// From: http://stackoverflow.com/questions/627504/what-is-the-best-way-to-recursively-copy-contents-in-c
public static void CopyDirectory(DirectoryInfo source, DirectoryInfo target, bool overwrite = true,
bool recurse = false, bool throwOnError = true)
{
try
{
//check if the target directory exists
if (Directory.Exists(target.FullName) == false)
{
@mattjcowan
mattjcowan / relative_path_from_to.cs
Last active April 25, 2016 02:44
Get relative path from one file to another on windows in C#
// See here for the following 2 methods: http://stackoverflow.com/questions/703281/getting-path-relative-to-the-current-working-directory
/// <summary>
/// Gets the relative path ("..\..\to_file_or_dir") of the current file/dir (to) in relation to another (from)
/// </summary>
/// <param name="to"></param>
/// <param name="from"></param>
/// <returns></returns>
public static string GetRelativePathFrom(this FileSystemInfo to, FileSystemInfo from)
@mattjcowan
mattjcowan / DTO.java.nunjucks
Last active December 14, 2015 21:06
A gulpfile with a 'codegen' task (from command line: gulp codegen) that you can use to code-generate files (in my case Android java files) against a ServiceStack /types/metadata.json endpoint ...
{%- extends "package.java.template.nunjucks" -%}
{%- set templateName = "models/DTO.nunjucks" -%}
{%- set subPackage = ".models" -%}
{%- import 'macros.java.nunjucks' as macros -%}
{% block content %}
import java.math.*;
import java.util.*;
import net.servicestack.client.*;
import com.google.gson.annotations.*;
@mattjcowan
mattjcowan / add-express-to-servicestack-project.bat
Last active November 25, 2015 06:03
ServiceStack and Visual Studio on the server, node.js/express/http-proxy and your favorite JS IDE on Mac/Linux,
REM Create a project using the AngularJS Template from ServiceStack
REM Run it, and make sure it works
REM We're going to use Express (i.e.: develop the SPA on a mac in your favorite IDE)
REM Copy default.cshtml to index.html for Express to load the home page
copy default.cshtml index.html
REM Install 3 npm packages to proxy api calls
npm install express --save