Skip to content

Instantly share code, notes, and snippets.

Rails.application.routes.draw do
root 'blog#index'
end
@lucasprag
lucasprag / key_chain.rb
Created May 26, 2016 15:39
key chain with polymorphism and single responsibility
class BedroomKeyGenerator
def self.generate
"algorithm of bedroom key" * 3
end
end
class FrontDoorKeyGenerator
def self.generate
"algorithm of front_door key" * 3
end
@lucasprag
lucasprag / key_chain.rb
Created May 26, 2016 15:38
key chain with meta-programming
class KeyChain
def initialize(door)
@door = door
end
def get
send(door)
end
private
@lucasprag
lucasprag / key_chain.rb
Last active May 26, 2016 16:54
key chain with if statements
class KeyChain
def initialize(door)
@door = door
end
def get
if door == :bedroom
generate_bedroom_key
elsif door == :front_door
generate_front_door_key
@lucasprag
lucasprag / GameScene.swift
Created January 29, 2016 19:13
present the game over scene
// omitted
class GameScene: SKScene, SKPhysicsContactDelegate {
// omitted
func gameOver() {
player.removeFromParent()
for enemy in enemies {
enemy.removeFromParent()
}
// transition effect that seems like doors opening
let reveal = SKTransition.doorsOpenHorizontalWithDuration(0.5)
@lucasprag
lucasprag / GameOverScene.swift
Last active January 29, 2016 19:24
game over dude
import SpriteKit
class GameOverScene: SKScene {
override init(size: CGSize) {
super.init(size: size)
// change the background of the scene to be black
backgroundColor = SKColor.blackColor()
@lucasprag
lucasprag / GameScene.swift
Created January 29, 2016 18:46
didBeginContact
// omitted
class GameScene: SKScene, SKPhysicsContactDelegate {
// omitted
func didBeginContact(contact: SKPhysicsContact) {
if (contact.bodyA.node!.name == "player" && contact.bodyB.node!.name == "enemy") {
gameOver()
}
}
@lucasprag
lucasprag / GameScene.swift
Last active January 29, 2016 19:23
SKPhysicsContactDelegate
// omitted
class GameScene: SKScene, SKPhysicsContactDelegate {
// omitted
override func didMoveToView(view: SKView) {
// tell the physics world that the class the implements
// the SKPhysicsContactDelegate is the GameScene
physicsWorld.contactDelegate = self
setupFloor()
@lucasprag
lucasprag / GameScene.swift
Created January 29, 2016 12:46
Handle the time
// omitted
class GameScene: SKScene {
// omitted
// timers
var lastTime = 0
var currentTime = 0
override func update(delta: CFTimeInterval) {
// loop all enemies and make then walk to collide with the plyer
@lucasprag
lucasprag / GameScene.swift
Last active January 29, 2016 12:36
Spaw enemies
// omitted
class GameScene: SKScene {
// omitted
var enemies = [SKSpriteNode]()
override func update(delta: CFTimeInterval) {
// loop all enemies and make then walk to collide with the player
for enemy in enemies {
enemy.position = CGPoint(x: Double(enemy.position.x) - 5, y: Double(enemy.position.y))
}