Skip to content

Instantly share code, notes, and snippets.

View zerowidth's full-sized avatar

Nathan Witmer zerowidth

View GitHub Profile
@zerowidth
zerowidth / obsidian.css
Last active October 15, 2022 05:40
obsidian styles
body {
--inline-code-padding: 2px;
--inline-code-border-radius: 4px;
}
/* inline code style */
.cm-s-obsidian span.cm-inline-code,
.markdown-rendered code,
.markdown-preview-view code {
border: var(--tag-border-width) solid var(--background-modifier-border);
@zerowidth
zerowidth / paginated_collection.js
Created November 18, 2010 22:04
first whack at pagination with backbone.js
// includes bindings for fetching/fetched
PaginatedCollection = Backbone.Collection.extend({
initialize: function() {
_.bindAll(this, 'parse', 'url', 'pageInfo', 'nextPage', 'previousPage');
this.page = 1;
},
fetch: function(options) {
options || (options = {});
this.trigger("fetching");
@zerowidth
zerowidth / port_tables.rb
Created February 14, 2013 03:23
Script to parse a text table and convert to a reasonable output. Demonstration of an idiomatic ruby script for a friend.
require "pp"
def convert_to_offsets(widths)
offsets = []
position = 0
widths.each.with_index do |width, index|
offsets << (position...(width+position)) # range does not include the end
position += width + 1 # assume spacing of 1 character
end
@zerowidth
zerowidth / portal.rb
Last active November 18, 2019 18:00
Calculations for siting a Minecraft portal in the nether
require "set"
STDERR.sync
exclusion = 8 # one nether block distance, or 8 overworld
existing = [[-743, 63, -39], [-743, 63, -40]]
targets = [[-791, 152, -48], [-792, 152, -48], [-793, 152, -48]]
existing_nether = [[-87, 67, -4]]
search_from = existing_nether.first
@zerowidth
zerowidth / do-stuff.rb
Created January 23, 2018 03:19
do-stuff to make git commits for demonstration purposes
#!/usr/bin/env ruby
require "pathname"
class RandomEditor
def initialize
@files = Pathname.new(".").entries.select(&:file?).map(&:to_s)
end
def run(iterations = 1, commit = false)
iterations.times do
@zerowidth
zerowidth / git-workflow.md
Last active July 18, 2017 17:50
A brief discusson on git workflow preferences (now published on zerowidth.com)

A colleague asks [slightly edited]:

Why didn't you squash your [feature branch merge] commit? I'm new to [project], but I found on [other project] that squashed commits made it much easier to git bisect. And since the [project] test suite is broken frequently, I assume we'll be git bisecting a lot. Un-squashed commits tended to leave broken tests or functionality that never actually shipped.

Git, because it's just "the stupid content tracker", is flexible enough to support just about any development workflow you can think of. You can use pull

@zerowidth
zerowidth / sql.md
Last active April 11, 2017 18:31
GitHub::SQL - a helping hand for SQL in a rails app

DEPRECATED

GitHub::SQL has been released as an officially-maintained project and ruby gem: github/github-ds.

@zerowidth
zerowidth / music.rb
Created May 7, 2012 21:37
A functional, lazily-evaluated solution to https://github.com/KeeperPat/music-yaml-parsing for a "coding challenged" competition
Proc.module_eval { def method_missing(m,*a); call(m.to_s,*a); end }
Array.module_eval { def rest; self[1..-1]; end }
Object.module_eval { def let; yield self; end }
Music = Module.new do
def self.load(filename)
depth = ->(l) { %r(^([\s-]*)\w).match(l)[1].length }
ldepth = ->(l) { %r(^(\s*)\S).match(l)[1].length }
nonzero = ->(n) { n > 0 }
empty = ->(c) { c.empty? }
@zerowidth
zerowidth / coffeescript.rb
Created April 8, 2013 03:16
Jekyll plugins for rendering compass stylesheets and auto-converting coffeescript files without requiring YAML front-matter.
require "coffee-script"
module Jekyll
# Automatically force coffeescript files to be compiled, even if they don't
# have the YAML front-matter.
class CoffeeConvertor < Generator
def generate(site)
converted = []
site.static_files.each do |sf|
@zerowidth
zerowidth / highlight_indent_fix.rb
Created April 8, 2013 03:20
Jekyll monkeypatch to strip leading space from indented `highlight` liquid blocks
Jekyll::Tags::HighlightBlock.module_eval do
def render(context)
code = strip_leading_space_from super
if context.registers[:site].pygments
render_pygments(context, code)
else
render_codehighlighter(context, code)
end
end