Skip to content

Instantly share code, notes, and snippets.

View restlessmedia's full-sized avatar
🎯
Focusing

Phil Cooper restlessmedia

🎯
Focusing
View GitHub Profile
@restlessmedia
restlessmedia / webapiconfig.cs
Created March 4, 2016 10:30
.Net WebApi catch all route
config.Routes.MapHttpRoute(
name: "CatchAll",
routeTemplate: "{*.}",
defaults: new { controller = "Default" }
);
public class DefaultController : ApiController
{
[HttpGet]
public HttpResponseMessage Get()
@restlessmedia
restlessmedia / web.config
Created January 28, 2016 11:25
.Net mobile rewrite rule
<rewrite>
<rules>
<rule name="Mobile Rewrite" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" negate="false" />
<conditions logicalGrouping="MatchAny" trackAllCaptures="false">
<add input="{HTTP_USER_AGENT}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-Device-User-Agent}" pattern="midp|mobile|phone" />
<add input="{HTTP_X-OperaMini-Phone-UA}" pattern="midp|mobile|phone" />
</conditions>
<action type="Redirect" url="http://localhost/mobile" appendQueryString="false" redirectType="Found" />
(function () {
var Slide = function (thumbs, image) {
this.thumbs = thumbs || [];
this.image = image || new Image();
this.images = [];
if (this.thumbs.length) {
this.show(0);
}
};
@restlessmedia
restlessmedia / autoPlacement.js
Created December 10, 2015 13:48
Bootstrap tooltip auto placement to prevent tooltip dropping off screen
var autoPlacement = function (tip, element) {
var $document = $(document);
var offset = $(element).offset();
var height = $document.outerHeight();
var width = $document.outerWidth();
var vert = 0.5 * height - offset.top;
var horiz = 0.5 * width - offset.left;
if (Math.abs(horiz) > Math.abs(vert)) {
return horiz > 0 ? 'right' : 'left';
}
private static Exception Create<T>(string message, T exception)
where T : Exception
{
Type exceptionType = typeof(T);
if (typeof(Exception).IsAssignableFrom(exceptionType))
return new Exception(message, exception);
MethodInfo method = _createDel.Method.GetGenericMethodDefinition().MakeGenericMethod(exceptionType);
return method.Invoke(null, new object[] { message, exception }) as Exception;
@restlessmedia
restlessmedia / TimeBlock.cs
Last active August 29, 2015 14:25
TimeBlock - using block for profiling
public class TimeBlock : IDisposable
{
public TimeBlock(Action<int> handler = null, bool start = true)
{
_handler = handler;
_watch = new Stopwatch();
if (start)
Start();
}
var load = function (img) {
var src = img.getAttribute('data-src');
if (src && img.src !== src) {
img.src = src;
}
};
var find = function () {
return document.querySelectorAll('.js-defer');
};
extend = function (members) {
var that = this;
var extended;
if (members && members.constructor) {
extended = members.constructor;
} else {
extended = function () {
return parent.apply(this, arguments);
};
}
(function (Quill) {
var Element = function (tagName, attributes) {
var element = document.createElement(tagName);
if (attributes) {
for (var key in attributes) {
if (attributes.hasOwnProperty(key)) {
element.setAttribute(key, attributes[key]);
}
}
@restlessmedia
restlessmedia / gist:1ac3630dd548f660344f
Last active August 29, 2015 14:16
GetLoadedTypes (extension)
/// <summary>
/// Gets the loaded types for this Assembly and skips if any types cannot be loaded when ReflectionTypeLoadException is thrown.
/// </summary>
/// <param name="assembly"></param>
/// <returns></returns>
public static Type[] GetLoadedTypes(this Assembly assembly)
{
try
{
return assembly.GetTypes();