Skip to content

Instantly share code, notes, and snippets.

@sinisterchipmunk
sinisterchipmunk / line
Created April 18, 2011 09:57
Very simple script to display a specified line in a file, plus the line immediately preceding and following it. I whipped this up as a quick solution to manually following a particularly vague stack trace from Jax (github.com/sinisterchipmunk/jax).
#!/usr/bin/env ruby
def fail(msg)
puts msg
puts
exit
end
fail "Usage: line [filename] [lineno]" if !ARGV[0] || !ARGV[1] || !File.file?(ARGV[0])
@sinisterchipmunk
sinisterchipmunk / tree
Created April 18, 2011 10:05
I found myself having to construct a series of near-identical directory structures, and wanted a quick visualization of their contents. Was too lazy to open a file manager, and was happy for the excuse to code some Ruby. This was the result.
#!/usr/bin/env ruby
TAB_STOP = 2
$directories_only = false
$use_color = true
class Tree
attr_reader :word, :branches
@sinisterchipmunk
sinisterchipmunk / autotest.rb
Created May 23, 2011 15:04
Quick-and-dirty autotest without installing Autotest
#!/usr/bin/env ruby
class Autotester
MONITOR_MATCH_PATTERN = "**/*.rb"
TEST_COMMAND = "rspec spec"
def cache
@cache ||= {}
end
set :deploy_to, "public_html" # the remote path where the gem index lives
set :build_command, "bundle exec rake build" # the command to build the gem locally
set :user, "rubygems" # the user to log in to the server with
# the rubygems server to deploy to
server "gems.example.com", :app
desc "Deploy the gem and rebuild the index"
task :deploy do
build
@sinisterchipmunk
sinisterchipmunk / assets.rake
Created September 13, 2011 13:53 — forked from shedd/assets.rake
Check asset encoding for valid UTF-8; if not valid, show compatible encodings
namespace :assets do
task :check => :environment do
paths = ["app/assets", "lib/assets", "vendor/assets"]
paths.each do |path|
dir_path = Rails.root + path
if File.exists?(dir_path)
dir_files = File.join(dir_path, "**")
@sinisterchipmunk
sinisterchipmunk / LICENSE
Last active September 8, 2023 17:57
tar, gzip, and untar files using ruby in memory without tempfiles
Copyright (C) 2011 by Colin MacKenzie IV
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
@sinisterchipmunk
sinisterchipmunk / dungeon.js.coffee
Created November 27, 2011 00:17
example of dungeon model as of section 8.5 of the Jax guides: http://guides.jaxgl.com/getting_started.html#drawing-the-scene
parse = (str) ->
vec = str.split /,\s*/
return [ parseFloat(vec[0]), 0.0, parseFloat(vec[1]) ]
Jax.getGlobal()['Dungeon'] = Jax.Model.create
addTorches: (world) ->
if @map
for z in [0...@map.length]
row = @map[z]
for x in [0...row.length]
@sinisterchipmunk
sinisterchipmunk / dice.rb
Created January 16, 2012 01:33
Code examples for "Welcome to my world!" - http://localhost:3000/mist/posts/welcome-to-my-world
class Dice
def initialize(count, sides)
@count, @sides = count, sides
end
def roll
@count.times.inject(0) { |a,i| a + rand(sides) }
end
end
@sinisterchipmunk
sinisterchipmunk / Example 1
Created January 27, 2012 15:17
Code examples for "Understanding REST in Rails 3" - http://thoughtsincomputation.com/understanding-rest-in-rails-3
REST request | CRUD request | Action
----------------|----------------------|-------
POST /posts | /posts/create | Create
GET /posts/1 | /posts/show/colin | Read
PUT /posts/1 | /posts/update/colin | Update
DELETE /posts/1 | /posts/destroy/colin | Delete
@sinisterchipmunk
sinisterchipmunk / install_homebrew.rb
Created February 15, 2012 16:16 — forked from mxcl/install_homebrew.markdown
get the ruby shebang from env so you can use non-standard ruby paths
#!/usr/bin/env ruby
# This script installs to /usr/local only. To install elsewhere you can just
# untar https://github.com/mxcl/homebrew/tarball/master anywhere you like.
module Tty extend self
def blue; bold 34; end
def white; bold 39; end
def red; underline 31; end
def reset; escape 0; end
def bold n; escape "1;#{n}" end