I no longer mantain this list. There are lots of other very comprehensive JavaScript link lists out there. Please see those, instead (Google "awesome JavaScript" for a start).
/** @jsx React.DOM */ | |
var api = 'http://addressbook-api.herokuapp.com/contacts'; | |
var App = React.createClass({ | |
mixins: [Routed], | |
render: function() { | |
return ( | |
<Root> | |
<Index path="/"/> |
# Rails 4 Application Template | |
# Remove normal files we don't want | |
remove_file "README.rdoc" | |
remove_file "public/index.html" | |
remove_file "app/assets/images/rails.png" | |
# Copy database.yml and secrets.yml to sample | |
inside "config" do | |
run "cp database.yml database.yml.sample" | |
run "cp secrets.yml secrets.yml.sample" |
require 'singleton' | |
# outputs a colored call-trace graph to the Rails logger of the lines of ruby code | |
# invoked during a single request. | |
# | |
# Example: | |
# | |
# 1) Make sure this file is loaded in an initializer | |
# | |
# 2) Add the following to your application.rb in Rails3: |
I have bemoaned the lack of a ViewModel in Rails many times, and I prefer using Presenters to simulate a ViewModel. But it turns out there is an object that does represent the state of the view in Rails apps. Its an instance of ActionView::Base
that the controller calls view_context
. We don't have much control of this object, but it seems like a logical place to put our view-specific behavior.
This code is an attempt at creating Presenters using modules. The module will be mixed into the view_context
object. This is very similar to how a Decorator module will be mixed into a model object, only instead of being specific to the model is it specific to the view.
This means that testing your presenter is no different than testing any other module. So relying on dependencies such as other methods or instance variables can make testing difficult.
class CommentsController < ApplicationController | |
def create | |
translator.translate params | |
end | |
private | |
def translator | |
CommentRequestTranslator.new(processor) |
Latency Comparison Numbers (~2012) | |
---------------------------------- | |
L1 cache reference 0.5 ns | |
Branch mispredict 5 ns | |
L2 cache reference 7 ns 14x L1 cache | |
Mutex lock/unlock 25 ns | |
Main memory reference 100 ns 20x L2 cache, 200x L1 cache | |
Compress 1K bytes with Zippy 3,000 ns 3 us | |
Send 1K bytes over 1 Gbps network 10,000 ns 10 us | |
Read 4K randomly from SSD* 150,000 ns 150 us ~1GB/sec SSD |
Dear Rubyists,
I just lost a contract because of my code in a Rails project.
The specific code in question is related to a "posting a comment" feature. Here are the details:
In this project, "posting a comment" does not simply entail inserting a row into the database. It involves a procedure to yes, insert a row, but also detect its language, check for spam, send emails, and "share" it to Twitter and Facebook. I believe this algorithm should be encapsulated. I do not believe it belongs in a controller or a model. I do not believe Active Record callbacks should be used.
The "senior developer", whom is the stake holder's right hand man, said this:
class ActionDispatch::Routing::Mapper | |
def draw(routes_name) | |
instance_eval(File.read(Rails.root.join("config/routes/#{routes_name}.rb"))) | |
end | |
end | |
BCX::Application.routes.draw do | |
draw :api | |
draw :account | |
draw :session |
desc "convert a latin1 database with utf8 data into proper utf8" | |
task :convert_to_utf8 => :environment do | |
puts Time.now | |
dryrun = ENV['DOIT'] != '1' | |
conn = ActiveRecord::Base.connection | |
if dryrun | |
def conn.run_sql(sql) | |
puts(sql) | |
end | |
else |