Skip to content

Instantly share code, notes, and snippets.

View hoitomt's full-sized avatar
🏠
Working from home

Michael Hoitomt hoitomt

🏠
Working from home
View GitHub Profile
@hoitomt
hoitomt / API Best Practices Notes.md
Created June 5, 2017 15:26
API Best Practices Notes

Source: http://www.vinaysahni.com/best-practices-for-a-pragmatic-restful-api

  • Use SSL
  • Do not redirect from non-SSL to SSL (encourages clients to keep doing it)
  • Version in the URL (At least major)
  • Unary attribute (+/-) in sort params to indicate direction of sort
  • Provide way for user to specify return fields
  • snake_case is easier to read (Even though it is not the standard way to define variables in Javascript: CamelCase)
  • pretty print by default (responses are slightly larger). Over-arching concept is that an API should also be human-readable
  • Support .gz compression, if not default to it. Much faster API
@hoitomt
hoitomt / README.md
Created June 19, 2018 17:58
Run 2 instances of Redis on OSX

OSX: Run two instances of Redis

Copy and update redis.conf

The redis configuration file is likely located at /usr/local/etc/redis.conf

cp /usr/local/etc/redis.conf /usr/local/etc/redis2.conf

Change the port number from 6379 to something else. I used 6380

Accept connections on the specified port, default is 6379.

@hoitomt
hoitomt / conversation.rb
Last active July 9, 2018 16:17
Conversation
# Retrieve the user
user = User.find(params[:user_id])
# Get all of the messages for the user and order so that the most recent message is first
raw_messages = Message.where("sender_user_id=? or receiver_user_id=?", user.id, user.id).order("created_at DESC")
# Our goal is to make a hash that looks like this:
# {
# other_party_1: [msg1, msg2, msg3],
# other_party_2: [msg7, msg8, msg9],