Skip to content

Instantly share code, notes, and snippets.

View codesoda's full-sized avatar

Chris Raethke codesoda

View GitHub Profile
@codesoda
codesoda / base.rb
Created September 28, 2015 23:03 — forked from bensie/base.rb
Sinatra API Helpers
require "sinatra/base"
require "sinatra/namespace"
require "multi_json"
require "api/authentication"
require "api/error_handling"
require "api/pagination"
module Api
class Base < ::Sinatra::Base
@codesoda
codesoda / rspec_model_testing_template.rb
Last active August 29, 2015 14:27 — forked from SabretWoW/rspec_model_testing_template.rb
Rails Rspec model testing skeleton & cheat sheet using rspec-rails, shoulda-matchers, shoulda-callbacks, and factory_girl_rails. Pretty much a brain dump of examples of what you can (should?) test in a model. Pick & choose what you like, and please let me know if there are any errors or new/changed features out there. Reddit comment thread: http…
# This is a skeleton for testing models including examples of validations, callbacks,
# scopes, instance & class methods, associations, and more.
# Pick and choose what you want, as all models don't NEED to be tested at this depth.
#
# I'm always eager to hear new tips & suggestions as I'm still new to testing,
# so if you have any, please share!
#
# @kyletcarlson
#
# This skeleton also assumes you're using the following gems:
@codesoda
codesoda / .rspec
Last active August 29, 2015 14:26
Sinatra Template
--color
--format Fuubar
--require spec_helper
@codesoda
codesoda / only_on.rb
Created December 1, 2014 18:07
Only On
# Run code only if it's a certain day of the week
# e.g.
# on(:monday) do
# puts "it's monday"
# end
module OnlyOn
def on(day, options = {})
yield if block_given? && day_of_week == day
end
@codesoda
codesoda / Requirements.md
Last active August 16, 2017 17:06
Tagging API

Generic Tagging JSON API

We will be building a Generic Tagging JSON API that can store, retrieve, delete and report on the usage of a "tag" across different entities. This is a guide for the endpoints, if you think you have a better route or would like to modify the naming/schema feel free. We like specs, so we hope you do to.

Create an Entry

POST /tag

- Entity Type, e.g. 'Product', 'Article'
@codesoda
codesoda / keybase.md
Created June 22, 2014 07:13
keybase.md

Keybase proof

I hereby claim:

  • I am codesoda on github.
  • I am codesoda (https://keybase.io/codesoda) on keybase.
  • I have a public key whose fingerprint is 853B 995C FFCE D1C2 5BEE 60C3 D37F 6671 2482 5F74

To claim this, I am signing this object:

@codesoda
codesoda / gist:ccd5f34a6ed1fd4c9a68
Created June 13, 2014 01:22
go away utf8 invalid byte sequence
# config/applications.rb
config.middleware.use "Utf8Sanitizer::Middleware"
# lib/utf8_sanitizer.rb
module Utf8Sanitizer
class Middleware
SANITIZE_ENV_KEYS = %w(
@codesoda
codesoda / heroku_database_restore.txt
Last active February 10, 2016 05:07
Restore Heroku Backups
$ heroku pg:backups capture -r REMOTE
$ heroku pg:backups public-url b001 -r REMOTE
$ pg_restore --verbose --clean --no-acl --no-owner -d DATABASE DUMP
@codesoda
codesoda / select_other.html
Created September 28, 2012 10:44
show/hide text box based on selected drop down
<!--
the select needs
- "has_other" css class
- "data-other" attribute, which points to the id of the element to hide/show (normally a textbox)
- "data-other-text" attribute, which indicates the text which indicates that other has been selected
-->
<select class="has_other" data-other="#textbox_id" data-other-text="...other">
<option>option 1</option>
<option>...other</option>
@codesoda
codesoda / time_for.rb
Created July 9, 2012 12:19
Time ruby code in the console
def time_for
started_at = Time.now
yield
elapsed = Time.now - started_at
end
# elapsed = time_for { 5 * i }
# otherwise Benchmark.measure { 5 * i }