Skip to content

Instantly share code, notes, and snippets.

@jleo3
jleo3 / times_square.sol
Created January 9, 2022 15:53
Created using remix-ide: Realtime Ethereum Contract Compiler and Runtime. Load this file by pasting this gists URL or ID at https://remix.ethereum.org/#version=soljson-v0.8.0+commit.c7dfd78e.js&optimize=false&runs=200&gist=
// SPDX-License-Identifier: MIT
pragma solidity 0.8.0;
import "https://github.com/0xcert/ethereum-erc721/src/contracts/tokens/nf-token-metadata.sol";
import "https://github.com/0xcert/ethereum-erc721/src/contracts/ownership/ownable.sol";
contract newNFT is NFTokenMetadata, Ownable {
constructor() {
nftName = "Synth NFT";
#! /usr/bin/env bash
set -o errexit
sudo apt-get update && sudo apt-get upgrade
install="sudo apt-get install -y -q"
update="sudo apt-get update -q"
# setup install directory
mkdir -p /tmp/install

Refactoring

Here's a list of resources I pulled together that explain what refactoring is, why it exists, what code smells are, and the mechanics of refactoring.

The Theory of Refactoring

json.credits @credits do |credit|
json.creditor credit.creditor
json.amount number_to_currency(credit.amount)
json.purchase_date credit.purchase_date.strftime("%a %e %b")
end
[11] pry(main)> all_books = Book.all
Book Load (0.2ms) SELECT "books".* FROM "books"
=> [#<Book id: 1, title: "Catcher in the Rye", author: "J.D. Salinger", abstract: "A catcher gets caught in a corn field\r\n", created_at: "2013-10-01 23:58:06", updated_at: "2013-10-01 23:59:25">,
#<Book id: 2, title: "foo bar", author: nil, abstract: nil, created_at: "2013-10-03 18:06:16", updated_at: "2013-10-03 18:06:16">,
#<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31">]
[12] pry(main)> all_books = Book.all
[13] pry(main)> all_books.size
=> 3
[14] pry(main)> all_books.first
=> #<Book id: 1, title: "Catcher in the Rye", author: "J.D. Salinger", abstract: "A catcher gets caught in a corn field\r\n", created_at: "2013-10-01 23:58:06", updated_at: "2013-10-01 23:59:25">
[1] pry(main)> Book
=> Book(id: integer, title: string, author: string, abstract: text, created_at: datetime, updated_at: datetime)
[2] pry(main)> Book.create title: "Who Stole My Cheese?"
(0.1ms) begin transaction
SQL (5.1ms) INSERT INTO "books" ("created_at", "title", "updated_at") VALUES (?, ?, ?) [["created_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00], ["title", "Who Stole My Cheese?"], ["updated_at", Tue, 08 Oct 2013 23:14:31 UTC +00:00]]
(14.9ms) commit transaction
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31">
[3] pry(main)> Book.find(4)
Book Load (0.3ms) SELECT "books".* FROM "books" WHERE "books"."id" = ? LIMIT 1 [["id", 4]]
=> #<Book id: 4, title: "Who Stole My Cheese?", author: nil, abstract: nil, created_at: "2013-10-08 23:14:31", updated_at: "2013-10-08 23:14:31">
%table.table
%body.table-stribed
%tr
%td
Name
%td
Amount
%tr
- @transactions.each do |transaction|
%td
Shirt.create name: "Rushed to Market", description: "Meta Shirt showing Warning about inability to load shirt", image: "rushed_to_market.png"
Shirt.create name: "Darwin's Delight", description: "Darwin with paper cutouts of evolution", image: "darwins_delight.png"
Shirt.create name: "Victory through Chaos", description: "Button Masher's Manifesto", image: "victory_through_chaos.png"
Shirt.create name: "Console Wars", description: "Gaming consoles as Star Wars battle vehicles", image: "console_wars.png"
Shirt.create name: "Downtime", description: "Lightsabers charging at an outlet", image: "downtime.png"
Shirt.create name: "Shoot First", description: "Solo and Greedo in 8-bit emulating text based game", image: "shoot_first.png"
Shirt.create name: "I Quit!", description: "Stick Figure guy has enough", image: "i_quit.png"
Shirt.create name: "Family Breakfast", description: "Vader makes eggs for a young Luke and Leia", image: "family_breakfast.png"
Shirt.create name: "Music Pirate", description: "Pirate turns to
// Place all the styles related to the Games controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
body, p, h1, h2, h3, h4, h5 {
font-family: Arial;
}
p {
font-size: 16px;
<% if @secret_number == @chosen_number %>
<h1>CONGRATS! YOU WON!</h1>
<h4>The secret number was <%=@secret_number%></h4>
<p><%= image_tag 'games/cat-wins.gif' %></p>
<% else %>
<h1>Sorry, you lose...</h1>
<h4>The secret number was <%=@secret_number%></h4>
<p><%= image_tag 'games/loser.gif' %></p>
<% end %>