Skip to content

Instantly share code, notes, and snippets.

View Thomascountz's full-sized avatar
💃
LGTM!

Thomas Countz Thomascountz

💃
LGTM!
View GitHub Profile
@Thomascountz
Thomascountz / congress.rb
Created June 8, 2017 01:14
API wrapper for Propublica's Congress API
# Abstracts queries to The Propublica Congress API into methods
class Congress
attr_reader :query
def initialize(args)
@query = args.fetch(:query, nil)
end
def members_of_senate(senate_number = 115)
get("#{senate_number}/senate/members.json")
@Thomascountz
Thomascountz / perceptron_spec.rb
Last active March 28, 2018 15:54
Initial Spec for a Perceptron Class
require 'spec_helper'
require 'perceptron'
RSpec.describe Perceptron do
describe '#activation' do
describe 'logic AND' do
bias = -1
weights = [bias, 1, 1]
describe 'when inputs are 0 and 0' do
it 'returns 0 AND 0' do
@Thomascountz
Thomascountz / perceptron.py
Last active March 5, 2023 12:50
Perceptron in Python v.1
"""
MIT License
Copyright (c) 2018 Thomas Countz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@Thomascountz
Thomascountz / perceptron_and.py
Created April 5, 2018 20:55
Using Perceptron in Python v. 1
import numpy as np
from perceptron import Perceptron
training_inputs = []
training_inputs.append(np.array([1, 1]))
training_inputs.append(np.array([1, 0]))
training_inputs.append(np.array([0, 1]))
training_inputs.append(np.array([0, 0]))
labels = np.array([1, 0, 0, 0])
@Thomascountz
Thomascountz / test_perceptron.py
Last active October 13, 2020 08:39
Tests for Python Perceptron v.1
"""
MIT License
Copyright (c) 2018 Thomas Countz
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
@Thomascountz
Thomascountz / .vimrc
Created April 23, 2018 18:24
vim dotfile
set relativenumber " relative line numbers
set tabstop=2 " soft tabs
set shiftwidth=2 " soft tabs
set expandtab " use spaces for tabs
set backspace=2 " backspace in insert mode works like normal editor
syntax on " syntax highlighting
filetype indent on " activates indenting for files
set autoindent " auto indenting
set number " line numbers
colorscheme desert " colorscheme desert
@Thomascountz
Thomascountz / .tmux.conf
Created April 23, 2018 18:26
tmux dotfile
##############################
# _
# | |_ _ __ ___ _ ___ __
# | __| '_ ` _ \| | | \ \/ /
# | |_| | | | | | |_| |> <
# \__|_| |_| |_|\__,_/_/\_\
#
#############################
#
# COPY AND PASTE
@Thomascountz
Thomascountz / README.md
Last active May 30, 2018 15:31
State Pattern Example in Ruby

State Pattern Example in Ruby

The State pattern suggests to create new classes for all possible states of a context object and to extract the state-related behaviors into these classes. The context will contain a reference to a state object that represents its current state. Instead of performing a behavior on its own, the context will delegate the execution to a state object. To change the context's state, one would pass another state object to the context. But to make states interchangeable, all states classes must follow the common interface, and the context must communicate with its state object via that interface. The described structure may look like the Strategy pattern, but there is one key difference. In the State pattern, the context, as wells as particular states, can initiate the transitions from one state to another.

Read more about the State Pattern here: https://refactoring.guru/design-patterns/state

Example Usage

@Thomascountz
Thomascountz / bottles.rb
Last active June 12, 2018 12:52
Listing 6.5 - 99 Bottles of OOP
# https://github.com/sandimetz/99bottles/blob/862f37346dfa8a9630c2ace0423e59c207a9f3f8/lib/bottles.rb
class BottleNumber
attr_reader :number
def initialize(number)
@number = number
end
def to_s
"#{quantity} #{container}"
end
class BottleNumberState0
end