Skip to content

Instantly share code, notes, and snippets.

@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
@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 / 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 / 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: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 / default.rb
Created April 20, 2012 23:43
resque cookbook
#
# Cookbook Name:: resque
# Recipe:: default
#
if ['solo', 'util'].include?(node[:instance_role])
execute "install resque gem" do
command "gem install resque redis redis-namespace yajl-ruby -r"
not_if { "gem list | grep resque" }
end
@cwise
cwise / resque.sh
Created January 8, 2012 17:53
Rewritten /engineyard/bin/resque
#!/bin/sh
#
# This script starts and stops the Resque daemon
# This script belongs in /engineyard/bin/resque
#
PATH=/bin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:$PATH
CURDIR=`pwd`
usage() {
@cwise
cwise / gist:1575082
Created January 7, 2012 15:46
EngineYard resque-web
require 'resque/server'
resque_constraint = lambda do |request|
request.env['warden'].authenticate? and request.env['warden'].user.admin? # or whatever manner your admin role can be determined
end
constraints resque_constraint do
mount Resque::Server.new, :at => "/resque"
end
@cwise
cwise / learning_basic_programming.md
Created December 31, 2011 21:28 — forked from edward/learning_basic_programming.md
Tech-ing Up: Learning basic programming

Tech-ing Up: Learning basic programming

Coming from http://www.reddit.com/r/canada/comments/m1494/looking_for_a_developer_advocate_for_shopify/ or elsewhere? Awesome.

This is a guide for learning the bare minimum needed for effectively working as a junior programmer or developer advocate at most software companies.

If you haven’t ever programmed before, don’t sweat it. Those who would be good fits at this job are naturally attuned to this stuff and their innate curiosity makes it a cakewalk. If you’re finding that it’s a frustrating experience the entire way through, then you should consider doing something else for a little while before you come back to give it another shot.

A first stab at programming

@cwise
cwise / gist:1353966
Created November 10, 2011 02:49
Ubuntu missing readline
You'll notice that readline is missing when attempting to run the console on Ubuntu.
sudo apt-get install install libreadline5-dev libncurses5-dev
rvm pkg install readline
cd $HOME/.rvm/src/ruby-1.9.2-p0/ext/readline
rvm remove 1.9.2
rvm install 1.9.2 --with-readline-dir=$rvm_path/usr