This is a maintained listing of all the different ways to debug and profile Node.js applications. If there is something missing or an improvement, post a comment! :)
namespace :db do desc "Backup project database. Options: DIR=backups RAILS_ENV=production MAX=7" | |
task :backup => [:environment] do | |
datestamp = Time.now.strftime("%Y-%m-%d_%H-%M-%S") | |
base_path = Rails.root | |
base_path = File.join(base_path, ENV["DIR"] || "backups") | |
backup_base = File.join(base_path, 'db_backups') | |
backup_folder = File.join(backup_base, datestamp) | |
backup_file = File.join(backup_folder, "#{RAILS_ENV}_dump.sql") | |
FileUtils.mkdir_p(backup_folder) | |
db_config = ActiveRecord::Base.configurations[RAILS_ENV] |
def login_as(user) | |
raise "Was expecting a User. Got a #{user.class} instead. Exiting." if user.class != User | |
@controller.request.env['warden'] = mock( | |
Warden, | |
:authenticate => user, | |
:authenticate! => user, | |
:authenticated? => true, | |
:authenticate? => true | |
) | |
user.last_sign_in_at = Time.now |
- Jim Weirich: The Building Blocks of Modularity – http://goo.gl/g4Nk
- Jim Weirich: SOLID Ruby – http://goo.gl/z3jd
- Sandi Metz: SOLID Object-Oriented Design – http://goo.gl/PDn6T
- Sandi Metz: Less – The Path to Better Design – http://goo.gl/VuTl4
- Demeter is for Encapsulation – http://is.gd/eeyLx
- Opinionated Modular Code – http://is.gd/eeyXm
- Scaling to Hundreds of Millions of Requests – http://vimeo.com/12814529
- Confident Code – http://goo.gl/VFLX
- Destroy All Software Screencasts – https://www.destroyallsoftware.com/screencasts
- Corey Haines: Fast Rails Tests – http://goo.gl/Va2gb
In order to demo your feature specs, follow these steps:
- Add capybara, poltergeist, launchy and selenium-webdriver to your Gemfile under test and development group.
- Add the attached demo helper to your spec/support.
- Add the capybara config to your spec_helper file.
- Run bundle install.
- Write your feature with its scenario specs.
- Put a demo filter on each scenario you want to demo. ( refer to the example below )
- Run bundle exec rspec spec.
require 'spec/support/grep_matcher' | |
describe do | |
disallow_presence_of pattern: "send(.*#", | |
location: "app/", | |
description: "Do not use dynamic method invocations", | |
failure: "Please change dynamic method call to something more sane." | |
end |
<?xml version="1.0" encoding="UTF-8"?> | |
<!-- | |
Licensed to the Apache Software Foundation (ASF) under one or more | |
contributor license agreements. See the NOTICE file distributed with | |
this work for additional information regarding copyright ownership. | |
The ASF licenses this file to You under the Apache License, Version 2.0 | |
(the "License"); you may not use this file except in compliance with | |
the License. You may obtain a copy of the License at | |
http://www.apache.org/licenses/LICENSE-2.0 |
I'm hunting for the best solution on how to handle keeping large sets of DB records "sorted" in a performant manner.
Most of us have work on projects at some point where we have needed to have ordered lists of objects. Whether it be a to-do list sorted by priority, or a list of documents that a user can sort in whatever order they want.
A traditional approach for this on a Rails project is to use something like the acts_as_list
gem, or something similar. These systems typically add some sort of "postion" or "sort order" column to each record, which is then used when querying out the records in a traditional order by position
SQL query.
This approach seems to work fine for smaller datasets, but can be hard to manage on large data sets with hundreds (or thousands) of records needing to be sorted. Changing the sort position of even a single object will require updating every single record in the database that is in the same sort group. This requires potentially thousands of wri
require 'csv' | |
file = "#{Rails.root}/public/data.csv" | |
table = User.all;0 # ";0" stops output. Change "User" to any model. | |
CSV.open( file, 'w' ) do |writer| | |
writer << table.first.attributes.map { |a,v| a } | |
table.each do |s| | |
writer << s.attributes.map { |a,v| v } |
columns_that_make_record_distinct = [:some_id, :another_name] | |
distinct_ids = Model.select("MIN(id) as id").group(columns_that_make_record_distinct).map(&:id) | |
duplicate_records = Model.where.not(id: distinct_ids) |