Adds a readable way of expressing percentage calculations.
TL;DR
200 - 15.percent # 170
<?php | |
// setup a template loader used by Twig to load the template strings. Most common is loading | |
// templates from the file system. This loader needs takes a template path or an array of | |
// template paths as argument to its constructor. | |
$templatePath = __DIR__.'/templates'; | |
$loader = new Twig_Loader_Filesystem($templatePath); | |
// setup the twig environment. This is used for the actual rendering. The Twig environment takes | |
// the loader and an array of options as its arguments. In this example I use the twig environment |
require 'net/http' | |
module Net | |
class HTTP | |
def self.enable_debug! | |
raise "You don't want to do this in anything but development mode!" unless Rails.env == 'development' | |
class << self | |
alias_method :__new__, :new | |
def new(*args, &blk) | |
instance = __new__(*args, &blk) | |
instance.set_debug_output($stderr) |
require 'io/console' | |
class Board | |
X, Y = 0, 1 | |
COLORS = [:red, :green, :brown, :magenta, :cyan] | |
HOR_LINE = "-" * 29 | |
EMPTY_COL = "| " * 4 + "|" | |
def initialize | |
@score = 0 |
Is this a bad idea?
module Decorate
def decorate(definition, options)
self.send(:alias_method, "__original_#{definition}", definition)
define_method definition, Proc.new { |*args|
send(options.fetch(:with), *args, &Proc.new { |args|
send("__original_#{definition}", *args)
})
Memoize
memoizes function return values based on class name, method name, and arguments. This means that this only works for functions that use state / have side effects.
module Memoize
def memoize(definition)
self.send(:alias_method, "__original_#{definition}", definition)
define_method definition, Proc.new { |*args|
@__memo ||= {}
# This is an h1 | |
## This is an h2 | |
Here is a paragraph with *some bold italics* and some **bold text**. | |
This paragraph is a little harder because it had **a bold sentence *with some italics* to make it more difficult.** | |
And finally a [link to shopify](http://shopify.com). |
.segment "HEADER" | |
.byte "NES", $1A ; Constant | |
.byte 2 ; 2 x 16KB PRG ROM | |
.byte 1 ; 1 x 8KB CHR ROM | |
.segment "CHARS" | |
;------------------------------------------------------------- | |
; CREATE SPRITES | |
;------------------------------------------------------------- | |
; The following creates one sprite. The following two bitmaps |
; ___ _ __ ___ __ ___ | |
; / __|_ _ __ _| |_____ / /| __|/ \_ ) | |
; \__ \ ' \/ _` | / / -_) _ \__ \ () / / | |
; |___/_||_\__,_|_\_\___\___/___/\__/___| | |
; An annotated version of the snake example from Nick Morgan's 6502 assembly tutorial | |
; on http://skilldrick.github.io/easy6502/ that I created as an exercise for myself | |
; to learn a little bit about assembly. I **think** I understood everything, but I may | |
; also be completely wrong :-) |