Skip to content

Instantly share code, notes, and snippets.

//Finish a block of non-zero bytes by outputting the code to the current code pointer,
//then setting the new code pointer to the current output destination, and incrementing
//the output destination (essentially reserving a byte of output to be later set to the
//code for the new run we are starting). Reset code to 0x01, for no bytes in the new run
//we are starting.
#define cobs_finish_block(X) (*code_ptr = (X), code_ptr = dst++, code = 0x01)
void cobs_stuff_data(const uint8_t *ptr, size_t length, uint8_t *dst, size_t *stuffed_length) {
const uint8_t *end = ptr + length;
const uint8_t *dst_start = dst;

Raspberry Pi VPN Router

This is a quick-and-dirty guide to setting up a Raspberry Pi as a "router on a stick" to ExpressVPN.

This is adapted from SuperJamie's gist.

Requirements

I used a Raspberry Pi 3 - seems like the extra speed may be useful for running VPN.

def stringViewThing = ReactComponentB[String]("StringViewThing")
.render_P(s => <.div(s): ReactElement)
.configure(Reusability.shouldComponentUpdateWithOverlay)
.componentWillUnmount(_ => Callback{println("StringViewThing unmounted! Again!")})
.build
val streetView = cursorView[Unit, Street, StreetDelta, Unit]("StreetView") { c => {
val r = <.div(
^.paddingTop := "20px",
^.backgroundColor := MaterialColor.Amber.a100,
case class Id[+A](guid: Long)
sealed trait DeltaIOA[U, A]
case class GetId[U, T <: U]() extends DeltaIOA[U, Id[T]]
case class Put[U, T <: U](create: Id[T] => DeltaIO[U, T]) extends DeltaIOA[U, T]
class Widener[U, V <: U] {
type DIOU[A] = DeltaIOA[U, A]
type DIOV[A] = DeltaIOA[V, A]
trait Delta[U, A] {
def apply(a: A): DeltaIO[U, A]
}
sealed trait DeltaIOA[U, A]
case class GetGuid[U]() extends DeltaIOA[U, Guid]
//case class GetId[U, T <: U]() extends DeltaIOA[U, Id[T]]
case class GetContext[U]() extends DeltaIOA[U, DeltaIOContext]
case class GetDeltaId[U]() extends DeltaIOA[U, DeltaId]
case class GetPRInt[U]() extends DeltaIOA[U, Int]
case Put(create) => State(s => {
// Id and revision for the new data we will create
val id = Id[A](Guid(s.deltaId.clientId, s.deltaId.clientDeltaId, WithinDeltaId(s.currentGuidId)))
val revision = Guid(s.deltaId.clientId, s.deltaId.clientDeltaId, WithinDeltaId(s.currentGuidId + 1))
// Make the data item
val createDIO = create(id.asInstanceOf[Id[U with A]])
// Remember to increment guid twice for the guid and revision we generated
val stateWithA: (StateData[U], A) = createDIO.foldMap(arrow).run(s.withNextGuidId.withNextGuidId).value
object Routes {
sealed trait Page
case class SearchPage(term: String) extends Page
val routerConfig = RouterConfigDsl[Page].buildConfig { dsl =>
import dsl._
def uriString(regex: String): RouteB[String] = new RouteB(regex, 1, g => Some(decodeURIComponent(g(0))), encodeURIComponent)
/**
* A Transaction can produce an effect and a result using STMOps. This represents
* an atomic operation performed using the STMOps, getting/setting data, etc.
* Using a wrapper allows for use of different effects, and serialisation.
*/
trait Transaction[A] {
def apply[F[_]: Monad](implicit stm: STMOps[F]): F[A]
def map[B](f: A => B): Transaction[B] = {
sbt:tree-react root project> show antdApp/fullClasspath
[info] * Attributed(/Users/rebeam/Documents/GitHub/tree-react/antd-app/target/scala-2.13/classes)
[info] * Attributed(/Users/rebeam/Documents/GitHub/tree-react/tree-slinky-extra/target/scala-2.13/classes)
[info] * Attributed(/Users/rebeam/Documents/GitHub/tree-react/tree-slinky/target/scala-2.13/classes)
[info] * Attributed(/Users/rebeam/Documents/GitHub/tree-react/tree-core/js/target/scala-2.13/classes)
[info] * Attributed(/Users/rebeam/Documents/GitHub/tree-react/tree-ot/js/target/scala-2.13/classes)
[info] * Attributed(/Users/rebeam/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/eu/timepit/refined_sjs1_2.13/0.9.13/refined_sjs1_2.13-0.9.13.jar)
[info] * Attributed(/Users/rebeam/Library/Caches/Coursier/v1/https/repo1.maven.org/maven2/me/shadaj/slinky-web_sjs1_2.13/0.6.5/slinky-web_sjs1_2.13-0.6.5.jar)
[info] * Attributed(/Users/rebeam/.ivy2/local/org.scalablytyped/antd_sjs1_2.13/4.3.1-70f266/jars/antd_sjs1_2.13.jar)
[info] * Attributed(/Users/r
@trepidacious
trepidacious / code.py
Created February 2, 2021 21:57
Pico RGB keypad
import time
import board
import busio
import usb_hid
from adafruit_bus_device.i2c_device import I2CDevice
import adafruit_dotstar
from adafruit_hid.keyboard import Keyboard
from adafruit_hid.keyboard_layout_us import KeyboardLayoutUS