Skip to content

Instantly share code, notes, and snippets.

@jch
jch / .gemrc
Created November 1, 2011 19:10
gemrc example
# http://docs.rubygems.org/read/chapter/11
---
gem: --no-ri --no-rdoc
benchmark: false
verbose: true
update_sources: true
sources:
- http://gems.rubyforge.org/
- http://rubygems.org/
backtrace: true
@jch
jch / rabbitmq-install-osx.md
Created April 28, 2012 23:48
Troubleshooting RabbitMQ installation on OSX via homebrew

Troubleshooting RabbitMQ installation on OSX via homebrew

brew update
brew install rabbitmq

To see if rabbitmq is running after following the installation instructions:

launchctl list | grep rabbit
> 48303	-	homebrew.mxcl.rabbitmq
@jch
jch / slideshow_controller.js
Created March 23, 2023 20:56
Stimulus slideshow controller, because I'm too stupid to do modulo math
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
static targets = [ "slide" ]
initialize() {
this.index = 1
}
next(e) {

Installation

1)

brew install nginx
sudo cp /usr/local/Cellar/nginx/1.8.0/homebrew.mxcl.nginx.plist /Library/LaunchDaemons

2)

Replace /usr/local/etc/nginx/nginx.conf with the nginx.conf in this gist. I'm using port 8888 for my current project. Obviously, change server_name as well, and probably the name of its access log.

/* **She grows old and feeble** */
//...But she would always have to return back to her dull world of chores and grown-ups.
return function() {
// And her latest story would be filled with wonder
latestStory = adventures[adventures.length - 1];
// But time is a bitch...
setInterval(function() {
// and our dear princess can't help but forget her adventures,

Rendering Deferred Views Outside of Rails Controllers

Typically, Rails views are rendered after some controller action is executed. But the code that powers Rails controllers are flexible and extensible enough to create custom rendering objects that can reuse views and helpers, but live outside of web request processing. In this post, I'll cover what a Rails controller is and what it's composed of. I'll also go over how to extend it to create your own customer renderers, and show an example of how you can render views in your background jobs and push the results to your frontend.

What's a Controller?

A Rails controller is a subclass of ActionController::Base. The documentation says:

Action Controllers are the core of a web request in Rails. They are made up of one or more actions that are executed on request and then either render a template or redirect to another action. An action is defined as a public method on the controller, wh

@jch
jch / rack_boot.rb
Created April 30, 2012 05:16
Programmatically start a rack app
require 'rack'
class RackApp
def self.call(env)
[200, {'Content-Type' => 'text/html'}, ['derp']]
end
end
# For a full list of options, see
# http://www.ruby-doc.org/stdlib-1.9.3/libdoc/webrick/rdoc/WEBrick.html
@jch
jch / yard-mount.rb
Created July 2, 2012 18:17
mount yard documentation at /docs
# 1) Running a raw RackAdapter in config.ru mounted at '/' works fine
require 'bundler/setup'
require 'yard'
run YARD::Server::RackAdapter.new(
{'surfiki' => [YARD::Server::LibraryVersion.new('surfiki', nil, File.expand_path('../.yardoc', __FILE__))]},
{
:single_library => true,
:caching => false
})
@jch
jch / mint.rb
Created December 29, 2016 17:38
# Clean up Mint exported transactions for working with a spreadsheet
#
# Usage:
#
# ruby mint.rb <transactions.csv>
#
# Export a CSV of transactions from Mint
#
# Tags are not exported, so it must be filtered out before export:
#
Last login: Tue Aug 23 13:16:58 on ttys003
jch@Jerrys-MacBook-Pro:~$ cd projects/ruby-net-ldap/
jch@Jerrys-MacBook-Pro:~/projects/ruby-net-ldap[tls-verify-hostnames]$ cd test/support/vm/openldap
jch@Jerrys-MacBook-Pro:~/projects/ruby-net-ldap/test/support/vm/openldap[tls-verify-hostnames]$ vagrant destroy
==> default: VM not created. Moving on...
jch@Jerrys-MacBook-Pro:~/projects/ruby-net-ldap/test/support/vm/openldap[tls-verify-hostnames]$ gem uninstall vagrant
jch@Jerrys-MacBook-Pro:~/projects/ruby-net-ldap/test/support/vm/openldap[tls-verify-hostnames]$ rbenv rehash
jch@Jerrys-MacBook-Pro:~/projects/ruby-net-ldap/test/support/vm/openldap[tls-verify-hostnames]$ hash -r
jch@Jerrys-MacBook-Pro:~/projects/ruby-net-ldap/test/support/vm/openldap[tls-verify-hostnames]$ vagrant plugin install vagrant-vbguest
Installing the 'vagrant-vbguest' plugin. This can take a few minutes...