This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Polymorphic validation | |
class Comment < ActiveRecord::Base | |
attr_accessible :content, :user, :user_id, :commentable, :commentable_id, :commentable_type | |
belongs_to :commentable, polymorphic: true | |
belongs_to :user | |
validates :commentable, :user, existence: { both: false } # Via validates_existence gem | |
validate :can_comment?, if: [:user, :commentable_id, :commentable_type] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
env: | |
PGHOST: localhost | |
PGPASS: runner | |
PGUSER: runner | |
RAILS_ENV: test | |
DATABASE_URL: postgresql://runner:runner@localhost | |
name: Rails Tests | |
on: [push, pull_request_review] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# you can make a text file of request times (in ms, one number per line) and import it here, or you can use a probability distribution to simulate request times (see below where setting req_durations_in_ms) | |
# rq = read.table("~/Downloads/request_times.txt", header=FALSE)$V1 | |
# argument notes: | |
# parallel_router_count is only relevant if router_mode is set to "intelligent" | |
# choice_of_two, power_of_two, and unicorn_workers_per_dyno are only relevant if router_mode is set to "naive" | |
# you can only select one of choice_of_two, power_of_two, and unicorn_workers_per_dyno | |
run_simulation = function(router_mode = "naive", | |
reqs_per_minute = 9000, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(processx) | |
library(RPostgres) | |
library(httr) | |
library(dbplyr) | |
library(tidyverse) | |
# this example assumes you've created a heroku postgresql | |
# instance and have the app name (in this example, "rpgtestcon"). | |
# use the heroku command-line app |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(shiny) | |
library(dplyr) | |
library(lubridate) | |
# Load libraries and functions needed to create SQLite databases. | |
library(RSQLite) | |
library(RSQLite.extfuns) | |
saveSQLite <- function(data, name){ | |
path <- dplyr:::db_location(filename=paste0(name, ".sqlite")) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'pathname' | |
require 'open3' | |
require 'mini_magick' | |
SRC_DIR = '/path/to/src/dir/'.freeze | |
TMP_DIR = '/path/to/tmp/dir/'.freeze | |
class TextReader | |
def initialize(input_path, output_path) | |
@input_path = input_path |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
# | |
# gather a few statistics and find all flagged comments | |
# | |
# Usage: | |
# rfluff [-qf] [tag] [tag] ... | |
# | |
# -qf outputs a vim compatible quickfix format, otherwise | |
# the output is human readable |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Show basic controller usage stats' | |
task :controllers => :environment do | |
logfiles = Dir['log/%s.log*' % Rails.env].sort | |
logs_gz, logs_txt = logfiles.partition{|f| Pathname.new(f).extname == '.gz' } | |
results = `ag Started -A 1 #{logs_txt.join(' ')}` | |
unless logs_gz.empty? | |
results << `zcat #{logs_gz.join(' ')} |ag Started -A 1` | |
end | |
Event = Struct.new(:http_method, :uri_path, :client_ip, :requested_at_str, :controller_name, :controller_action, :format) do | |
def requested_at |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
desc 'Find routes that will raise a routing error when requested' | |
task unroutable_routes: :environment do | |
# A lot of this code was taken from how `rake routes` works | |
# https://github.com/rails/rails/blob/f95c0b7e96eb36bc3efc0c5beffbb9e84ea664e4/railties/lib/rails/commands/routes/routes_command.rb | |
require 'action_dispatch/routing/inspector' | |
unroutables = Rails.application.routes.routes. | |
map { |r| ActionDispatch::Routing::RouteWrapper.new(r) }. | |
reject { |r| r.internal? || r.engine? || r.path.starts_with?('/rails/') || !r.controller }. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(ggplot2) | |
library(ggirl) | |
# create the plot | |
plot <- ggplot() + | |
geom_polygon( data=map_data("state"), aes(x=long, y=lat, group=group), | |
fill="#cdddee", color="#7296bc" )+ | |
geom_point(data = data.frame(long = -77.01728, lat = 38.78125), | |
aes(x=long, y=lat), |
OlderNewer