Skip to content

Instantly share code, notes, and snippets.

@cwise
cwise / gist:2890831
Created June 7, 2012 19:00
Calling a server method to calculate something via Ajax...
Imaging you have a form that represents a Wall.
<%= content_tag :h2, t(:wall).capitalize %>
<%= simple_form_for @wall do |f| %>
<%= f.hidden_field :current_units %>
<%= f.input :direction, :as => :select, :collection => @directions, :value_method => :code, :label_method => label_method, :include_blank => false %>
<%= field_set_tag t(:construction).capitalize do %>
<%= f.input :wall_type, :as => :select, :collection => @wall_types, :value_method => :code, :label_method => label_method, :include_blank => false, :input_html => {:class => 'initial_field'} %>
<%= f.input :lintel_type, :as => :select, :collection => @lintel_types, :value_method => :code, :label_method => label_method, :include_blank => false %>
<%= f.input :corners, :input_html => {:size => 10, :class => 'number_field'} %>
@cwise
cwise / gist:5320439
Created April 5, 2013 15:56
Update DNSimple with DynamicD
#!/bin/bash
LOGIN="<your DNSimple login here>"
TOKEN="<your API token here>"
DOMAIN_ID="<your domain id here - use /domains to find it>"
RECORD_ID="<your record id here - use /domains/:domain_id/records to find it>"
IP="`curl http://icanhazip.com/`"
curl -H "Accept: application/json" \
-H "X-DNSimple-Token: $LOGIN:$TOKEN" \
@cwise
cwise / gist:7499661
Created November 16, 2013 12:35
Stack level too deep?
# put this in application.rb before your app is initialized
module Kernel
def require_and_print(string)
puts string
require_original(string)
end
alias_method :require_original, :require
alias_method :require, :require_and_print
end
@cwise
cwise / signature
Created February 4, 2014 20:29
signature
<style type="text/css">
a.link{margin:0;padding:0;border:none;text-decoration:none;}
</style>
<br />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="format-detection" content="telephone=no">
<table width='320' id="sig" cellspacing='0' cellpadding='0' border-spacing='0' style="width:320px;margin:0;padding:0;">
<tr>
@cwise
cwise / delete-broken-images
Created March 24, 2015 02:13
Delete broken images
images = Spree::Image.all.reject do |image|
begin
open image.attachment.url
putc '.'
true
rescue
puts image.attachment.url
false
end
end