Skip to content

Instantly share code, notes, and snippets.

@ashbb
ashbb / layout_test.rb
Created April 7, 2012 07:16
A solution for Jason Scharf's problem.
Shoes.app title: "asset manager", width: 1000 do
flow do
background rgb(191, 209, 229)
stack do
para "TOC Asset Manager", stroke: blue, font: "helvetica", align: "center", size: 20
end
stack width: 100 do
caption "Encoders", font: "helvetica"
%w[EBU41 EBU42 EBU43 EBU48 EBU49 EBU52 EBU53 EBU54 NET27 NET28 NET29 NET30 EBU91 EBU95].each do |name|
@ashbb
ashbb / tetrishoes_green_and_purple.rb
Created April 5, 2012 11:58
tetriShoes for Green and Purple
# tetrishoes by lljk
# https://github.com/lljk/shoes-stuff/blob/master/tetrishoes.rb
#
# modified for Green & Purple Shoes by ashbb
class Array
def clear
_clear
end if method_defined? :_clear
end
@ashbb
ashbb / clipboard.rb
Created April 2, 2012 12:05
Clipboard test snippet to get/set text data in JRuby and SWT.
require 'java'
require 'swt'
module Swt
include_package 'org.eclipse.swt'
include_package 'org.eclipse.swt.widgets'
include_package 'org.eclipse.swt.dnd'
import java.awt.datatransfer.StringSelection
import java.awt.Toolkit
end
@ashbb
ashbb / breakout_commented_for_gs.rb
Created March 31, 2012 09:13
Breakout Game for Green Shoes
# a dumb little breakout game by lljk
# use the mouse or left and right keys to move the paddle
# space bar or left click to launch ball
# space bar while ball is moving to pause game
# First, we'll make widgets for the ball, bricks, paddle, and bonus stars
# Revised a little bit for Green and Purple Shoes by ashbb.
# This code works both with Green and Purple Shoes.
@ashbb
ashbb / thread_test_jruby_swt.rb
Created March 10, 2012 05:55
Why doesn't a red rectangle appear within Thread block?
require 'java'
require 'swt'
module Swt
include_package 'org.eclipse.swt'
include_package 'org.eclipse.swt.widgets'
include_package 'org.eclipse.swt.graphics'
end
class Object
@ashbb
ashbb / flicker_in_screen.rb
Created March 7, 2012 13:33
Flickering rectangle
require 'java'
require 'swt'
module Swt
include_package 'org.eclipse.swt'
include_package 'org.eclipse.swt.layout'
include_package 'org.eclipse.swt.widgets'
include_package 'org.eclipse.swt.graphics'
include_package 'org.eclipse.swt.events'
end
@ashbb
ashbb / shoes_url_sample.rb
Created February 17, 2012 12:23
A small sample snippet to use Shoes.url.
class PhotoFrame < Shoes
url '/', :index
url '/a', :a
url '/b', :b
url '/c', :c
def index
a
end
@ashbb
ashbb / console_test.rb
Created February 15, 2012 12:04
A sample snippet to use puts and gets on Green Shoes.
require 'green_shoes'
class ShoesIO < StringIO
def initialize app, stdout, *args
@app, @stdout = app, stdout
super *args
end
def gets
res = @app.ask @stdout.string.split("\n").last
@ashbb
ashbb / nachbar.rb
Created February 7, 2012 14:48
I got an email from Germany.
module Mod
def check_neighbour? a, b
return true if @circles.empty?
@circles.each{|c| return false if c.left/40 == a and c.top/40 == b}
@circles.each do |c|
x, y = c.left/40, c.top/40
return true if (x-1 == a and y == b) or (x == a and y-1 == b) or (x+1 == a and y == b) or (x == a and y+1 == b)
end
return false
end
@ashbb
ashbb / search_on_spotify.rb
Created January 14, 2012 08:54
Search an artist on spotify musicservice. Original code was written by Peter.
['green_shoes','meta-spotify'].each(&method(:require))
Shoes.app do
def artist_lookup artist
@slot.clear do
@e.text = artist.name
uri = artist.uri
songs = Array.new
chosen_artist = MetaSpotify::Artist.lookup(uri, :extras => 'albumdetail')
q, r = chosen_artist.albums.length.divmod 10