Skip to content

Instantly share code, notes, and snippets.

View tubbo's full-sized avatar
😎
losing my sight, losing my mind, go to the general to save some time

Tom Scott tubbo

😎
losing my sight, losing my mind, go to the general to save some time
View GitHub Profile
package main
type Addable interface {
Total int
Add(value int) int
}
func (addable *Addable) Add(value int) int {
addable.Total = addable.Total + value
@tubbo
tubbo / 1old.js
Created April 4, 2020 20:32
new syntax for changing how this-binding to functions works. just an idea for now.
class App {
ready() {
alert("hello")
}
}
const app = new App()
document.addEventListener("DOMContentLoaded", app.ready.bind(app))
// or
@tubbo
tubbo / Dockerfile
Last active November 26, 2018 16:45
docker compose setup for soundstorm
#
# Docker image build script for Soundstorm
#
# Use latest Ruby
FROM ruby:2.5.3
# Install system dependencies
RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - \
&& curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add - \
@tubbo
tubbo / polymorphic.rb
Last active April 13, 2017 20:22 — forked from laspluviosillas/polymorphic.rb
Issue with polymorphic associations
class Task < ActiveRecord::Base
has_one :notification_preference, as: :notifee
accepts_nested_attributes_for :notification_preference
end
class NotificationPreference < ActiveRecord::Base
belongs_to :notifee, polymorphic: true
end
@tubbo
tubbo / pert.rb
Last active February 13, 2017 18:28
PERT estimation calculator
#!/usr/bin/env ruby
#
# PERT Calculator v1.0.0
#
# To install, place this file in a directory that is in your $PATH. On
# my machine, I have ~/bin in my $PATH, so that's where `pert` lives.
#
# Example:
#
# $ pert 0.35 0.75 1
@tubbo
tubbo / Terminal
Last active January 26, 2017 16:42 — forked from kitsuneyo/Terminal
Game::Note.new
(irb):3: warning: toplevel constant Note referenced by Game::Note
=> #<Note id: nil, article_id: nil, type: nil, category: nil, body: nil, cite_url: nil, cite_title: nil, cite_website: nil, created_by_id: nil, created_at: nil, updated_at: nil>
# ^^ This is a new Note class object, not a Game::Note class object
@tubbo
tubbo / models.rb
Last active March 21, 2021 21:32 — forked from mfifth/models.rb
class User < ActiveRecord::Base
has_many :memberships
has_many :groups, through: :memberships
end
class Group < ActiveRecord::Base
has_many :memberships
has_many :members, class_name: 'User', through: :memberships
end
@tubbo
tubbo / order.rb
Last active January 4, 2017 21:25
class Order < ApplicationRecord
has_many :order_items, dependent: :destroy
def amount
order_items.sum :total_price
end
end
@tubbo
tubbo / activeadmin.rb
Last active December 13, 2016 20:09 — forked from bennyzr/gist:0bd5d7c59c69010dec73fa4576a5a04d
Insert tag into Active Admin body tag to disable turbolinks
ActiveAdmin::Views::Pages::Base.class_eval do
def build(*args)
super
add_classes_to_body
add_attributes_to_body
build_active_admin_head
build_page
end
def add_attributes_to_body