Publish the sheet to the web via share menu
Have you ever seen a website and wondered how it was made? How does a programmer even get started building one? Well, wonder no longer - I'm going to give you a quick rundown of the building blocks for a modern website.
When you access a website via your web browser, you are connecting to another computer that gives you back a set of files that make up the website. This other computer is referred to as a "server" because it serves your browser (the
require './config/boot' | |
Dtime::Users::User.find_each do |user| | |
user.set({ | |
follower_count: user.follower_ids.size, | |
following_count: user.followed_user_ids.size | |
}) | |
end |
desc 'clears cache' | |
task 'cache:clear' => 'environment' do | |
warn "Clearing cache.... #{$cache.flush}" | |
warn "Removing cache.... #{`rm -rf tmp/body`}" | |
end |
Usage:
s3 = AWS::S3.new(...)
s3.buckets['bucket-name'].objects['object-name.jpg'].url_for(:write, content_type: 'image/jpeg')
Generates a signed request allowing a PUT /bucket-name/object-name.jpg with an image file, so that an HTTP PUT can be used instead of a presigned_post request with HTTP POST and a bunch of hidden fields.
I read this trick on the Soundcloud blog: http://backstage.soundcloud.com/2012/06/building-the-next-soundcloud/
You can return an existing object from a javascript constructor to avoid creating a new object.
I'm using this as an identity map - one instance per id. Adapted to Coffeescript and adding a feature
to update the existing class with any new information (me.set(data)
), it looks something like user.coffee.
You have to copy-paste the simple return super
constructor into every child class. Without this the code breaks. Not sure how to solve this issue.
class Dtime.View extends Backbone.View | |
# Call cleanup before removing completely, | |
# unbind events from this and all children | |
leave: -> | |
@cleanup?() | |
@unbindFromAll() | |
@remove() | |
@_leaveChildren() | |
@_removeFromParent() |
To interaction with the dtime API via Javascript, you need to be able to chain together API calls in a straightforward manner.
Hypermedia APIs rely on state machine logic - given a current state, there are a number of transitions you can make (Valid HTTP verbs on the available rels)
In the code, transition(current_state, rel, opts)
is our way to transition.
class ApplicationController | |
# Sharing the setup of processors, since many actions will use them | |
# - thinking of switching this out for a facade | |
def trigger_processor(name, listening_controller) | |
processor_klass = processors[name] | |
processor = processor_klass.new(params) | |
processor.add_listener(EventNotifier.new) | |
processor.add_listener(listening_controller) | |
processor.process(current_user) | |
end |
In this case, the API endpoint is dev-api.dtime.com.
http get https://dev-api.dtime.com
See a JS fiddle example: