Skip to content

Instantly share code, notes, and snippets.

View simonbaird's full-sized avatar
💭
🤔

Simon Baird simonbaird

💭
🤔
View GitHub Profile
@simonbaird
simonbaird / tau.patch
Created June 16, 2011 15:51
Patch ruby to define tau
diff --git a/ext/bigdecimal/lib/bigdecimal/math.rb b/ext/bigdecimal/lib/bigdecimal/math.rb
index c17841f..c672cbf 100644
--- a/ext/bigdecimal/lib/bigdecimal/math.rb
+++ b/ext/bigdecimal/lib/bigdecimal/math.rb
@@ -9,6 +9,7 @@ require 'bigdecimal'
# atan(x, prec) Note: |x|<1, x=0.9999 may not converge.
# exp (x, prec)
# log (x, prec)
+# TAU (prec)
# PI (prec)
# See http://tauday.com/
module Math
TAU = PI * 2.0
end
if defined? BigMath
module BigMath
module_function
def TAU(prec)
@simonbaird
simonbaird / gist:1228368
Created September 20, 2011 04:59
html_safe gotcha
#
# This is pretty confusing until you know what's going on...
#
# See http://techspry.com/ruby_and_rails/html_safe-and-helpers-in-rails-3-mystery-solved/
# for an explanation...
#
ruby-1.8.7-p334 :025 > foo_safe = "<p>foo</p>".html_safe
=> "<p>foo</p>"
ruby-1.8.7-p334 :026 > (foo_safe + "<p>bar</p>").html_safe # not what you thought! unintuitive!
@simonbaird
simonbaird / use_helper_method.rb
Created October 3, 2011 00:15
Pick and choose helper methods to use in your controller actions
#
# If you want to use helper methods inside your controller's actions
# (even though it is arguably a code smell, ie you should push your
# presentation logic down into views rather than have it in your
# controllers), you can include the helper modules you want, for
# example:
#
# class ThingController < ActionController::Base
# include ApplicationHelper
# include ThingHelper
@simonbaird
simonbaird / example.erb
Created December 10, 2011 13:50
Embedded python?
<%#
#
# Embedded python?
#
# See:
# http://mail.python.org/pipermail/python-ideas/2011-December/013003.html
# http://readthedocs.org/docs/ncoghlan_devs-python-notes/en/latest/pep_ideas/suite_expr.html
# and related discussion:
# http://mail.python.org/pipermail/python-ideas/2011-December/thread.html#13003
#
@simonbaird
simonbaird / create_with_subtype.rb
Created February 8, 2012 02:27
Specify type when creating a record in AR STI
#
# This was causing problems when submitting the nested object form
# in a/v/product/channels_edit because all the nested channels would
# be created at plan Channel objects instead of the PrimaryChannel, EusChannel etc.
#
# In active record normally :type is ignored, eg:
# Channel.create(:type='PrimaryChannel', :etc=>1, ...)
# ignores the type attr and uses 'Channel'.
#
# This hack will make it actually use the :type value.
@simonbaird
simonbaird / styles.css
Created August 8, 2012 07:00
Make pinned tabs in Firefox a bit wider
@namespace url(http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul);
.tabbrowser-tab[pinned] {
width: 72px;
}
@simonbaird
simonbaird / block_render_helper.rb
Created August 8, 2012 08:02
block_render rails helper
#
# A trick so you can have partials that take blocks.
# Uses render :layout.
#
# Example:
# <%= block_render 'some_partial_with_a_yield', :foo => 123 do %>
# Any erb here...
# <% end %>
#
def block_render(partial_name, locals={})
@simonbaird
simonbaird / .gitconfig
Created October 31, 2012 02:22
Nice brief git logs
[core]
# -E means don't page if less one screen
# -F means quit when EOF reached
# -r fixes the %C(yellow)%+d colouring somehow
pager = less -E -F -r
[alias]
ll = log --pretty=nice -n 30 # about one screen worth
lll = log --pretty=nice # goes back forever
gsettings set org.gnome.desktop.input-sources xkb-options "['ctrl:nocaps']"