Skip to content

Instantly share code, notes, and snippets.

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

Ken Johnson cktricky

🏠
Working from home
View GitHub Profile
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
X-UA-Compatible: IE=Edge
ETag: "6b4caf343a20865de174b2b530b945dd"
Cache-Control: max-age=0, private, must-revalidate
X-Request-Id: c3b0a57861087c0b827aab231747ef0c
X-Runtime: 0.051734
Connection: close
{"admin":false,"created_at":"2014-01-23T16:17:10Z","email":
@cktricky
cktricky / user_controller.rb
Created March 26, 2014 02:34
as_json index Railsgoat
def show
respond_with @user.as_json
end
<script type='text/javascript'>
jwplayer('my-video').setup({
primary: "flash",
sources: [
{file: <%= sanitize(@video.signed_html5.inspect) %>},
{file: <%= sanitize(@video.signed_flash.inspect) %>}
],
skin: 'someSkin',
flashplayer: <%= sanitize(asset_path('swf/jwplayer.flash.swf').inspect) %>,
# cf_url is http://dSomething.cloudfront.net/path
# video_name is test.mp4
def signed_html5
parsed_uri = URI.parse(cf_url)
url = "#{parsed_uri.scheme}://#{parsed_uri.host}#{parsed_uri.path}/#{video_name}"
signed_url = sign(url)
end
# cf_url is http://dSomething.cloudfront.net/path
# video_name is test.mp4
# AWS URL Signing Gem
gem 'aws_cf_signer'
@cktricky
cktricky / aws_signing.rb
Created March 4, 2014 22:33
AWS Cloudfront Signing Config File
# Add config/keys/pk-someRandomString.pem to your .gitignore file so...
# that it isn't stored in source code repos
key_file = Rails.root.join("config", "keys", "pk-someRandomString.pem")
SIGNER = AwsCfSigner.new(key_file)
@cktricky
cktricky / safe_request_handling.md
Last active January 2, 2016 15:59
Mass Assignment Part 2

##Web Application Code##

Within the request handling code:

_ = require('underscore');
var user = new User(_.pick(req.body, User.userCreateSafeFields));

Within the User model:

UserSchema.statics = {

@cktricky
cktricky / request_handling.md
Last active January 2, 2016 15:59
mass-assignment

##Client Request##

The following is a post request sent by a user during the registration process

POST /api/create_user HTTP/1.1
Accept: application/json
Content-Type: application/json;charset=UTF-8
Host: localhost
Connection: Keep-Alive

Accept-Encoding: gzip

@cktricky
cktricky / embed-gist.js
Last active February 5, 2023 11:26
Syntax highlighting for embedded gists
/*
To use this file, save it to a JS file and include it (<script src=) or
wrap it in <script type="text/javascript"> </script> tags on the page you are embedding the code on.
1) When you craft the script tag for including the gist assign it a class="embed-gist"
2) Give a file parameter, this is the name of the file, this is something absolutely necessary,
needs to be the first parameter (before lines)
cd /usr/share/tomcat7
sudo ln –s /var/lib/tomcat7/conf conf
sudo ln –s /etc/tomcat7/policy.d/03catalina.policy conf/catalina.policy
sudo ln –s /var/log/tomcat7 log
sudo chmod –R 777 /usr/share/tomcat7/conf