Skip to content

Instantly share code, notes, and snippets.

View iamwilhelm's full-sized avatar

Wil Chung iamwilhelm

  • Mountain View, CA
View GitHub Profile
When you want to tail a rails log, but without the extraneous stuff, you can simply do:
tail -f log/production.log | grep "[/#]"
It will show the first and last lines of each request, plus any error stack trace.
@iamwilhelm
iamwilhelm / gist:120523
Created May 30, 2009 14:56
how to get all the attributes names of records in couchdb
/* this mapreduce pair returns all the keys of the attribute hash from all records in the system */
/* the map function to return all the values of keys */
function(doc) {
keys = {}
for(key in doc) {
if (key != "_id" && key != "_rev") {
keys[key] = 1
}
}
alias arc="pushd /Library/Arc3/;mzscheme -m -f as.scm; popd"
class SomeMailer < ActionMailer::Base
# assumes that there's a file named pretty_template.html.erb in app/views/some_mailer
def html_email_with_attachment(email_address, msg)
recipients [email_address]
from "hello@world.com"
subject "This is an html email with an attachment"
# have to set content_type explicitly
content_type "multipart/alternative"
<ul>
<% if @messages.empty? %>
There are no messages
<% else %>
<% @messages.each do |m| %>
<li><%= m.body %></li>
<% end %>
</ul>
<ul>
<% if @messages.each do |m| %>
<li><%= m.body %></li>
<% end.empty? %>
<li>There are no messages</li>
<% end %>
</ul>
def index
render :update do |page|
page.inner_html(params["target"], "Hello world!")
page.effect(:highlight, params["target"])
# and other page effects
end
end
<h1><%= @article.title %></h1>
<p>
<%= @article.body %>
</p>
<p id="comments_list" style="display: none">
</p>
<span id="comments_indicator" style="display: none">
<%= image_tag "indicator.gif" %>
</span>
<%= link_to_remote "show all comments",
$(document).ready(function() {
$("a.get").click(
function() {
url = $(this).attr("data-href");
target = $(this).attr("data-target");
$(target).html("Loading...");
$.get(url, function(data) {
$(target).html(data);
});
});