Skip to content

Instantly share code, notes, and snippets.

View elorest's full-sized avatar

Isaac Sloan elorest

View GitHub Profile
require "http"
require "./*"
module Amber::Controller
class Base
include Render
include Redirect
include Callbacks
protected getter request = HTTP::Request.new("GET", "/")
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:
require "http"
require "./*"
module Amber::Controller
class Base
include Render
include Redirect
include Callbacks
protected getter request = HTTP::Request.new("GET", "/")
require "http"
require "./*"
module Amber::Controller
class Base
include Render
include Redirect
include Callbacks
protected getter request = HTTP::Request.new("GET", "/")
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|
# == 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
= 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
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
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
@elorest
elorest / client.cr
Last active August 28, 2019 22:08
Crystal Websocket Demo
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