Skip to content

Instantly share code, notes, and snippets.

require 'rubygame'
include Rubygame
include Rubygame::EventTriggers
# Factory method to create KeyReleaseTriggers easily.
def released( key )
return KeyReleaseTrigger.new( key )
end
@jacius
jacius / load_image.rb
Created June 21, 2009 06:34
A sample script to demonstrate Ruby-SDL-FFI (as of June 21, 2009)
#!/bin/env ruby
# A sample script to demonstrate Ruby-SDL-FFI (as of June 21, 2009).
# NOTE: Ruby-SDL-FFI API is still in flux.
require 'ruby-sdl-ffi'
path = ARGV[0]
if path.nil?
#!/bin/env ruby
# One way of making an object start and stop moving gradually:
# make user input affect acceleration, not velocity.
require "rubygame"
# Include these modules so we can type "Surface" instead of
@jacius
jacius / git-cherry-pick-range.sh
Created August 11, 2009 02:16
Cherry pick a range of git commits.
#!/bin/sh
#
# A very simple shell script to "cherry pick" a range of commits in Git.
# I might add more features later, like validation.
#
# Credit goes to Alex Riesen:
# http://www.nabble.com/cherry-pick---since---td10105685.html
#
# This script is released to the public domain. You can do whatever you want with it.
@jacius
jacius / smarttabs.el
Created September 18, 2009 09:13
Emacs smart tabs - indent with tabs, align with spaces!
;;
;; Emacs smart tabs functionality
;; Intelligently indent with tabs, align with spaces!
;;
;; Note: Indenting only uses tabs when indent-tabs-mode is non-nil,
;; otherwise it uses spaces as usual.
;;
;; To use: save as smarttabs.el in your .emacs.d directory, and add
;; "(require 'smarttabs)" to your .emacs file.
;;
@jacius
jacius / untar
Created October 5, 2009 20:34
untar: A simple shell script to untar a tarball.
#!/bin/bash
#
# A simple command to untar any tarball.
#
# For times when you don't care whether it was compressed
# with bzip2 or gzip, you just want to untar it already!
#
# Usage: untar [-v|--verbose] file
#
@jacius
jacius / about_ls_r.txt
Created December 20, 2009 23:25
ls_r: recursively list (and process) directories
Return a hash of directory contents, recursively.
Given a directory structure like this:
a/
|-- b.txt
`-- c/
|-- d.txt
`-- e/
@jacius
jacius / regexp_highlighting.rb
Created December 24, 2009 07:54
weird regexps
%r<this is a valid regexp>e.to_s
# That's right.
%r(this one is valid, but...()
it actually closes right here:)i.inspect
# Tricky.
%r[this is valid too]x.clone
# Correct.
#! /usr/bin/ruby
# Plot random pixels.
require 'rubygame'
include Rubygame
Width = 640
Height = 400
window.onload = ->
paper = Raphael 0, 0, 320, 200
circle = paper.circle 50, 40, 10
circle.attr "fill", "#f00"
circle.node.onclick = -> alert "Stop poking me!"
window.onkeypress = (ev) ->
ev = window.event || ev
switch ev.keyCode
when 37 then circle.attr( "cx", circle.attr("cx") - 5 )
when 38 then circle.attr( "cy", circle.attr("cy") - 5 )