Skip to content

Instantly share code, notes, and snippets.

View nicbell's full-sized avatar
🎯
Focusing

Nic Bell nicbell

🎯
Focusing
  • inja
  • London | Biarritz
View GitHub Profile
@nicbell
nicbell / UIString.kt
Created December 8, 2022 13:00
UIString: Allows switching between strings and string resources without additional logic in the view. Also avoids accessing Android platform classes outside of the view to resolve strings.
import android.content.res.Resources
import android.os.Parcelable
import androidx.annotation.StringRes
import kotlinx.parcelize.Parcelize
/**
* UIString: Allows switching between strings and string resources without additional
* logic in the view. Also avoids accessing Android platform classes outside of the view
* to resolve strings.
*/
@nicbell
nicbell / 1_primitive_comparison.js
Last active September 23, 2022 16:56
JavaScript object deep comparison. Comparing x === y, where x and y are values, return true or false. Comparing x === y, where x and y are objects, returns true if x and y refer to the same object. Otherwise, returns false even if the objects appear identical. Here is a solution to check if two objects are the same.
//Primitive Type Comparison
var a = 1;
var b = 1;
var c = a;
console.log(a == b); //true
console.log(a === b); //true
console.log(a == c); //true
console.log(a === c); //true
@nicbell
nicbell / PublishedContentWrappedExtensions.cs
Created September 26, 2016 11:18
Umbraco multiple hostnames, get correct url for a page, based on the domain of the current page.
public static class PublishedContentWrappedExtensions
{
public static string GetContextAwareUrl(this PublishedContentWrapped content)
{
var urls = new List<string>();
urls.Add(UmbracoContext.Current.RoutingContext.UrlProvider.GetUrl(content.Id));
urls.AddRange(UmbracoContext.Current.RoutingContext.UrlProvider.GetOtherUrls(content.Id));
var url = urls.FirstOrDefault(x => x.Contains(UmbracoContext.Current.HttpContext.Request.Url.Host));
@nicbell
nicbell / Auth0Async.kt
Created July 7, 2019 11:15
Async wrapper for Auth0.
import android.content.Context
import com.auth0.android.Auth0
import com.auth0.android.authentication.AuthenticationAPIClient
import com.auth0.android.authentication.AuthenticationException
import com.auth0.android.callback.BaseCallback
import com.auth0.android.result.Credentials
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.Deferred
import ltd.inja.app.R
@nicbell
nicbell / jquery.hittest.js
Created March 5, 2013 12:34
The purpose of this plugin is to be able to detect if a point (X,Y) falls within an element.
(function ($) {
$.fn.hitTest = function (x, y) {
return (x > this.offset().left && x < this.offset().left + this.width()) && (y > this.offset().top && y < this.offset().top + this.height());
};
})(jQuery);
var isHit = $(".something").hitTest(90, 100);
var win = window, doc = win.document, docElem = doc.documentElement;
// Replace 'no-js'/'js' class on <html>
docElem.className = docElem.className.replace(/\bno-js\b/g, '') + ' js ';
// loadJS: load a JS file asynchronously. From https://github.com/filamentgroup/loadJS/
function loadJS(e,t){"use strict";var n=doc.getElementsByTagName("script")[0],o=doc.createElement("script");return o.src=e,o.async=!0,n.parentNode.insertBefore(o,n),t&&"function"==typeof t&&(o.onload=t),o}
win.loadJS = loadJS;
// Enhancements for qualified browsers - "Cutting the Mustard"

This should not take more than 15 minutes, you will need to use command line or powershell to run the commands.

Sometimes you may need to close and reopen your shell window after a change to see the change.

    1. Install node 5.x.x available at https://nodejs.org/en/
    1. Make sure it's on path. Run node -v
    1. Upgrade npm npm i npm -g -f
    1. Check npm version npm -v needs to be 3.x.x
    1. Install Python 2.x.x (make sure to choose add to path) available at https://www.python.org/downloads/
    1. Make sure Python is on path. python -V
@nicbell
nicbell / NHibernateSessionManager.cs
Last active December 14, 2015 12:58
NHibernate Session Manager with SysCache
using FluentNHibernate.Cfg;
using FluentNHibernate.Cfg.Db;
using NHibernate;
using NHibernate.Caches.SysCache2;
using NHibernate.Context;
using NHibernate.Tool.hbm2ddl;
using System;
using System.Web;
namespace Ixoxo.NHib
@nicbell
nicbell / index.html
Created May 14, 2014 09:25
A Pen by Nic Bell.
<svg style="display: none; height: 100px; width: 100%" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1">
<defs id="FooDefs">
<linearGradient id="MyFirstGradient" x1="0" y1="0" x2="0" y2="50" gradientUnits="userSpaceOnUse">
<stop id="stop1" style="stop-color:#1acf86;" offset="0" />
<stop id="stop2" style="stop-color:#ff0051;" offset="0.25" />
<stop id="stop3" style="stop-color:#1da1c9;"offset="0.625" />
<stop id="stop4" style="stop-color:#e45f25;" offset="1" />
</linearGradient>
</defs>
<text x="0" y="50%" id="text" style="font-size:72px;fill:url(#MyFirstGradient);"></text>