Skip to content

Instantly share code, notes, and snippets.

@cthornton
cthornton / jwt_creation_1.rb
Created July 3, 2014 03:33
Sample JTW Creation
auth_header = JWT.encode({
user_id: 123,
iat: Time.now.to_i, # Specify the time the token was issued
exp: Time.now.to_i + 2 # Expire the token in 2 seconds
}, "<my shared secret>")
RestClient.get("http://api.example.com/", authorization: auth_header)
@cthornton
cthornton / new-user.sh
Created May 20, 2014 03:51
Create new user
# Make new user on a new system
useradd --create-home --shell /bin/bash \
--groups sudo \
christopher
@cthornton
cthornton / exposed_variables.rb
Created April 1, 2014 16:44
Exposed Variables
# Creates an interface to safely expose internal methods and variables to be used by some sort of templating system.
#
# Say for example, we want to send users an email when they register, and we want companies to be able to modify how
# the messages appear to their end users. One solution is to allow evaling in the email templates:
#
# ```
# Hello #{@user.fullname}! Welcome to the application! ...
# ```
#
# This is clearly a security risk as it allows users to enter malicious code. Another solution can be to just gsub