Skip to content

Instantly share code, notes, and snippets.

@acook
acook / ubuntu_server_setup.bash
Last active December 20, 2015 20:48
Ubuntu server setup for Ruby, Nginx, and Node.js.
#!/usr/bin/env/bash
# run this like: `curl https://gist.github.com/acook/6192391/raw/ubuntu_server_setup.bash | bash`
echo "Enter the email address for this server's SSH key: "
read email
mkdir ~/.ssh
ssh-keygen -t rsa -C $email
echo "Enter password to install packages: "
@acook
acook / adding_methods_to_enumerable.rb
Last active December 20, 2015 21:29
So, it doesn't appear there's a clean way to add functionality to modules that are already loaded. This happens in 1.9.3 and 2.0.0.
module MyModule
def my_module_method
puts "BOOYAH!!"
end
end
Enumerable.send :include, MyModule
Enumerable.instance_methods.include? :my_module_method
#=> true
begin; require 'rubygems'; rescue LoadError; end
eng = defined?(RUBY_ENGINE) ? RUBY_ENGINE : 'ruby'
gems = defined?(Gem) ? Gem.default_dir : "/usr/lib/#{eng}/gems/#{ver}"
(RUBY_VERSION.split('.') +
[RUBY_PATCHLEVEL, RUBY_REVISION, eng, RUBY_PLATFORM]).
each_with_index { |v, i| puts "RUBY_VERINFO[#{i}]=#{v}" }
puts "GEM_ROOT=#{gems}"
@acook
acook / game.rb
Last active December 21, 2015 00:28
class Game
def initialize
@player = Player.new
@gui = GUI.new(self)
end
attr :player, :gui
class Player
attr_accessor :hit_points, :max_hit_points
@acook
acook / display_shell_indexing.sh
Created August 13, 2013 11:39
if it displays "0" then the shell is zero indexed, if it displays "1" then its 1-indexed
export INDEX=('1' '0')
echo ${INDEX[1]}
#!/usr/bin/env ruby
file = File.new("test.wav", "r")
puts "First position: #{file.pos}"
char = file.getc
puts "Got character: #{char}"
file.pos
@acook
acook / app.rb
Last active December 21, 2015 04:18
Serving up static files outside of Public with Sinatra. Good for putting static files behind your auth wall.
require 'pathname'
require 'sinatra/base'
module MyApp
module_function
def root
Pathname.new(__FILE__).dirname
end
end
@acook
acook / rvm_test.bash
Last active December 21, 2015 07:59
Programmatically install and use rubies/gemsets based on the files in the current directory.
rvm use --install --create .
text = "Give apple to Sam."
regex = /^Give (?<fruit>.+?) to (?<person>.+?)\.$/
matchdata = text.match regex
puts matchdata[:fruit] #=> apple
puts matchdata[:person] #=> Sam
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<!-- Generated by: TmTheme-Editor -->
<!-- ============================================ -->
<!-- app: http://tmtheme-editor.herokuapp.com -->
<!-- code: https://github.com/aziz/tmTheme-Editor -->
<plist version="1.0">
<dict>
<key>author</key>
<string>Anthony M. Cook</string>