Skip to content

Instantly share code, notes, and snippets.

Nathan Broadbent ndbroadbent

View GitHub Profile
@ndbroadbent
ndbroadbent / opengl_fix.rb
Created Dec 27, 2018
Fix OpenGL rendering on MacOS Mojave for Mittsu
View opengl_fix.rb
fixed_opengl = false
start_time = Time.now
renderer.window.run do
renderer.render(@scene, @camera)
if !fixed_opengl && Time.now - start_time > 0.5
# Workaround for OpenGL bug on MacOS Mojave
# Have to slightly move the window to start the rendering,
# otherwise it stays black.
# See: https://stackoverflow.com/a/52915794/304706
View array_partition.rb
class ArrayPartition
def self.partition_counts(count, max)
return [count] if count <= max
group_count = (count / max) + (count % max > 0 ? 1 : 0)
result = [0] * group_count
count.times do |n|
result[n % group_count] += 1
end
result.sort
end
@ndbroadbent
ndbroadbent / add_network_to_dev_board.md
Last active Nov 22, 2018
Previous version of my FGPA dev board winners
View add_network_to_dev_board.md

(This was before I found out about the icoBoard with pluggable pmod accessories.)

How can I add networking to an FPGA development board?

Some development boards include a SoC that has an ARM processor and built-in networking. If you choose a plain FPGA board (e.g. Artix 7 or iCE40 UltraPlus), how can you add networking?

  • Ethernet-SPI/Bus Module ($24.95). Has a built-in chip with a TCP/IP stack, so it's much easier to get started.
  • ESP8266 WiFi Module ($5.56). Self contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network.
@ndbroadbent
ndbroadbent / craco.config.js
Last active Nov 13, 2018
create-react-app configuration using craco, for ant.design, Less loader for custom theming, and preact-compat
View craco.config.js
// UPDATE: I released a craco plugin as an NPM package: https://github.com/ndbroadbent/craco-antd
@ndbroadbent
ndbroadbent / auto_const.js
Last active Nov 10, 2018
Idea for a Babel/Webpack plugin that makes JavaScript more like Ruby
View auto_const.js
// Assume const by default, instead of global var
// Source
// ---------------------------------------
varA = 1
const varB = 2
let varC = 2
@ndbroadbent
ndbroadbent / subclass_test.rb
Created Nov 9, 2018
Private vs protected in Ruby
View subclass_test.rb
class A
protected
def a_protected
'can call protected'
end
private
def a_private
@ndbroadbent
ndbroadbent / rubocop-commit-msg-hook.rb
Last active Oct 30, 2018
Git commit-msg hook for Rubocop
View rubocop-commit-msg-hook.rb
#!/usr/bin/env ruby
# Save this to ".git/hooks/commit-msg", then run: "chmod +x .git/hooks/commit-msg"
require 'english'
require 'yaml'
commit_message = File.read(ARGV[0])
if commit_message.match?(/^(WIP|te?mp)/)
puts 'Skipping Rubocop for temporary commit.'
exit
View bump_version.rb
#!/usr/bin/env ruby
require 'json'
VERSION_REGEX = /^(?<major>\d+)\.(?<minor>\d+)\.(?<patch>\d+)$/
VERSION_TYPES = %w[major minor patch].freeze
LANGUAGES = Dir.glob(File.expand_path('../config/*.json', __dir__)).map do |f|
f[%r{/([^/]+)\.json$}, 1]
end.freeze
LANGUAGE_MAX_LENGTH = LANGUAGES.map(&:length).max
VERSION_KEYS = {
@ndbroadbent
ndbroadbent / preload_helper.rb
Created Oct 27, 2018
HTTP/2 Server Push for Rails - Add Link preload headers for all CSS and image assets on your home page
View preload_helper.rb
module PreloadHelper
def compute_asset_path(*args)
computed_path = super
add_link_header_for_computed_asset_path(computed_path)
computed_path
end
protected
# Preload all CSS and images on the home index page.
@ndbroadbent
ndbroadbent / request_post_data.json
Created Oct 14, 2018
Missing keys in Sentry Additional Data
View request_post_data.json
{
"project": "224002",
"logger": "javascript",
"platform": "javascript",
"request": {
"headers": {
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:62.0) Gecko/20100101 Firefox/62.0",
"Referer": "http://*.*.*.*:3000/dashboard"
},
"url": "http://*.*.*.*:3000/templates/tpl_******************/edit"
You can’t perform that action at this time.