Skip to content

Instantly share code, notes, and snippets.

View noahgibbs's full-sized avatar

Noah Gibbs noahgibbs

View GitHub Profile
@noahgibbs
noahgibbs / stochastic.rb
Created September 22, 2023 09:53
Stochastic method definition
class BadIdea
def self.method_added(method_name)
return if @mid_define
@obj ||= Object.new
@old_methods ||= {}
@old_methods[method_name] ||= []
@old_methods[method_name] << self.instance_method(method_name)
@noahgibbs
noahgibbs / System config (fine)
Created May 19, 2023 10:26
Good vs bad Bundler config
noah@Noahs-MBP activerecord % chruby system
noah@Noahs-MBP activerecord % gem env
RubyGems Environment:
- RUBYGEMS VERSION: 3.0.3.1
- RUBY VERSION: 2.6.10 (2022-04-12 patchlevel 210) [universal.arm64e-darwin22]
- INSTALLATION DIRECTORY: /Library/Ruby/Gems/2.6.0
- USER INSTALLATION DIRECTORY: /Users/noah/.gem/ruby/2.6.0
- RUBY EXECUTABLE: /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/bin/ruby
- GIT EXECUTABLE: /usr/bin/git
- EXECUTABLE DIRECTORY: /usr/local/bin
# Change a sci-notation string to a float string without using the Numeric class in between. At all.
# Assume input string in "12345e7" format,
# return string in "123450000000.0" format
def exp2sf(exp_str)
mant, ex = exp_str.split("e")
zeroes = ""
next_place_zeroes = "0"
@noahgibbs
noahgibbs / r00lz.rb
Created April 28, 2019 15:52
R00lz.to_underscore, for those who hate typing out regexps visually.
# r00lz/lib/r00lz.rb
module R00lz
def self.to_underscore(s)
s.gsub(
/([A-Z]+)([A-Z][a-z])/,
'\1_\2').gsub(
/([a-z\d])([A-Z])/,
'\1_\2').downcase
end
end
@noahgibbs
noahgibbs / gist:f006364c3b335046314d9cdcbaa5c4d6
Created July 16, 2018 22:28
Robert Pozen writing advice, very abbreviated notes
Make an Outline:
* Brainstorm
* Categorize (arrange into categories and subcategories)
* Outline
Introduction:
* Provide the Reader with Context
* State the main theme
* Explain the organization (what you'll get, how you'll get it)
@noahgibbs
noahgibbs / nested_exception.rb
Created December 16, 2016 16:21
Sample Ruby code with nested exceptions - use Ruby 2.3.0 or higher
class LibraryError < RuntimeError; end
class AppError < RuntimeError; end
# Library code
def library_call
begin
1/0
rescue
raise LibraryError.new("Something went wrong")
end
class ParentClass
puts "Self when defining ParentClass: #{self.class} / #{self.inspect}"
def parent_method
puts "Self inside parent_method: #{self.class} / #{self.inspect}"
end
end
module MyModule
def self.module_obj_method
puts "Self inside module_obj_method: #{self.class} / #{self.inspect}"
<h1>D3 Shaded Globe</h1>
<!-- Add scripts for topoJson, jQuery -->
<script src="http://d3js.org/d3.v3.min.js"></script>
<script src="http://d3js.org/topojson.v1.min.js"></script>
<script src="http://datamaps.github.io/scripts/datamaps.world.min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js" ></script>
<div class="world-map"
style="position: relative; height: 500px">
@noahgibbs
noahgibbs / rickshaw_xkcd_test.html
Created March 1, 2013 18:31
The full basic Rickshaw XKCD renderer.
<!doctype html>
<script src="http://code.shutterstock.com/rickshaw/vendor/d3.v2.js"></script>
<script src="http://code.shutterstock.com/rickshaw/rickshaw.min.js"></script>
<div id="chart"></div>
<script>
// Return an xinterp function for a given graph
function xinterp_on_graph(graph) {
<!doctype html>
<script src="http://code.shutterstock.com/rickshaw/vendor/d3.v2.js"></script>
<script src="http://code.shutterstock.com/rickshaw/rickshaw.min.js"></script>
<div id="chart"></div>
<script>
var graph = new Rickshaw.Graph( {