Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Michael Hoitomt hoitomt

🏠
Working from home
View GitHub Profile
View conversation.rb
# 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],
@hoitomt
hoitomt / README.md
Created Jun 19, 2018
Run 2 instances of Redis on OSX
View README.md

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.
View API Best Practices Notes.md

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 / footspeed.md
Created Aug 4, 2016
Foot Quickness Drills
View footspeed.md

https://www.youtube.com/watch?v=bUBtG39Q7dw

  1. Fast Feet
  2. Wideouts
  3. Lateral line hops
  4. Vertical line hops
  5. 1 leg lateral line hops
  6. 1 leg vertical line hops
  7. Lateral shuffles - back and forth across a center section (he uses a weight)
  8. 4 cone agility drill
View Stack
Stack - [a, b, c, d]
Start:
node4 -> node3 -> node2 -> node1
Stack - no idea how many items are in it, only knows the top item
@data = node4
Next - Add a new node to the stack - "push"
push(value)
@hoitomt
hoitomt / habtm.md
Last active Aug 29, 2015
Create a has and belongs to many relationship in Rails 4.2
View habtm.md

This will create a parents table, a kids table and a relationship between the two tables.

  1. Create the Parents table

    bundle exec rails generate model parents fname:string lname:string
    
  2. Create the Kids table

    bundle exec rails generate model kids fname:string lname:string
    
@hoitomt
hoitomt / mysite.nginx.conf
Last active Aug 29, 2015
Nginx Configuration for Web Sockets
View mysite.nginx.conf
# Allows websocket connections on /websocket
upstream mysite {
server 127.0.0.1:3000;
}
map $http_upgrade $connection_upgrade {
default upgrade;
'' close;
}
@hoitomt
hoitomt / log_request.go
Created Jan 30, 2015
Golang: Log HTTP Requests in Go
View log_request.go
package main
import (
"fmt"
"log"
"net/http"
"os"
)
func main() {
View gist:9649943
var hash = window.location.hash;
var token = '0007zWwBHQBqmKj6KIDMo5HENldn9hwYpfq8EPhqkn';
var redirectUrl = 'https://reviews.local.apartmentguide.com/#' + token;
var url = 'https://primediaTest.okta.com/login/sessionCookieRedirect?token=' + token + '&redirectUrl=' + redirectUrl;
if(!hash.length) {
window.location.replace(url);
}