Skip to content

Instantly share code, notes, and snippets.

Keybase proof

I hereby claim:

  • I am jtrim on github.
  • I am jessetrimble (https://keybase.io/jessetrimble) on keybase.
  • I have a public key whose fingerprint is F91C 3D5D 83BC 3B4B ED30 0A77 85F2 9CB2 647D 8801

To claim this, I am signing this object:

Function.prototype.call = function() { return "NO" }
====
!!!!
==========================
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
|| _____ _____ ||
|| | | | | | | ||
|| |-|-| |-|-| ||
|| ##### ##### ||
@jtrim
jtrim / mustache_if.rb
Created January 24, 2013 22:03
Possible way to express conditionals in dual purpose (rails + mustache) templates.
# The following is a possible way we can express conditionals in templates that
# are written to be rendered *both* by Rails and for the front-end in Mustache.
#
# ```haml
# - task.if 'assignee' do
# %label.subtle 'assigned to'
# = task.assignee_name
#
# - task.unless 'assignee' do
# %label.subtle 'not assigned'
@jtrim
jtrim / regex_validations.rb
Created December 7, 2012 22:58
Thorougly testing regex validations
# /app/models/foo.rb
class Foo < ActiveRecord::Base
validates_format_of :zip, with: /^[0-9]{5}$/, message: 'must be a valid 5-digit ZIP'
end
# /spec/models/foo_spec.rb
require 'spec_helper'
describe Foo do
describe 'validations' do
it { should_not allow_value("12345\n12345").for(:zip) }
@jtrim
jtrim / dasherize.coffee
Created November 28, 2012 18:54
Takes a string as the only argument and "dasherizes" it
# Dasherizes a string
#
# Usage:
#
# _.dasherize("Foo_Bar") #=> 'foo-bar'
# _.dasherize("FooBar") #=> 'foo-bar'
# _.dasherize("foo_bar") #=> 'foo-bar'
# _.dasherize("foo-bar_Baz") #=> 'foo-bar-baz'
#
dasherize: (string) ->
@jtrim
jtrim / gist:4042885
Created November 9, 2012 00:23
Make every page link to .html
class ApplicationController < ActionController::Base
# ...
def default_url_options
{ :format => :html }
end
end
#!/usr/bin/env ruby
image_data = IO.read('test.png')
pngquant_io = IO.popen('pngquant 16')
pngquant_io.write image_data
pngquant_io.close_write
processed_data = pngquant_io.read
@jtrim
jtrim / gem-docs-bookmarklet.html
Created July 2, 2012 18:05
Bookmarklet for opening rubydoc.info rubygem documentation.
<a href="javascript:window.open('http://rubydoc.info/gems/' + prompt('Gem name:') + '/frames');">Gem Docs</a>
@jtrim
jtrim / ugly-haml.rb
Created June 14, 2012 19:34
Haml ugly option
# config/initializers/haml.rb
Haml::Template.options[:ugly] = true