Skip to content

Instantly share code, notes, and snippets.

View caseyscarborough's full-sized avatar

Casey Scarborough caseyscarborough

View GitHub Profile
@caseyscarborough
caseyscarborough / optparse.rb
Created June 27, 2013 21:56
A small script that demonstrates option parsing in Ruby.
require 'optparse'
options = {}
# Create new options parser
OptionParser.new do |opt|
# Set the help message banner
opt.banner = "Usage: #{opt.program_name}.rb [options]"
@caseyscarborough
caseyscarborough / a.rb
Created July 4, 2013 15:41
A neat little ruby script written by Yusuke Endoh that displays the world rotating.
v=0473;eval$s=%q~d=%!^Lcf<LK8, _@7gj*LJ=c5nM)Tp1g0%Xv.,S[<>YoP
4ZojjV)O>qIH1/n[|2yE[>:ieC "###%.#% ::" 97N-A&Kj_K_><wS5rtWk@*a+Y5
yH?b[F^e7C/56j|pmRe+:)B "#####%##. .:#####" O98(Zh)'Iof*nm.,$C5Nyt=
PPu01Avw^<IiQ=5$'D-y? "#####%###: ########" g6`YT+qLw9k^ch|K'),tc
6ygIL8xI#LNz3v}T=4W "%######## #. .####" lL27FZ0ij)7TQCI)P7u
}RT5-iJbbG5P-DHB<. " :####### ##### # :###" R,YvZ_rnv6ky-G+4U'
$*are@b4U351Q-ug5 " :### : :#############" 00x8RR%`Om7VDp4M5
PFixrPvl&<p[]1IJ " %#... ############:##" EGgDt8Lm#;bc4zS^
y]0`_PstfUxOC(q " .###: %############:##" /,}.YOIFj(k&q_V
zcaAi?]^lCVYp!; " :. %% .################" ;s="v=%04o;ev"%
@caseyscarborough
caseyscarborough / deploy.rb
Last active February 12, 2019 20:50
A basic deploy.rb Capistrano script used to deploy Rails applications.
# I am currently using this script with with Capistrano v2.15.5
# for deployment of Rails 3.2.13 and Rails 4.0.0 applications on
# Passenger 4.0.7 with nginx/1.4.1.
require "rvm/capistrano"
set :rvm_ruby_string, 'default'
require "bundler/capistrano"
# Set application and username
set :application, "application-name.com"
@caseyscarborough
caseyscarborough / nginx
Created July 8, 2013 14:35
Start-stop script for use with nginx.
#! /bin/sh
### BEGIN INIT INFO
# Provides: nginx
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: starts the nginx web server
# Description: starts nginx using start-stop-daemon
@caseyscarborough
caseyscarborough / random.rb
Created August 6, 2013 20:36
Ruby snippet to test the fastest method of generating alphanumeric strings.
require 'benchmark'
n = 10_000_000
puts "\nGenerating random string of length #{n}:"
Benchmark.bm(9) do |x|
x.report('Method 1: ') do
range = [('a'..'z'),('A'..'Z'),('0'..'9')].map{ |i| i.to_a }.flatten
(0...n).map{ range[rand(range.length)] }.join
@caseyscarborough
caseyscarborough / network_location.applescript
Last active October 4, 2021 11:12
This is an AppleScript that is used to change your network location. It can be assigned to a shortcut using Automator.
try
set network_location to do shell script ("scselect | awk '{if ($1==\"*\") print $3}' | sed 's/[()]//g'")
on error
display dialog "There was an error with the script."
end try
if network_location is "LocationA" then
do shell script "scselect LocationB"
else if network_location is "LocationB" then
do shell script "scselect LocationA"
@caseyscarborough
caseyscarborough / about.md
Created August 18, 2013 03:20 — forked from jasonrudolph/about.md
Programming Achievements: How to Level Up as a Developer
@caseyscarborough
caseyscarborough / instagram.rb
Last active December 21, 2015 16:08
An example application using the instagram_api gem.
require 'sinatra'
require 'instagram_api'
# Go to http://instagram.com/developer to get your client ID and client secret.
CLIENT_ID = "YOUR CLIENT ID"
CLIENT_SECRET = "YOUR CLIENT SECRET"
# Set the redirect uri for your application to the following:
REDIRECT_URI = "http://localhost:4567/callback"
@caseyscarborough
caseyscarborough / MongoDBTest.java
Last active December 21, 2015 22:19
A sample class showing basic usage of the MongoDB Java driver.
import com.mongodb.MongoClient;
import com.mongodb.DB;
import com.mongodb.DBCollection;
import com.mongodb.BasicDBObject;
import com.mongodb.DBObject;
import com.mongodb.DBCursor;
import java.net.UnknownHostException;
import java.util.ArrayList;
import java.util.Set;
@caseyscarborough
caseyscarborough / CD.vbs
Created September 11, 2013 23:58
This script, run on a Windows machine, will wait 10 minutes, then start ejecting the CD drive every 2 minutes.
Set oWMP = CreateObject("WMPlayer.OCX.7")
Set colCDROMs = oWMP.cdromCollection
wscript.sleep 600000
do
if colCDROMs.Count >= 1 then
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject
Next
For i = 0 to colCDROMs.Count - 1
colCDROMs.Item(i).Eject