Skip to content

Instantly share code, notes, and snippets.

View elorest's full-sized avatar

Isaac Sloan elorest

View GitHub Profile
# TODO: Write documentation for `CanMapper`
module CanMapper
VERSION = "0.1.0"
# TODO: Put your code here
end
class BitMapper(T)
property buffer : T
require "http"
require "random"
require "openssl/cipher"
require "crypto/subtle"
random = Random.new
key = random.random_bytes(32)
def encrypt(value : Bytes, key)
require "http"
require "random"
require "openssl/cipher"
require "crypto/subtle"
random = Random.new
key = random.random_bytes(32)
def encrypt(value : Bytes, key)
require "http"
require "random"
require "openssl/cipher"
require "crypto/subtle"
random = Random.new
key = random.random_bytes(32)
def encrypt(value : Bytes, key)
class Services::FitbitController < ApplicationController
access user: :all
def callback
logger.info params
logger.info "Hello********************************************************************************"
if params[:code]
current_user.services.update_all(expired: true)
current_user.services.create(code: params[:code])
redirect_to root_path, notice: "Succesfully connected to Fitbit"
@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
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
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
= 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
# == 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