Skip to content

Instantly share code, notes, and snippets.

@ashbb
ashbb / PlayfairCipher.rb
Created July 29, 2013 12:24
Playfair Cipher
# Playfair Cipher
class PlayfairCipher
AZ = ('A'..'Z').to_a - ['J']
def initialize keyword
@square = keyword.upcase.gsub(/[^A-Z]/, '').gsub('J', 'I').split('').uniq
AZ.each{|x| @square.push x unless @square.include? x}
@square = 0.step(20, 5).collect{|x| @square.slice x,5}
@h = AZ.collect{|x| AZ.collect{|y| "'#{x+y}' => '#{convert x, y}'"}}.flatten.join ', '
@h = eval "{#{@h}}"
@rh = @h.invert
@ashbb
ashbb / ski_jumping.rb
Last active December 11, 2015 03:38
Shoes 4 Ski Jumping Game. Inspired by [Sebastjan's post](http://librelist.com/browser//shoes/2013/1/13/thank-you/) in Shoes ML. But, this is not a game, just a tiny example to learn Shoes 4. ;-)
class Skier
def initialize app
app.strokewidth 2
@x0, @y0 = 0, 20
@img1 = app.oval @x0 + 25, @y0 - 20, 5, 5
@img2 = app.line @x0 + 5, @y0, @x0 + 25, @y0 - 15
@img3 = app.line @x0 + 5, @y0 - 13, @x0 + 20, @y0 - 15
@img4 = app.line @x0, @y0, @x0 + 30, @y0
@img5 = app.line @x0, @y0, @x0 + 30, @y0 - 10
@img5.hide
@ashbb
ashbb / shoes_large_analog_clock.rb
Created August 2, 2012 11:42
Shoes Large Analog Clock written by Douglas Allen
# Shoes Large Analog Clock written by Douglas Allen
Shoes.app :width => 1024,
:height => 760,
:title => 'Welcome to Shoes' do
@radius = 600
@centerx = width / 2
@centery = height / 2
@msg = para ""#, margin: 4, align: 'center'
@ashbb
ashbb / roids_purple.rb
Created July 9, 2012 13:03
Roids for Purple Shoes
# Roids - Exploring Everyday Things with R and Ruby: Chapter 7 - Schooling Fish and Flocking Birds
# https://github.com/sausheong/everyday/blob/master/Chapter%207%20-%20Schooling%20Fish%20and%20Flocking%20Birds/roids.rb
#
# Edited a little bit for Purple Shoes
require 'matrix'
# Boids - http://www.red3d.com/cwr/boids/
FPS = 48
@ashbb
ashbb / 3buttons_on_slot1.rb
Created June 29, 2012 14:19
Have a trial of ShoesComposite and ShoesLayout for Shoes 4
require 'java'
require 'swt'
module Swt
include_package 'org.eclipse.swt.graphics'
include_package 'org.eclipse.swt.events'
module Widgets
import org.eclipse.swt.widgets.Layout
end
end
@ashbb
ashbb / stack_and_flow_layout.rb
Created June 12, 2012 11:54
Trying to create original StackLayout class and FlowLayout class for Shoes 4 inherited from Swt::Widgets::Layout class.
require 'java'
require 'swt'
module Swt::Widgets
import org.eclipse.swt.widgets.Layout
end
display = Swt::Widgets::Display.new
shell = Swt::Widgets::Shell.new display, Swt::SWT::SHELL_TRIM
shell.setLayout Swt::Layout::RowLayout.new
@ashbb
ashbb / text_game.rb
Created April 30, 2012 14:30
Text Game on Red Shoes
# This Text Game was written by Jared H.
# His original code is: https://gist.github.com/2500159
# and https://gist.github.com/2554879
#
# Slightly revised by ashbb for Red Shoes.
require_relative 'text_game_map'
require_relative 'text_game_helper'
Shoes.app title: "Guardians at the Threshold", width: 700, height: 700 do
@ashbb
ashbb / text_game_with_purple_shoes.rb
Created April 28, 2012 07:21
Text Game on Purple Shoes
# This Text Game was written by Jared H.
# Original code is: https://gist.github.com/2500159
class Map
attr_accessor :reincarnate, :jewel_hallway, :jewel_cavern, :jewel_stairway, :name, :i
def initialize
@reincarnate = false
@jewel_hallway = false
@jewel_cavern = false
@ashbb
ashbb / marble_solitaire_for_green_and_purple.rb
Created April 12, 2012 13:59
Marble Solitaire Game for Green and Purple Shoes
# little marble solitaire game
# by lljk
#
# revised for Green and Purple Shoes by ashbb
#
class SolitaireMarble < Shoes::Widget
attr_accessor :x, :y
def initialize(x, y)
@ashbb
ashbb / asteroids_for_green_and_purple.rb
Created April 11, 2012 11:54
Asteroids game for Green and Purple Shoes
# asteroids game by lljk
# have fun!
# revised for Green and Purple Shoes by ashbb
# But in this code, the ship doesn't rotate on Green Shoes
class Shoes::Widget
def move x, y
@ele.move x, y
end