Skip to content

Instantly share code, notes, and snippets.

View ccashwell's full-sized avatar
🤔
¯\_(ツ)_/¯

Chris Cashwell ccashwell

🤔
¯\_(ツ)_/¯
View GitHub Profile
@ccashwell
ccashwell / restrict_by_request_type.rb
Last active November 29, 2018 22:32
CanCan Authorization: Restrict resources by request format JSON
# Lock down controller actions with CanCan based on request format.
class Ability
include CanCan::Ability
def initialize(user, format=nil)
user ||= User.new
can :index, Model if format == "application/json"
end
end
@ccashwell
ccashwell / github_ssh.sh
Created November 8, 2012 22:29
Bash Scripting: OAUTH2 Authorization, Generating SSH keys and Adding Keys to GitHub
#!/bin/bash
# This is an example of OAUTH2 authorization via GitHub and adding a new (optionally generated) SSH key to your account.
# If generated, the key is put in the default location with no password. Security is obviously relaxed for brevity's sake. Enjoy.
read -p "GitHub Username: " uname
read -s -p "GitHub Password: " passwd
if [[ "$uname" == "" || "$passwd" == "" ]]; then
echo -e "\n\nCan't set up your GitHub SSH keys without authorization. You're on your own now, champ."
exit 1
fi