Skip to content

Instantly share code, notes, and snippets.

View adamhopkinson's full-sized avatar

Adam Hopkinson adamhopkinson

View GitHub Profile
@adamhopkinson
adamhopkinson / favicon.svg
Created September 11, 2021 22:54
# Favicons with light/dark mode colour scheme
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@adamhopkinson
adamhopkinson / showbreakpoints.blade.php
Created December 7, 2020 16:56
Small TailwindCss component to show which breakpoint is active
<div class="flex space-x-2 mb-4 rounded border text-center text-sm font-bold">
<div class="flex-1 p-2"><span class="text-green-700 mr-1 xs:inline-block sm:hidden">&#x2713;</span><span class="text-red-700 mr-1 hidden sm:inline-block">&#x2717;</span><br>XS</div>
<div class="flex-1 p-2"><span class="text-green-700 mr-1 hidden sm:inline-block md:hidden">&#x2713;</span><span class="text-red-700 mr-1 inline-block sm:hidden md:inline-block">&#x2717;</span><br>SM</div>
<div class="flex-1 p-2"><span class="text-green-700 mr-1 hidden md:inline-block lg:hidden">&#x2713;</span><span class="text-red-700 mr-1 inline-block md:hidden lg:inline-block">&#x2717;</span><br>MD</div>
<div class="flex-1 p-2"><span class="text-green-700 mr-1 hidden lg:inline-block xl:hidden">&#x2713;</span><span class="text-red-700 mr-1 inline-block lg:hidden xl:inline-block">&#x2717;</span><br>LG</div>
<div class="flex-1 p-2"><span class="text-green-700 mr-1 hidden xl:inline-block 2xl:hidden">&#x2713;</span><span class="text-red-700 mr-1
document.getElementById('canvas').toBlob(function(blob){
var image = document.createElement('img');
var url = URL.createObjectURL(blob);
image.onload = function() {
URL.revokeObjectURL(url);
}
console.log(url);
image.src = url;
document.body.appendChild(image);
});
@adamhopkinson
adamhopkinson / gist:d239937c56b29cc1da2e
Last active April 5, 2019 08:58
Converting a TSQL DateTimeOffset to UTC in Excel
/*
* if C2 contains a DateTimeOffset eg 2015-08-13 09:31:12.0000000 +01:00
* parse the date and time out and add them together
* then subtract the hours offset (which - in Excel time storage is hours/24)
* note that this ignores the minute-part of an offset (eg Venezuela)
*/
=DATE(LEFT($C2,4), MID($C2,6,2),MID($C2,9,2)) + TIME(MID($C2,12,2),MID($C2,15,2),MID($C2,18,2)) + (MID($C2,29,3)/24)
@adamhopkinson
adamhopkinson / apply_timezone_to_timestamp.sql
Created February 20, 2019 10:11
BigQuery Standard SQL UDF to apply a timezone offset to a timestamp
-- Takes a timestamp (in seconds) and a timezone offset (eg +0730) and returns a timestamp
CREATE TEMPORARY FUNCTION applyTZOffsetToUnixTimestamp(ts INT64, tzOffset STRING)
RETURNS INT64 AS (
CASE
WHEN SUBSTR(tzOffset, 1, 1) = '+' THEN ts + (CAST(SUBSTR(tzOffset, 2, 2) AS INT64) * 60 * 60) + (CAST(SUBSTR(tzOffset, 4, 2) AS INT64) * 60)
WHEN SUBSTR(tzOffset, 1, 1) = '-' THEN ts - (CAST(SUBSTR(tzOffset, 2, 2) AS INT64) * 60 * 60) - (CAST(SUBSTR(tzOffset, 4, 2) AS INT64) * 60)
ELSE NULL
END
);
@adamhopkinson
adamhopkinson / gist:8036875
Last active August 10, 2017 12:43
C# Globablisation - getting the market instance from the visitors' origin country (via GeoIP)
var market = MarketInfo.Markets.SingleOrDefault(m => m.Code == Visitor.CountryCode);
if (market == null)
market = Visitor.Market;
@adamhopkinson
adamhopkinson / link.cshtml
Created January 12, 2016 14:54
Using a sitecore General Link field
@adamhopkinson
adamhopkinson / gist:8026627
Last active December 31, 2015 18:28
Getting a Sitecore item url in a C# repeater
<ul>
<asp:Repeater ID="rpFooterDestinations" runat="server">
<ItemTemplate>
<li>
<a href="<%# Sitecore.Links.LinkManager.GetItemUrl(
(Sitecore.Data.Items.Item) Container.DataItem
) %>"><%# Eval("DisplayName") %></a>
</li>
</ItemTemplate>
</asp:Repeater>
@adamhopkinson
adamhopkinson / gist:7792041
Created December 4, 2013 17:40
Quick c# list foreach
ids.ForEach(id => {
itineraries.Add(Sitecore.Context.Database.GetItem(id));
});
@adamhopkinson
adamhopkinson / gist:7791592
Created December 4, 2013 17:19
Defaulting a sitecore query to a blank list
List<Item> items = (Sitecore.Context.Item.Axes.SelectItems(query) ?? new Item[] { }).ToList();