Programming Languages
Lisp (1958)
Interpreted, dynamic typing, functional
C (1972)
Compiled, static typing, imperative (procedural)
Interpreted, dynamic typing, functional
Compiled, static typing, imperative (procedural)
// 1. Swith two variables | |
// ES5 | |
var temp = a; | |
a = b; | |
b = temp; | |
// ES6 - destructuring assignment | |
[b, a] = [a, b]; |
// BEFORE REFACTORING (IMPERATIVE) | |
var filteredLinks = []; | |
var weekdayCounts = {}; | |
// Limit to 4 links per weekday. | |
// Loop through all links and keep track of | |
// how many are in each weekday. | |
widget.links.forEach(function(link) { | |
var weekday = link.group; | |
if (weekdayCounts[weekday] === undefined) { | |
weekdayCounts[weekday] = 0; |
'use strict'; | |
var R = require('ramda'); | |
var blank = function(value) { | |
return value == null || (typeof value === 'string' && value.trim().length === 0); | |
}; | |
var present = function(value) { | |
return !blank(value); |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; BASE CLASS | |
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
; public class ContentItem { | |
; public String foobar() { | |
; return "content_item"; | |
; } | |
; } |
class Foo | |
def bar | |
end | |
end |
namespace :db do | |
# NOTE: In Rails 3 there will be a db:setup task but it only works if ActiveRecord::Base.schema_format == :ruby | |
# See http://afreshcup.com/2009/05/11/seed-data-in-rails-3 | |
# The following patch fixes db:schema:load to work with schema_format :sql: | |
# https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/2789-make-rake-task-dbschemaload-compatible-with-sql-schema-format | |
desc 'Recreate the database, load the schema, and initialize with the seed data' | |
task :super_setup => [ 'db:drop', 'db:create' ] do | |
system("cat db/development_structure.sql db/development_data.sql | script/dbconsole") | |
seed_file = File.join(Rails.root, 'db', 'seeds.rb') | |
load(seed_file) if File.exist?(seed_file) |
'use strict'; | |
// NOTE: this in memory locking approach will only work with a single process | |
// You might use something like Redis och memcachached for storing the lock if you need to lock | |
// across several processes. | |
var synchronizedFunction = function(lockIdFn, fn) { | |
var locks = {}; | |
var synchronized = function() { | |
var args = Array.prototype.slice.call(arguments), | |
lockId = lockIdFn.apply(null, args); |
# In lib/tasks/deploy.rake | |
namespace :deploy do | |
def write_error_page(status, locale = nil) | |
dest_filename = [status.to_s, locale, "html"].compact.join(".") | |
File.open(File.join(Rails.root, "public", dest_filename), "w") do |file| | |
path = File.join(Rails.root, "app", "views", "errors", "#{status}.rhtml") | |
file.print ERB.new(File.read(path)).result | |
end | |
end |
describe "Mocking/Stubbing Associations with RSpec" do | |
it "can be done with proxy_target" do | |
# Suppose the Article model has an after_save callback that invokes notify_change on the author | |
# if the article has been changed. | |
@article.author.proxy_target.should_receive(:notify_change) | |
@article.update_attributes(:body => "new body") | |
end | |
end |