Skip to content

Instantly share code, notes, and snippets.

View chendo's full-sized avatar

chendo chendo

View GitHub Profile
@chendo
chendo / raven.rb
Last active January 11, 2022 11:49
Pulls energy usage from a Rainforest Automation RAVEn USB stick and publishes into a MQTT server to be consumed by Home Assistant
# License: Public domain
# Depends on https://github.com/nonspecialist/pyraven being installed and accessible at `raven`
require 'bundler/inline'
gemfile do
source 'https://rubygems.org'
gem 'mqtt'
end
@chendo
chendo / _document.js
Last active June 2, 2022 02:54
Server side rendering (SSR) in Next.js with styled-components, styled-jsx, and emotion.
import Document, { Head, Main, NextScript } from 'next/document'
import { renderToString } from 'react-dom/server'
import { extractCritical } from 'emotion-server'
import { ServerStyleSheet } from 'styled-components'
import flush from 'styled-jsx/server'
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const styledComponentsSheet = new ServerStyleSheet()
@chendo
chendo / _document.js
Created April 16, 2019 12:43
Critical CSS support for both styled-components and Emotion in Next.js
import Document, { Head, Main, NextScript } from 'next/document'
import { ServerStyleSheet } from 'styled-components'
import { renderToString } from 'react-dom/server'
import { extractCritical } from 'emotion-server'
export default class MyDocument extends Document {
static async getInitialProps(ctx) {
const sheet = new ServerStyleSheet();
const originalRenderPage = ctx.renderPage
#!/bin/bash
if [ -e /dev/nvme1n1 ]
then
sudo /etc/init.d/docker stop
sudo mkfs.ext4 /dev/nvme1n1
sudo mount /dev/nvme1n1 /var/lib/docker
sudo /etc/init.d/docker start
fi
@chendo
chendo / go_interactive.rb
Created July 10, 2018 03:23
go_interactive lets you interactively write specs
class GoInteractive
def self.start(*args, **kwargs)
@init ||= begin
Pry.hooks.add_hook(:before_eval, "go_interactive") do |code, pry|
current.before_eval(code, pry)
end
Pry.hooks.add_hook(:after_eval, "go_interactive") do |result, pry|
current.after_eval(result, pry)
end
var filter = vis.append("defs")
.append("filter")
.attr("id", "stroke")
filter
.append("feFlood")
.attr("flood-color", "blue")
.attr("result", "strokeColor")
@chendo
chendo / points.json
Created July 20, 2017 22:19
ARKit positional data for a few laps around a go kart track - 14213 data points
This file has been truncated, but you can view the full file.
[
{
"speed": 0.0090636899694800377,
"x": -507,
"y": 307,
"time": 1500542785486,
"gpsHoriAcc": 10,
"z": 858,
"lat": -37.779849772376735,
"gpsHeading": 152.9296875,
package main
import (
"fmt"
"github.com/apcera/nats"
"runtime"
"sync/atomic"
"time"
)
require 'celluloid/io'
require 'socket'
class Server
include Celluloid::IO
def run
@tcp = TCPServer.new('0.0.0.0', 31337)
loop do
Connection.new_link(@tcp.accept).async.run
@chendo
chendo / required_keyword_arguments.rb
Created March 28, 2014 03:19
My take on required keyword arguments in Ruby 2.0. This solution throws a nice backtrace, but still requires a name to be passed in.
module RequiredKeywordArguments
def required!(name)
backtrace = caller_locations(1).map { |c| c.to_s }
ex = ArgumentError.new("Missing required keyword argument '#{name}'")
ex.set_backtrace(backtrace)
raise ex
end
end
class Foo