Skip to content

Instantly share code, notes, and snippets.

# Hello, and welcome to makefile basics.
#
# You will learn why `make` is so great, and why, despite its "weird" syntax,
# it is actually a highly expressive, efficient, and powerful way to build
# programs.
#
# Once you're done here, go to
# http://www.gnu.org/software/make/manual/make.html
# to learn SOOOO much more.
# spec/support/database_cleaner.rb
#
# Set sane default for database cleaner and add a meta tag to enable database commits.
# This is important if you need to test after_commit callbacks in rails. (i.e. elasticsearch)
#
require 'database_cleaner'
RSpec.configure do |config|
config.before(:suite) do
DatabaseCleaner.strategy = :transaction
@dhoelzgen
dhoelzgen / base_controller.rb
Last active October 7, 2021 16:19
CORS in Rails 4 APIs
class API::V1::BaseController < ApplicationController
skip_before_filter :verify_authenticity_token
before_filter :cors_preflight_check
after_filter :cors_set_access_control_headers
def cors_set_access_control_headers
headers['Access-Control-Allow-Origin'] = '*'
headers['Access-Control-Allow-Methods'] = 'POST, GET, PUT, DELETE, OPTIONS'
#!/usr/bin/env bash
curl https://s3.amazonaws.com/heroku-jvm-buildpack-vi/vim-7.3.tar.gz --output vim.tar.gz
mkdir vim && tar xzvf vim.tar.gz -C vim
export PATH=$PATH:/app/vim/bin
@coldnebo
coldnebo / rails_trace.rb
Last active December 1, 2018 08:10
This Rack middleware for Rails3 lets you see a call-trace of the lines of ruby code in your application invoked during a single request. Only code within your app is considered (i.e. in the /app folder). This expands on my previous attempt (https://gist.github.com/3077744). Example of output in comments below.
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:
@brentd
brentd / parallel_asset_compiler.rb
Created July 31, 2012 23:11
Parallelize assets:precompile
require 'parallel' # gem install parallel (https://github.com/grosser/parallel)
# Monkey patch to Sprockets::StaticCompiler, a class provided by actionpack
# that's used by the assets:precompile task. This patch uses the Parallel gem
# to parallelize asset compilation in the simplest way possible.
#
# Parallel wraps Process.fork to handle things like inter-process communication
# via pipes and determining the maximum number of processes to run based on
# your system's total logical processors. So far only tested on MRI 1.9.3 on OS X.
module Sprockets
@lexmag
lexmag / article.rb_product.rb
Created July 28, 2012 15:12
Two-way polymorphic models / Polymorphic HABTM association
class Article < ActiveRecord::Base # Product class is similar
belongs_to :user
has_many :media, as: :ownable
with_options through: :media, source: :representable do |assn|
assn.has_many :videos, source_type: 'Video'
assn.has_many :images, source_type: 'Image'
end
end
@bbrowning
bbrowning / README.md
Created July 27, 2012 17:48
Diffs of the minimum changes required to convert a TB 2.0.3 config to work with TB 2.1.0

Below are the minimum changes required to get the underlying AS7 config file in TorqueBox 2.0.3 to work with TorqueBox 2.1.0. There's one diff for non-clustered environments (standalone.xml) and another for clustered environments (standalone-ha.xml).

If you are clustering without multicast, then you'll also need to add the attribute advertise='false' to the `` element in standalone-ha.xml in addition to the changes below.

# VERSIONING
# all production gems should use STRICT version dependencies ex: "1.0.0"
# development and test gems can you LOOSE version dependencies ex: "~> 1.0.0"
source 'http://rubygems.org'
# list gems for *all* environments/groups here
# ex: rails, mysql2, rails-console-tweaks
# list gems for frontend app servers here
@erikh
erikh / hack.sh
Created March 31, 2012 07:02 — forked from DAddYE/hack.sh
OSX For Hackers
#!/usr/bin/env sh
##
# This is script with usefull tips taken from:
# https://github.com/mathiasbynens/dotfiles/blob/master/.osx
#
# install it:
# curl -sL https://raw.github.com/gist/2108403/hack.sh | sh
#