Skip to content

Instantly share code, notes, and snippets.

Bodacious / Gemfile
Created January 10, 2023 21:10
Demonstrating the anonymous modules when including blocks in scopes
View Gemfile
# frozen_string_literal: true
source ""
gem "activerecord", github: "bodacious/rails"
gem "sqlite3"
Bodacious / main.rb
Created June 28, 2022 10:38
Jbuilder named attributes vs `extract!`
View main.rb
require "bundler/inline"
gemfile do
gem "benchmark-ips"
gem "jbuilder"
gem "activesupport", require: ["active_support"]
class User
attr_accessor :id, :name, :email, :password, :age, :username
Bodacious / string.rb
Created September 11, 2020 15:55
Ruby Palindrome String
View string.rb
class String
def palindrome?
clean_string = self.gsub(/[^\w]/, '').downcase
clean_string == clean_string.reverse
puts "madam".palindrome? # => true
puts "racecar".palindrome? # => true
puts "madam, . ".palindrome? # => true
puts "02/02/2020".palindrome? # => true
Bodacious / monty_hall.rb
Created May 31, 2018 17:00
Monty Hall Problem demonstrated in Ruby
View monty_hall.rb
class Game
attr_accessor :doors
attr_reader :correct_door
def initialize(door_count: )
chosen_door = (1..door_count).to_a.sample
@doors = do |d, i| == chosen_door)
@correct_door = @doors.detect(&:correct?)
Bodacious / random_password.rb
Last active June 5, 2017 11:17
Random password generator in Ruby on Rails
View random_password.rb
# Examples:
# @password = RandomPassword.password
class RandomPassword
class << self
delegate :password, to: new
Bodacious / app_delegate.rb
Created February 7, 2017 12:47
Empty app delegate
View app_delegate.rb
class AppDelegate
def window
@window ||= UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)
def application(application, didFinishLaunchingWithOptions:launchOptions)
window.rootViewController = UIViewController.alloc.init
Bodacious / app_delegate.rb
Created February 7, 2017 12:37
RubyMotion Hello World example.
View app_delegate.rb
class AppDelegate
def hello_world_label
@hello_world_label ||= begin
frame = CGRectMake(20,200,280,40)
label = UILabel.alloc.initWithFrame(frame)
label.text = "Hello world"
label.textColor = UIColor.whiteColor
label.textAlignment = UITextAlignmentCenter
Bodacious / example 1.rb
Created October 28, 2016 09:38
Adding gender-specific messages to your rails app with genderize
View example 1.rb
# Since Sarah is the object of this sentence
"Sarah is a new member, why not send #{@sarah.object} a message?"
Bodacious / sass.sass
Created October 27, 2016 17:00
SASS script for creating quick colour pallette
View sass.sass
$hue: 173;
$first-color: hsl($hue, 100%, 50%);
$second-color: complement($first-color);
.first-color {
background: $first-color;
.second-color {
background: $second-color;
Bodacious /
Last active May 13, 2016 16:46
How to find an average value, without having to store every data point

How to find an average value, without having to store every data point

This was a solution to a problem I was trying to solve on my webiste: how can I arrive at an average value over time, when new data is being provided, without having to store every datum.

I wrote this code to prove to myself that I wasn't crazy, and that this was indeed a valid way to calculate the mean.