Skip to content

Instantly share code, notes, and snippets.

View deanhume's full-sized avatar
🎮
Gaming

Dean deanhume

🎮
Gaming
View GitHub Profile
@deanhume
deanhume / ambient-light.js
Created June 27, 2018 15:12
Ambient Light Sensor
const details = document.getElementById("details");
// Feature detection
if (window.AmbientLightSensor){
try{
const sensor = new AmbientLightSensor();
// Detect changes in the light
sensor.onreading = () => {
details.innerHTML = sensor.illuminance;
@deanhume
deanhume / service-worker-ghost-cms.js
Created March 23, 2018 16:46
Service Worker for Ghost CMS
const cacheName = 'blogCache';
const offlineUrl = '/offline/';
self.addEventListener('install', event => {
event.waitUntil(
caches.open(cacheName)
.then(cache => cache.addAll([
'./assets/font/icons.woff2',
'./assets/js/script.js',
'https://fonts.googleapis.com/css?family=Open+Sans:400,700',
@deanhume
deanhume / forLoopTest.cs
Created March 15, 2018 16:42
For Loop Test
for (int i = 0; i < ListLoop.Count; i++)
{
if (populatedList\[i\] == "Test2500")
{
return;
}
}
@deanhume
deanhume / forEach.cs
Created March 15, 2018 16:42
ForEach
foreach (string findString in populatedList)
{
if (findString == "Test2500")
{
return;
}
}
@deanhume
deanhume / forLoop.cs
Created March 15, 2018 16:41
forloop
/// <summary>
/// Loops through the loop until it reaches a count of 3000
/// </summary>
public void ForLoop()
{
List<string\> list = new List<string>();
for (int i = 0; i < 3000; i++)
{
list.Add("Test" \+ i);
@deanhume
deanhume / whileloop.cs
Created March 15, 2018 16:40
WhileLoop
/// <summary>
/// Loops through the list until it
/// reaches a count of 3000.
/// </summary>
public void WhileLoop()
{
List<string\> list = new List<string>();
int x = 0;
@deanhume
deanhume / drawmap.cs
Created March 15, 2018 09:24
DrawMap
/// <summary>
/// Draws the map.
/// </summary>
/// <param name="helper">The helper.</param>
/// <param name="key">The key.</param>
/// <param name="jsonUrl">The json URL.</param>
/// <param name="mapWidth">Width of the map.</param>
/// <param name="mapHeight">Height of the map.</param>
/// <returns>The html of the map.</returns>
public static string DrawMap(this HtmlHelper helper, string key, string jsonUrl, string mapWidth, string mapHeight)
@deanhume
deanhume / getmarkers.cs
Created March 15, 2018 09:23
GetMarkers
public ActionResult GetMarkers()
{
// This would normally be our call to the Db,
// else we could populate this
// with some data as Ive done here.
MarkerList markers = GetMarkersObjects();
return Json(markers, JsonRequestBehavior.AllowGet);
}
@deanhume
deanhume / clear-cache.js
Created September 20, 2017 08:22
Clear Service Worker Cache
if ('serviceWorker' in navigator) {
caches.keys().then(function(cacheNames) {
cacheNames.forEach(function(cacheName) {
caches.delete(cacheName);
});
});
}
@deanhume
deanhume / storage-estimate.js
Created September 20, 2017 08:21
Storage Estimate
if ('storage' in navigator && 'estimate' in navigator.storage) {
navigator.storage.estimate().then(estimate => {
console.log(`Using ${estimate.usage} out of ${estimate.quota} bytes.`);
});
}