Skip to content

Instantly share code, notes, and snippets.

View fuzzygroup's full-sized avatar

J. Scott Johnson fuzzygroup

View GitHub Profile
@fuzzygroup
fuzzygroup / rails_migration_create_countries.rb
Last active January 5, 2023 11:00 — forked from marcomd/rails_migration_create_countries.rb
Rails migration to add countries table and populate it with countries gem
require 'countries/iso3166'
class CreateCountries < ActiveRecord::Migration[6.0]
def change
create_table :countries do |t|
t.string :name, limit: 64
t.string :name_it, limit: 64
t.integer :region, limit: 1
t.string :iso2, limit: 2
t.string :phone_prefix, limit: 3
[git_status]
conflicted = "🏳"
ahead = "🏎💨"
behind = "😰"
diverged = "😵"
untracked = "🤷‍"
stashed = "📦"
#modified = "📝"
staged.value = "++"
staged.style = "green"
require 'json'
require 'benchmark'
class BaseRuntime
def figlet
puts "starting service..."
end
end
class MainRuntime < BaseRuntime
ruby -e 'loop { puts `ps -ef --sort=start_time`.split("\n").last(10) << "\n-----\n"; sleep 1; }'
root 25888 22481 0 18:03 ? 00:00:00 docker-containerd-shim be068eef4b51530beba2ef40ade7c179a38dd440660b5b262ca97589758efe0a /var/run/docker/libcontainerd/be068eef4b51530beba2ef40ade7c179a38dd440660b5b262ca97589758efe0a docker-runc
root 25906 25888 0 18:03 ? 00:00:00 /bin/sh -c cd workspace && eval $(ssh-agent) && ssh-add && (rbenv install $(cat .ruby-version) || rbenv version) && gem install bundler && rbenv rehash && bundle install && bundle exec cap $DEPLOY_ENV deploy --trace
root 25946 25906 0 18:03 ? 00:00:00 ssh-agent
root 26114 25906 4 18:03 ? 00:00:06 /root/.rbenv/versions/2.2.3/bin/cap staging deploy --trace
root 26144 3291 0 18:03 ? 00:00:00 sshd: jenkins [priv]
jenkins 26148 26144 0 18:03 ? 00:00:00 sshd: jenkins@pts/2
jenkins 26149 26148 0 18:03 pts/2 00:00:00 -bash
jenkins 26240 26149 0 18:04 pts/2
MariaDB [rails_logs_development]> alter table log_entries add column wizard_key int
-> ;
Query OK, 0 rows affected (0.22 sec)
Records: 0 Duplicates: 0 Warnings: 0
MariaDB [rails_logs_development]> Ctrl-C -- exit!
Aborted
ScottiMac:rails_logs sjohnson$ bundle exec rails c
DEPRECATION WARNING: ActiveSupport.halt_callback_chains_on_return_false= is deprecated and will be removed in Rails 5.2. (called from <top (required)> at /Users/sjohnson/fuzzygroup/hyde/coding_tests/rails_logs/config/initializers/new_framework_defaults.rb:21)
Loading development environment (Rails 5.1.4)
@fuzzygroup
fuzzygroup / divide.rb
Created March 21, 2018 14:49
Divide a number (the dividend) by another number (the divisor) without using division; assume integers and assume positive integers
def divide(dividend, divisor)
quotient = 0
while(dividend >= divisor) do
dividend = dividend - divisor
quotient = quotient + 1
end
quotient
end
@fuzzygroup
fuzzygroup / reverse_string.rb
Created March 21, 2018 14:38
reverse a string with recursion in Ruby
def reverse_recursive(string)
return string if string.size <= 1
tail = string[-1]
head = string[0...-1]
rest = reverse_recursive(head)
tail + rest
@fuzzygroup
fuzzygroup / array_tools.rb
Created February 7, 2018 18:29
Flatten array of arbitrarily nested arrays
=begin
Ruby code that will flatten an array of nested arrays of integers (or whatever)
into a flat array of integers. e.g. [[1,2,[3]],4] -> [1,2,3,4].
A tail recursion was adopted so the minimal amount of variables is added to the stack.
Usage examples:
ArrayTools.flatten([])
class HealthController < ApplicationController
def index
results = {:status => "ok"}
respond_to do |format|
format.html { render :status => 200, :html => "ok" and return }
format.json { render :status => 200, :json => results.to_json and return }
end
end
end

Keybase proof

I hereby claim:

  • I am fuzzygroup on github.
  • I am fuzzygroup (https://keybase.io/fuzzygroup) on keybase.
  • I have a public key ASAc0uLHZZur7k3KmRfr0GLgIPiWeaFVJmhMasz0XGbP1wo

To claim this, I am signing this object: