Skip to content

Instantly share code, notes, and snippets.

View edwardloveall's full-sized avatar
👈
there he is

Edward Loveall edwardloveall

👈
there he is
View GitHub Profile
Record
new -> LocalOnly
LocalOnly*
save -> InFlight
Persisted
edit -> Edited
Edited
save -> InFlight
InFlight
success -> Persisted
@edwardloveall
edwardloveall / double_spec.rb
Created January 4, 2018 15:09
Quick test of RSpec's Instance double
RSpec.configure do |config|
config.mock_with :rspec do |mocks|
mocks.verify_doubled_constant_names = true
end
end
class Greeting
def greet
'Hi'
end
class Person
getter name
def initialize(@name : String)
end
end
class AddDirectionToVotes::V20171102095010 < LuckyMigrator::Migration::V1
def migrate
alter :votes do
add positive : Bool?
end
execute "UPDATE votes SET positive = 'true';"
execute "ALTER TABLE votes ALTER COLUMN positive SET NOT NULL;"
end
@edwardloveall
edwardloveall / thoughts.md
Created October 30, 2017 00:39
Lucky thoughts
web v0.4.2
migrator: v0.2.3

Routing is a little odd at first, but I think I will enjoy it eventually. It's weird having implicit routes.

I love having the routes in pages be their own classes, i.e. link "Edit", to: Topics::Edit.route(topic). The relationship between routes and controller#action is a part of rails that I think a lot of beginners don't grok for a while.

My mental model for what goes in a form, query, and model is pretty confused. I love the idea of separation. It's one of the first parts of rails to get messy, but I need a lot of help understanding where to put what. This could very well be me having to unlearn rails.

# An algorithm to reverse a number using only mathematical functions, i.e. no
# String.reverse, or similar. For example, turn `1234` into `4321`.
def reverse_number(number)
digit_count = Math.log10(number).floor + 1
sum = 0
(1..digit_count).each do |power|
ten_to_the_n = 10.0**power
ten_to_the_n_minus_one = 10.0**(power - 1)
remainder = number % ten_to_the_n
@edwardloveall
edwardloveall / NSDrawing.swift
Created April 12, 2016 00:41
Which way should I draw?
import Cocoa
class ViewA: NSView {
override func drawRect(rect: NSRect) {
let context = NSGraphicsContext.currentContext()?.CGContext
CGContextSetRGBFillColor(context, 0, 0, 0, 1)
CGContextFillRect(context, bounds)
CGContextSetRGBFillColor(context, 1, 0, 0, 1)
@edwardloveall
edwardloveall / ps4 controller fix.md
Last active January 1, 2016 01:03
Fix PS4 controller syncing with Mac OS X Yosemite
@edwardloveall
edwardloveall / migrate.rb
Created March 7, 2015 00:09
Rails: Migrate table from integer based primary keys to UUID
remove_column :table, :id, :primary_key
add_column :table, :id, :uuid, default: 'uuid_generate_v4()'
execute('ALTER TABLE table ADD PRIMARY KEY (id);')
@edwardloveall
edwardloveall / gtav_stocks.rb
Last active March 30, 2017 18:28
Get stocks for the GTA V BAWSAQ
require 'net/http'
require 'json'
def request
Net::HTTP.get(URI('http://socialclub.rockstargames.com/games/gtav/ps4/bawsaq'))
uri = URI('http://socialclub.rockstargames.com/games/gtav/ajax/stockdetail')
http = Net::HTTP.new(uri.host, uri.port)
req = Net::HTTP::Get.new(uri)