When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:
main {
max-width: 38rem;
padding: 2rem;
margin: auto;
}
How do you send information between clients and servers? What format should that information be in? What happens when the server changes the format, but the client has not been updated yet? What happens when the server changes the format, but the database cannot be updated?
These are difficult questions. It is not just about picking a format, but rather picking a format that can evolve as your application evolves.
By now there are many approaches to communicating between client and server. These approaches tend to be known within specific companies and language communities, but the techniques do not cross borders. I will outline JSON, ProtoBuf, and GraphQL here so we can learn from them all.
# Add all gems in the global gemset to the $LOAD_PATH so they can be used in rails3 console with bundler | |
if defined?(::Bundler) | |
$LOAD_PATH.concat Dir.glob("#{ENV['rvm_path']}/gems/#{ENV['rvm_ruby_string']}@global/gems/*/lib") | |
end |
require 'rubygems' | |
require 'rack' | |
class Object | |
def webapp | |
class << self | |
define_method :call do |env| | |
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?) | |
[200, {}, send(func, *attrs)] | |
end |
#inspired (a lot) by http://blog.gugl.org/archives/47 | |
# Note, to achieve this I should only have to define a formatter. | |
# why BufferedLogger instead of Logger with a buffered IO? | |
# I suspect there is a reason for BufferedLogger so I'll keep it | |
class LineLogger < ActiveSupport::BufferedLogger | |
SEVERITIES = Severity.constants.inject([]) {|arr,c| arr[Severity.const_get(c)] = c; arr} | |
attr_writer :formatter |
#!/usr/bin/env ruby | |
require "irb" | |
load "#{ENV['HOME']}/.irbrc" | |
def IRB.run_config; end | |
ARGV.unshift "console" | |
load File.dirname(__FILE__) + "/rails" |
# exe_packager.rb : find all dependencies for a given EXE and package it in | |
# a zip file | |
require 'csv' | |
require 'zip/zip' | |
require 'zippy' | |
ARGV.each do |exe_file| | |
short_filename = File.basename(exe_file, '.exe') |
Warden::Manager.serialize_into_session{|user| user.id } | |
Warden::Manager.serialize_from_session{|id| User.get(id) } | |
Warden::Manager.before_failure do |env,opts| | |
# Sinatra is very sensitive to the request method | |
# since authentication could fail on any type of method, we need | |
# to set it for the failure app so it is routed to the correct block | |
env['REQUEST_METHOD'] = "POST" | |
end | |