Skip to content

Instantly share code, notes, and snippets.

View joshwlewis's full-sized avatar
⛷️

Josh W Lewis joshwlewis

⛷️
View GitHub Profile
@joshwlewis
joshwlewis / app.rb
Created March 3, 2014 20:22
Get request json for Sinatra
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 / application.rb
Last active August 29, 2015 13:56
Rack::Cors doesn't insert headers when Rails app errors out. Fix it by inserting Rack::Cors at the top of your middleware stack.
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 / wercker.yml
Created November 14, 2013 21:39
Wercker configuration for Ruby 2.0, Rails 4.0, Rspec, Postgres stack with deployment to Heroku and Hipchat notifications.
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 / user.rb
Created November 21, 2013 16:31
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.
class User < ActiveRecord::Base
devise :trackable
has_paper_trail
def update_tracked_fields!(request)
without_versioning { super(request) }
end
end

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 July 6, 2016 19:48
Hipchat emoticon data
[{"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 / scss_format_validator.rb
Created November 19, 2012 20:09
Rails validation for scss (or sass)
# 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
@joshwlewis
joshwlewis / do-not-press-down.sh
Created December 6, 2022 21:38
Falcon Player GPIO DO_NOT_PRESS Button Scripts
#!/bin/bash
# do-not-press-down.sh runs when the physical DO NOT PRESS button is depressed.
# This is designed to provide feedback as to whether or not the button release
# will activate a sequence. If the $PREFIX is not already playing, this runs
# an ok sound + effect. If $PREFIX is already playing (somebody is spamming
# the button), this runs an err sound + effect. Either way, the sound + effect
# will play in the background without interrupting anything already playing.
# For this reason, use short sounds and sequences with this script (under 1
# second).