Skip to content

Instantly share code, notes, and snippets.

@rskelley9
rskelley9 / whats_my_os.sh
Created October 1, 2017 05:40
Reveals type of operating system shell is running in a simple format useful for logic in other scripts.
#!/bin/sh
case "$(uname -s)" in
Linux*) sys=Linux;;
Darwin*) sys=Mac;;
CYGWIN*) sys=Cygwin;;
MINGW*) sys=MinGw;;
*) sys="UNKNOWN:$(uname -s)"
esac
echo ${sys}
@rskelley9
rskelley9 / rm_ds_store.sh
Created October 1, 2017 05:14
I created this script to remove the hidden .DS_Store file from my projects and automatically initialize and update my .gitignore file to keep it untracked.
#!/bin/sh
if [ -f "`find . -name .DS_Store`" ] ; then
if [ ! -f "`git rev-parse --is-inside-work-tree`" ] ; then
echo "no git repository found"
while true; do
read -p "Do you wish to initialize git repository in this folder $(echo $(pwd))?" yn
case $yn in
@rskelley9
rskelley9 / sql_injection_examples.rb
Created March 21, 2017 05:11
Some Examples of SQL Injection in Rails
params = {}
## Using string interpolation in where clauses is always dangerous
## BAD (Strings unescaped)
params[:firstname] = "'cat' OR lastname='Kelley'"
User.find(:first, conditions: "firstname = #{params[:firstname]}")
#=> AR Relation matching conditions
## GOOD (Escaped/Parameterized via Hash or Array)
User.find(:first, conditions: {firstname: params[:firstname]})
@rskelley9
rskelley9 / application_controller.rb
Last active October 31, 2016 05:02
How I remedied duplicate form submissions via preventing cache, and preventing duplicate data save in database in controller layer.
class ApplicationController < ActionController::Base
prepend_before_filter :authenticate_user!
private
## Tell client not to cache the response
def client_will_not_cache_response
response.headers["Cache-Control”] = “no-cache, no-store”
response.headers[“Pragma”] = “no-cache”
response.headers[“Expires”] = “Fri, 01 Jan 1990 00:00:00 GMT”
end
@rskelley9
rskelley9 / application_controller.rb
Last active October 31, 2016 05:43
How I remedied duplicate form submissions: https://www.tumblr.com/blog/ryankelley
class ApplicationController < ActionController::Base …
private
def client_will_not_cache_response
response.headers["Cache-Control”] = “no-cache, no-store”
response.headers[“Pragma”] = “no-cache”
response.headers[“Expires”] = “Fri, 01 Jan 1990 00:00:00 GMT”
end
end
@rskelley9
rskelley9 / scanner.sh
Created December 22, 2015 07:37
Scan for other computers on LAN
echo -e "\nScan LAN for other computers.\n"
if [ -n ""$@"" ]; then
ip=$(/sbin/ifconfig $1 | grep 'inet ' | awk '{ print $2}' | cut -d"." -f1,2,3 )
nmap -sP $ip.1-255
else
echo "Enter Interface parameter ex:"
echo -e "\t./scannetwork.sh $(ifconfig -lu | awk '{print $2}')\n"
echo "Available interfaces: "
for i in $(ifconfig -lu)
@rskelley9
rskelley9 / commands.md
Created December 16, 2015 05:20
Some useful net related aliases from my zshrc.

Aliases

# Get local computer IP address for LAN network
alias myip="ifconfig | sed -En 's/127.0.0.1//;s/.*inet (addr:)?(([0-9]*\.){3}[0-9]*).*/\2/p'"

# Public facing ip
alias myippub='wget -qO- icanhazip.com'

# Get mac address for en0
@rskelley9
rskelley9 / callapi.sh
Last active August 3, 2017 16:31
Shell script for calling api
if ! type "$brew" > /dev/null; then
echo "homebrew is not installed, please install homebrew"
else
if ! type "$curl" > /dev/null; then
echo "curl is not installed, please install homebrew"
else
if ! type "$jq" > /dev/null; then
echo "jq is not installed, please install homebrew"
else
if [ -z "$2" ]; then
@rskelley9
rskelley9 / command.txt
Last active November 8, 2015 07:47
Count the Number of Hosts on Your LAN
List the hosts on your LAN, their MAC addresses and IP's and then count them:
```
$ arp -an | tee >(wc -l)
```
@rskelley9
rskelley9 / how_to.md
Last active December 29, 2024 17:32
Workaround: Connect your Chromecast to a Hotel Wireless Network

About

I recently relocated for new employment. I've been staying in an extended stay hotel for about 3 weeks now. The hotel I'm staying in gives its guests free Wifi access. However, it requires users to accept terms and conditions on a splash page via browser interface before they can use the network. This makes it difficult to use my Chromecast with the network, as it doesn't have a means of accessing that splash page. While I could call the IT help line, I decided to explore a work-around.

Like many networks, my hotel's network attempts to improve security by using MAC address filtering. Luckily, Mac OS X (10.4 - 10.10) makes it very easy to spoof your network card's MAC address.

Here's how to add a devices like Chromecast, AppleTV, Roku to a wireless network that requires a browser to authenticate and accept terms and conditions.

Before You Start