Skip to content

Instantly share code, notes, and snippets.

@jeffomatic
jeffomatic / rustfmt-skip-children.sh
Last active February 5, 2023 04:57
rustfmt --skip-children emulation script
#!/bin/bash
#
# This script filters rustfmt output for format-on-save workflows in text
# editors.
#
# Usage:
#
# rustfmt-skip-children /path/to/source
#
# In particular, it:
@jeffomatic
jeffomatic / gist:5015296
Created February 22, 2013 17:51
Ruby load ruins whatever clever thing you were doing with alias_method
# base.rb
class Base
def foo
puts "BASE"
end
end
# derived.rb
@jeffomatic
jeffomatic / gist:4632923
Created January 25, 2013 08:54
In case rvm install is failing due to missing rubygems package
source $HOME/.rvm/scripts/rvm
rvm use ruby-1.9.3-p374
rvm rubygems 1.8.24
@jeffomatic
jeffomatic / gist:3849644
Created October 7, 2012 21:24
blog: accessing Rails helpers outside views, declaring globally-accessible Helpers module
# Put this into extra/my_proj/helpers.rb
module MyProj
module Helpers
extend ActionView::Helpers
end
end
@jeffomatic
jeffomatic / gist:3849655
Created October 7, 2012 21:27
blog: accessing Rails helpers outside views, calling globally-accessible Helpers module
MyProj::Helpers.pluralize(1, 'person')
MyProj::Helpers.simple_format(string)
@jeffomatic
jeffomatic / gist:3421955
Created August 22, 2012 03:10
Binary tree output 3
values: [3, 0, 2, 3, 0, 5, 7, 9, 7, 4, 4, 4, 4, 6, 8, 3, 6, 6, 3,
9, 3, 9, 1, 6, 7, 7, 3, 1, 7, 4, 7, 9, 8, 8, 6, 6, 0, 0, 3, 6, 1,
1, 0, 5, 3, 9, 5, 8, 4, 1, 0, 7, 9, 1, 6, 4, 0, 8, 8, 9, 7, 2, 9,
5, 8]
⌜·············3·⌝
⌜0···········⌝ ⌜3············⌝
0 ⌜·····2⌝ 3 ⌜·····5············⌝
⌜···1·⌝ 2 ⌜4·⌝ ⌜7·············⌝
⌜0·⌝ ⌜1·⌝ ⌜···4 ⌜4·⌝ ⌜······7 ⌜······9·⌝
0 ⌜0⌝ 1 ⌜1⌝ ⌜3·⌝ 4 ⌜4⌝ ⌜6·⌝ ⌜····8·⌝ ⌜9·⌝
@jeffomatic
jeffomatic / gist:3421950
Created August 22, 2012 03:09
Binary tree output 2
values: [4, 5, 0, 6, 2, 9, 7, 4, 1, 3, 8, 8, 2, 2, 7, 6, 8, 0, 0,
6, 9, 9, 0, 9, 3, 5, 6, 6, 2, 4, 0, 0, 0, 8, 7, 7, 0, 8, 6, 7, 7,
1, 7, 4, 1, 5, 6, 0, 9, 4, 0, 8, 0, 1, 0, 2, 9, 1, 4, 3, 5, 3, 4,
0, 1]
⌜··························4······⌝
⌜0·················⌝ ⌜····5····⌝
0 ⌜·····2····⌝ ⌜4·⌝ ⌜6··················⌝
⌜·········1·⌝ ⌜··3·⌝ 4 ⌜4⌝ ⌜·6 ⌜···········9·⌝
⌜0·⌝ ⌜1·⌝ ⌜2⌝ ⌜3⌝ 4 4⌝ ⌜5⌝ ⌜7······⌝ ⌜9·⌝
0 ⌜0·⌝ 1 ⌜1⌝ 2 2⌝ 3 3 4 5 5 ⌜···7 ⌜8·⌝ 9 ⌜9⌝
@jeffomatic
jeffomatic / gist:3421916
Created August 22, 2012 03:07
Binary tree output 1
values: [3, 9, 8, 5, 5, 0, 6, 3, 4, 4, 5, 0, 8, 3, 2, 7, 8, 3, 6,
4, 3, 7, 8, 4, 1, 5, 1, 5, 5, 0, 3, 5, 8, 8, 7, 0, 4, 5, 1, 0, 2,
7, 7, 2, 2, 9, 6, 2, 2, 0, 9, 9, 0, 2, 7, 8, 5, 2, 4, 1, 6, 1, 3,
9, 7]
⌜··················3·······································⌝
⌜0·⌝ ⌜······9·⌝
0 ⌜0········⌝ ⌜···················8·⌝ ⌜9⌝
0 ⌜···2·⌝ ⌜··········5·⌝ ⌜8·⌝ 9 9⌝
⌜1·⌝ ⌜2·⌝ ⌜3····⌝ ⌜5·······⌝ 8 ⌜8⌝ 9
⌜·1 ⌜1⌝ 2 ⌜2·⌝ 3 ⌜··4·⌝ 5 ⌜6···⌝ 8 8⌝
@jeffomatic
jeffomatic / gist:3421894
Created August 22, 2012 03:04
Binary tree insert, visualizer, and decomposition into doubly-linked cycle
# encoding: UTF-8
def tree_insert(root, v)
if !root[:v]
root.clear
root.merge!(
:v => v,
:p => nil,
:n => nil
)
elsif root[:v] > v
@jeffomatic
jeffomatic / gist:3281352
Created August 7, 2012 03:54
blog: jl_signal, code: iterating through signal connections
// A sample Emit() method on a signal object for slots that take
// two arguments.
void Emit( TArg1 a1, TArg2 a2 ) const
{
// Here, the iterator is just a pointer to a list node.
// Incrementing the iterator means that we just follow the node's
// "next" pointer. But what happens if the current node is freed
// before the iterator can be incremented?
for ( ConnectionListIter i = m_oConnections.begin();
i.isValid();