This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# vid @ https://twitter.com/josh_cheek/status/835884161047080960 | |
# and @ https://vimeo.com/205773556 | |
require 'graphics' | |
class MineSweeper | |
class Cell | |
def initialize(mine:, clicked:, marked:, x:, y:, count:) | |
@x, @y, @mine, @clicked, @marked, @count = | |
x, y, mine, clicked, marked, count | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
loc1_name = 'Chicago' # => "Chicago" | |
loc2_name = 'Houston' # => "Houston" | |
# Get the lib with `gem install geocoder` | |
# it ultimately calls out to this API: http://maps.googleapis.com/maps/api/geocode/json?address=Chicago&language=en&sensor=false | |
require 'geocoder' # => true | |
include Math # => Object | |
def radians(n) | |
n * PI / 180 # => 0.7309109668442155, -1.5294285014482003, 0.5194174327134308, -1.664517065837707 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This is DRY run amok. There is no reason to create an abstraction around | |
# loading all the notes when we have it already: Note.all | |
# The private methods add no value. | |
class NotesController < ApplicationController | |
def index | |
load_notes | |
end | |
def show | |
load_note |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Based on https://codepen.io/clawtros/pen/yVONbR | |
require 'graphics' | |
SIZE = 0.5 | |
Node = Struct.new :x, :y, :∆x, :∆y, :color, :lifespan, :on_death do | |
def successor | |
new∆x = ∆x*0.98 + (rand - 0.5) / 2 | |
new∆y = ∆y*0.98 + (rand - 0.5) / 2 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#encoding: utf-8 | |
import os | |
import time | |
print(" _ _ ___ ______ \n" + | |
" (_) | / _ \ | ___ \\\n" + | |
" _ __ ___ _| |_ _ __ ___ / /_\ \| |_/ /\n" + | |
"| '_ ` _ \| | __| '_ ` _ \| _ || __/ \n" + | |
"| | | | | | | |_| | | | | | | | || | \n" + |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class DecoratorClone | |
def initialize(model) | |
@model = model | |
end | |
def method_missing(m, *args) | |
raise NameError, "Decorator method '#{m}' not found" unless @model.respond_to?(m) | |
@model.send(m, *args) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://twitter.com/josh_cheek/status/804868012620779521 | |
radius = 21 | |
0.step by: 1 do |degrees| | |
angle = degrees*Math::PI/180 | |
y = (radius * (Math.sin(angle) / 2 + 1)).to_i | |
x = (radius * (Math.cos(angle) / 2 + 1)).to_i | |
print "\e[#{y};#{2*x}HXX" | |
sleep 0.01 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# app/models/permissions/admin_permission.rb | |
module Permissions | |
class AdminPermission < BasePermission | |
def initialize(user) | |
allow_all | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# Extracted from traceroute gem + checking the presence of views as well | |
require_relative './config/environment.rb' | |
class Traceroute | |
def initialize(app) | |
@app = app | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
VIEW_PATH = 'lib/assets' | |
namespace :static do | |
desc 'Render all resources' | |
task :publicate => :environment do | |
resources(VIEW_PATH).each do |src, dest| | |
html= controller.render_to_string(file:src, layout:'application') | |
dirname = File.dirname(dest) | |
unless File.directory?(dirname) | |
FileUtils.mkdir_p(dirname) |