Skip to content

Instantly share code, notes, and snippets.

View andy-williams's full-sized avatar

Andrew Williams andy-williams

View GitHub Profile
@andy-williams
andy-williams / shopify.liquid
Created March 7, 2017 21:12
shopify-modulo
{% for product in collection.products %}
{% capture everyThird %}{{ forloop.index | modulo: 3 }}{% endcapture %}
{% capture everyOnePastThird %}{{ forloop.index0 | modulo: 3 }}{% endcapture %}
{% if forloop.first == true or everyOnePastThird == '0' %}
<div class="row">
{% endif %}
{% include 'product-catalog-item' %}
{% if forloop.last == true or everyThird == '0' %}
@andy-williams
andy-williams / ApiController.cs
Created March 6, 2019 01:07
React inline error with asp.net Model State errors
[Route("api/v1/account")]
[AllowAnonymous]
public class ApiController : Controller
{
[Route("login")]
public async Task<IActionResult>Login([FromBody] LoginRequest login)
{
if (ModelState.IsValid)
{
// ... logic
@andy-williams
andy-williams / Main.cs
Created March 6, 2019 13:56
Get exceptions of all tasks with Task.WhenAll
async Task Main()
{
var task1 = Task.Run(async () => {
await Task.Delay(500);
throw new Exception("Exception from task 1");
});
var task2 = Task.Run(() =>
{
throw new Exception("Exception from task 2");
});
@andy-williams
andy-williams / lavenstein.cs
Created May 2, 2019 21:15
Simple Lavenstein edit distance algorithm
public class Program
{
public void Main()
{
PrintEditDistance("ab", "ab");
PrintEditDistance("bbc", "abc");
PrintEditDistance("bbbc", "bbc");
PrintEditDistance("xyza", "abcx");
}