Skip to content

Instantly share code, notes, and snippets.

View agilous's full-sized avatar

Bill Barnett agilous

View GitHub Profile

Brute Force Pi Calculation

Making use of the observation that Pi is the area of a circle with diameter equal to one, a brute force calculation of Pi would be to:

  1. randomly generate points in a square
  2. count the points within the circle and the total number of points
  3. multiple the ratio of points in the circle to total number of points by the area of a square with a side the length of the diameter of the circle (in this case two (2))

Usage

@agilous
agilous / UBUNTU-MACBOOK-PRO.md
Last active January 20, 2023 16:56
Troubleshooting "No Sound" issue on MacBook Pro 13,2 running Ubuntu 22.04.1 LTS
@agilous
agilous / SPELLING_BEE.md
Last active November 5, 2022 06:22
NYT Spelling Bee solver in Ruby

Spelling Bee

NYT Spelling Bee solver written in Ruby. It should work fine on any BSD/Linux/Unix system with Ruby installed.

Running the code

In a terminal:

git clone git@gist.github.com:3488d03f298cef55289bc899e79e18a3.git spelling_bee
cd spelling_bee
irb -r ./spelling_bee.rb
@agilous
agilous / SINGLE_PAGE_RAILS_APP.md
Last active January 17, 2023 20:53
Single Page Rails App

Single Page Rails App

Credit to @GregMolnar.

Run the app

This has only been tested with Ruby 3.1.2. YMMV.

rackup app.ru
@agilous
agilous / dynamic-text-replacement.rb
Created March 10, 2022 19:48
Short Ruby script that permits dynamic replacement of text
file_name = 'errors.sql'
error_number = 50_001
lines = IO.readlines(file_name)
lines.each_with_index do |line, index|
next unless line[/99999/]
lines[index] = line.gsub('99999', error_number.to_s)
error_number += 1
end
@agilous
agilous / simple-release-notes.rb
Last active February 17, 2022 21:31
Simple RELEASE-NOTES.md generator script using Octokit gem
require 'octokit' # (See: https://github.com/octokit/octokit.rb)
# (See: https://github.com/settings/tokens OR https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token)
personal_access_token = 'ghp_1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'
client = Octokit::Client.new(access_token: personal_access_token)
client.auto_paginate = true
repo_name = 'foo/bar'
releases = client.releases(repo_name)
@agilous
agilous / README.md
Last active January 21, 2021 05:26
RSpec Demo

RSpec Demo

In this demo we will:

  • Learn why testing is important
  • Learn about testing "philosophies"
  • Learn how RSpec makes testing "productive and fun" including:
    • Units specs (Models: "M")
    • Request & Routing specs (Controllers: "C")
    • View specs (Views: "V")
  • System specs (Models, Views & Controllers: "MVC")
@agilous
agilous / README.md
Last active October 15, 2020 03:32
action-controller-demo

ActionController Demo

In this demo we will:

  • Review a bit about the "M" and "V" parts of MVC
  • Learn how to debug our code with Pry
  • Learn about the essential parts of a Rails controller including:
    • Actions/Methods
    • Parameters including Strong Parameters
    • Filters
    • Flash (with Cookies & Sessions)

ActiveRecord Demo

This gist has become cincinnatirb/active_record_demo. You can watch a (near perfect) run-through on YouTube here.

In this demo we will:

  • Revisit Rails generators
  • Learn more about Microsoft's Visual Studio Code and some of its features
  • Expand our use of git for source code control
  • Explore use of the DB Browser for SQLite to explore the internals of a SQL database
  • Be quickly introduced to Rails routing, controllers and views
  • Implement our first feature request