Skip to content

Instantly share code, notes, and snippets.

View rosswilson's full-sized avatar

Ross Wilson rosswilson

View GitHub Profile
@rosswilson
rosswilson / client.js
Created July 4, 2020 16:19
Node.js TCP server to transmit messages to connected clients when GPIO events happen. Can be used to mute and unmute a Zoom call with a physical button.
const net = require("net");
const { spawn } = require("child_process");
const client = new net.Socket();
client.connect(9000, "192.168.1.26", function () {
console.log("Connected to button server");
});
const unmuteScript = `
@rosswilson
rosswilson / account_view.ex
Created May 17, 2020 16:49
Phoenix Framework Per-View Page Titles
defmodule MyAppWeb.Admin.AccountView do
use MyAppWeb, :view
def render("page_title", assigns) do
page_title(view_template(assigns.conn), assigns)
end
defp page_title("index.html", _assigns), do: "Accounts"
defp page_title("new.html", _assigns), do: "New Account"
defp page_title("edit.html", _assigns), do: "Edit Account"
@rosswilson
rosswilson / application.rb
Created January 12, 2020 01:48
Rails response header containing git revision sha
# config/application.rb
require_relative 'boot'
require 'rails/all'
require_relative '../lib/middleware/revision_middleware'
# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
@rosswilson
rosswilson / pot-transfer.json
Created February 21, 2018 14:23
Monzo Webhook Payloads
{
"type": "transaction.created",
"data": {
"id": "tx_00009TnTFcG7cG6bxxxxxx",
"created": "2018-02-19T17:32:03.234Z",
"description": "pot_00009Qoyee0RPU0sxxxxxx",
"amount": -40000,
"fees": {},
"currency": "GBP",
"merchant": null,
@rosswilson
rosswilson / pagination.ex
Created February 21, 2018 12:08
Example of pagination using Ecto
defmodule MyApp.Pagination do
@moduledoc """
Takes an Ecto query and applies limit and offset style pagination.
"""
import Ecto.Query
defstruct [:entries, :page_number, :page_size, :total_pages]
@doc """
@rosswilson
rosswilson / factory.ex
Created February 7, 2018 19:39
Elixir Test Factory Pattern
defmodule MyApp.Factory do
use MyApp.Faker, repo: MyApp.Repo
def user_factory do
%MyApp.Users.User{
name: "Some name",
email: "some-name@example.com"
}
end
<canvas id="user-icon" width="256" height="256"></canvas>