Skip to content

Instantly share code, notes, and snippets.

@joshka
joshka / Readme.md
Last active October 14, 2022 19:32
8/Any pin PIO based UART TX code for a Raspberry Pi Pico

Raspberry Pi Pico PIO 8 Pin UART TX

This code creates a UART TX on 8 sequential pins of the Raspberry Pi Pico. The main use case being MIDI splitter devices

The second 16 port implementation should work for any number of pins, but just acts as a pure copy to those pins instead of having individual control over every pin of every byte. Hence while less flexible, the controlling software is simpler (just send a uart byte and it's copied to every pin).

Only tested in the simulator so far. https://wokwi.com/projects/344345628967436882

Used https://wokwi.com/tools/pioasm to go from uart_tx.pio.h to uart_tx.h

@joshka
joshka / Global.asax.cs
Created October 14, 2014 05:56
HTTP -> HTTPS redirect and add HSTS header
// ...
protected void Application_BeginRequest(object sender, EventArgs e)
{
switch (Request.Url.Scheme)
{
case "http":
RedirectToHttps();
break;
case "https":
AddStsHeader();
@joshka
joshka / Cell.cs
Created April 13, 2013 16:21
Game of life in C#
using System.Collections.Generic;
namespace GameOfLife1
{
struct Cell
{
public Cell(int x, int y) : this()
{
Y = y;
X = x;
@joshka
joshka / gist:5361561
Created April 11, 2013 07:59
replace lambda with method / class.method
class Foo
{
List<Person> _people = new List<Person>();
IEnumerable<Person> Drinkers()
{
return people.Where(p => p.Age >= 18);
}
IEnumerable<Person> Drinkers2()
{
@joshka
joshka / GroupingExtensions.cs
Created October 21, 2012 07:20
GroupByCount
// http://devlicio.us/blogs/derik_whittaker/archive/2012/10/20/how-to-split-a-list-into-chunks-fun-code.aspx
static class GroupingExtensions
{
public static IEnumerable<IEnumerable<T>> GroupByCount<T>(this IEnumerable<T> source, int count)
{
if (source == null) throw new ArgumentNullException("source");
return GroupByCountIterator<T>(source, count);
}
@joshka
joshka / StubDataTable.cs
Created March 12, 2011 14:03
A C# implementation of Stub for DataTable creation as a test helper.
using System;
using System.Collections;
using System.Data;
namespace TestDataTableBuilder
{
class Program
{
static void Main(string[] args)
{
public static class ClassToBeTested
{
public static void DoSomething(int input, AnotherCrazyPublicStaticClass staticClass)
{
var result = staticClass.MethodToBeMocked(input); // go hit the database, network, web services, file and everything else you can imagine.
// now some business logic that I want to test
// 400 lines of code
// if result is blah do x otherwise do y
// 20 foreach loops each one with 2 nested loops and 10 if conditions.
}
public class MainViewModel : ViewModelBase
{
public MainViewModel()
{
ActivityProcessor processor = new ActivityProcessor();
GetUnicornsCommand = processor.CreateCommand(GetUnicorns).WithContinuation(HandleGetUnicornErrors);
}
IEnumerable<IActivity> GetUnicorns()
{
private static IEnumerable<TSource> SkipWhileImpl<TSource>(
IEnumerable<TSource> source,
Func<TSource, bool> predicate)
{
using (IEnumerator<TSource> iterator = source.GetEnumerator())
{
do
{
if (!iterator.MoveNext())
yield break;