Skip to content

Instantly share code, notes, and snippets.

Avatar

Josh W Lewis joshwlewis

View GitHub Profile
View keybase.md

Keybase proof

I hereby claim:

  • I am joshwlewis on github.
  • I am joshwlewis (https://keybase.io/joshwlewis) on keybase.
  • I have a public key ASAIpXAvWMfvfbCFhOn4NjLXG4OuKRPcXPHb79teCBqhLQo

To claim this, I am signing this object:

@joshwlewis
joshwlewis / hipcat_emoticons.json
Last active Jul 6, 2016
Hipchat emoticon data
View hipcat_emoticons.json
[{"name":"allthethings","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/allthethings-1414024836.png"},{"name":"android","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/android-1414024011.png"},{"name":"areyoukiddingme","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/areyoukiddingme-1414024355.png"},{"name":"arrington","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/arrington-1414023805.png"},{"name":"arya","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/arya-1414028821.png"},{"name":"ashton","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/ashton-1414025136.png"},{"name":"atlassian","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/atlassian-1414025304.png"},{"name":"awesome","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/awesome-1417754492.png"},{"name":"awthanks","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/awthanks-1414025485.png"},{"name":"aww","url":"https://dujrsrsgsd3nh.cloudfront.net/img/emoticons/aww-1417754503
@joshwlewis
joshwlewis / application.rb
Last active Aug 29, 2015
Rack::Cors doesn't insert headers when Rails app errors out. Fix it by inserting Rack::Cors at the top of your middleware stack.
View application.rb
config.middleware.insert 0, Rack::Cors do
allow do
origins(/^https:\/\/app.client.com$/)
resource '*',
headers: :any,
methods: [:get, :put, :post, :delete]
end
end
@joshwlewis
joshwlewis / app.rb
Created Mar 3, 2014
Get request json for Sinatra
View app.rb
class App < Sinatra::Base
helpers do
def request_json
request.body.rewind
::JSON.parse(request.body.read)
end
end
put '/foobar' do
@data = request_json
@joshwlewis
joshwlewis / user.rb
Created Nov 21, 2013
When using paper_trail and devise, new user versions are saved on each request. The following prevents saving new user versions when devise trackable columns (sign_in_count, current_sign_in_at, last_sign_in_at, current_sign_in_ip, last_sign_in_ip) are updated.
View user.rb
class User < ActiveRecord::Base
devise :trackable
has_paper_trail
def update_tracked_fields!(request)
without_versioning { super(request) }
end
end
@joshwlewis
joshwlewis / wercker.yml
Created Nov 14, 2013
Wercker configuration for Ruby 2.0, Rails 4.0, Rspec, Postgres stack with deployment to Heroku and Hipchat notifications.
View wercker.yml
box: wercker/ubuntu12.04-ruby2.0.0
services:
- wercker/postgresql
build:
steps:
- bundle-install
- rails-database-yml
- script:
name: db:setup
code: bundle exec rake db:setup
@joshwlewis
joshwlewis / scss_format_validator.rb
Created Nov 19, 2012
Rails validation for scss (or sass)
View scss_format_validator.rb
# app/validators/scss_format_validator.rb
class ScssFormatValidator < ActiveModel::EachValidator
def validate_each(object, attribute, value)
begin
# Attempt to parse SCSS
Sass::Engine.new(value, syntax: :scss).render
rescue Exception => e
# Add error if parsing fails
object.errors.add(attribute, :invalid_scss, error: e.inspect)
end
You can’t perform that action at this time.