Skip to content

Instantly share code, notes, and snippets.

View adamhunter's full-sized avatar

Adam Hunter adamhunter

View GitHub Profile
(function($) {
// errors is an array of errors
// render :json => {:errors => @item.errors.full_messages}
function FormErrors(errors) {
var self = this,
error_count = errors.length;
this.html = function() {
var html = '';
html += '<div class="errorExplanation" id="errorExplanation">';
1) Add the function below into your .bash_profile, .bash_login, or other shell profile file.
2) Then you can hit nt (for new tab) anywhere
and a new tab will open up in same directory.
All credit for the idea and applescript goes to @jnunemaker - I just tidied it up.
If you can improve it further, let him know -- [email protected].

Poor Man's Deploy

  • Start a Sinatra server on port 4000
  • GET / to that server triggers a git pull and mod_rails restart
  • Hit port 4000 locally after pushing

Why?

init = Rails::Initializer.run do |config|
#...
end
# look for all existing loaded plugin's public/ directories
plugin_assets = init.loaded_plugins.map { |plugin| File.join(plugin.directory, 'public') }.reject { |dir| not (File.directory?(dir) and File.exist?(dir)) }
init.configuration.middleware.use MyApp::Rack::StaticOverlay, :roots => plugin_assets
1) Put terminal_clone_tab.sh somewhere in
your path and make sure it is executable
chmod u+x terminal_clone_tab.sh
2) Then add the following alias (~/.bash_profile or something)
alias nt='terminal_clone_tab.sh'
3) Then you can hit nt (for new tab) anywhere
and a new tab will open up in same directory.
If there is an easier way to do this, let me know [email protected].
# RSpec
require 'spec/expectations'
# Webrat
require 'webrat'
require 'test/unit/assertions'
World(Test::Unit::Assertions)
Webrat.configure do |config|
In response to all the responses to:
http://twitter.com/rtomayko/status/1155906157
You should never do this in a source file included with your library,
app, or tests:
require 'rubygems'
The system I use to manage my $LOAD_PATH is not your library/app/tests
@adamhunter
adamhunter / ruby-riak
Created February 19, 2010 14:34 — forked from bigfleet/ruby-riak
#!/bin/bash
# On OS X? Installed homebrew already? Interested in Riak? Get familiar!
# This command in your terminal should be a one-stop shop.
# curl http://gist.github.com/raw/308745/107168665a46decd540dd1c5d50ccdd82eb01051/ruby-riak | sh
brew install erlang wget
curl http://bitbucket.org/basho/riak/get/riak-0.8.tar.gz | tar zx
cd riak && make all rel
cd rel/riak && bin/riak start
wget http://bitbucket.org/basho/riak/raw/67c55dfd44f5/client_lib/jiak.rb
# If your workers are inactive for a long period of time, they'll lose
# their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is
# lost. Because, really. why not?
#
# Stick this in RAILS_ROOT/config/initializers/connection_fix.rb (or somewhere similar)
#
# From:
# http://coderrr.wordpress.com/2009/01/08/activerecord-threading-issues-and-resolutions/
# Config for Nginx to act as a front-end for Riak
# The main goal is to proxy all GETs directly to Riak, and disallow anything else (POST, PUT, etc)
# Also, disallow use of the map/reduce query links (i.e. /riak/bucket/key/_,_,_)
# Config is in /etc/nginx/sites-available/default or somewhere like that
# Set up load-balancing to send requests to all nodes in the Riak cluster
# Replace these IPs/ports with the locations of your Riak nodes
upstream riak_hosts {
server 127.0.0.1:8098;