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
require "http" | |
require "./*" | |
module Amber::Controller | |
class Base | |
include Render | |
include Redirect | |
include Callbacks | |
protected getter request = HTTP::Request.new("GET", "/") |
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
The MIT License (MIT) | |
Copyright (c) 2017 Elias Perez | |
Permission is hereby granted, free of charge, to any person obtaining a copy | |
of this software and associated documentation files (the "Software"), to deal | |
in the Software without restriction, including without limitation the rights | |
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
copies of the Software, and to permit persons to whom the Software is | |
furnished to do so, subject to the following conditions: |
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
require "http" | |
require "./*" | |
module Amber::Controller | |
class Base | |
include Render | |
include Redirect | |
include Callbacks | |
protected getter request = HTTP::Request.new("GET", "/") |
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
require "http" | |
require "./*" | |
module Amber::Controller | |
class Base | |
include Render | |
include Redirect | |
include Callbacks | |
protected getter request = HTTP::Request.new("GET", "/") |
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
require "flate" | |
require "gzip" | |
require "openssl/cipher" | |
require "base64" | |
require "secure_random" | |
module Flate | |
def self.write(str) | |
io = IO::Memory.new | |
Flate::Writer.new(io) do |flate| |
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
# == Schema Information | |
# | |
# Table name: images | |
# | |
# id :integer not null, primary key | |
# file :string(255) | |
# category :string(255) | |
# tank_configuration_id :integer | |
# created_at :datetime | |
# updated_at :datetime |
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
= form_for(@tank_configuration) do |f| | |
- if @tank_configuration.errors.any? | |
#error_explanation | |
h2 | |
= pluralize(@tank_configuration.errors.count, "error") | |
| prohibited this tank_configuration from being saved: | |
ul | |
- @tank_configuration.errors.full_messages.each do |msg| | |
li | |
= msg |
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
def select_field(name : String | Symbol, collection : Array(Array), **options : Object) | |
options_hash = Kit.safe_hash(options, {:name => name}) | |
selected = [options_hash.delete(:selected)].flatten.map(&.to_s) | |
content(element_name: :select, options: options_hash) do | |
String.build do |str| | |
collection.map do |item| | |
str << %(<option value="#{item[0]}"#{selected.includes?(item[0].to_s) ? %( selected="selected") : nil}>#{item[1]}</option>) | |
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
class ApiController < ApplicationController | |
def index | |
session[%w(a b c d e f g h i j k l m n o p).sample] = Time.now.to_s | |
respond_with do | |
json session.to_h.to_json | |
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
require "http" | |
ws = HTTP::WebSocket.new("127.0.0.1", "/ping", 3000) | |
# react to received messages | |
ws.on_message do |msg| | |
puts "recieved message: #{msg}." | |
end | |
# spawn a fiber that will forward messages from a channel |