Skip to content

Instantly share code, notes, and snippets.

@RyanScottLewis
RyanScottLewis / gist:383882
Created April 29, 2010 16:58 — forked from burke/gist:383832
RuleBook benchmarks
require 'rubygems'
require 'benchmark'
require 'rulebook'
class Foo
[:admin, :blah].each do |role|
define_method "is_#{role}?" do
true
end
@RyanScottLewis
RyanScottLewis / Ruby
Created May 25, 2010 07:40
A way to make DSLs for Ruby
class DSL
def initialize(*args, &blk); call(*args, &blk); end
def call(*args, &blk); instance_exec(*args, &blk); end
end
class Klass
def foo
print 'foo'
DSL.new do
def bar
Needs two 7-segment displays and a target finder.
Wire the 1 [ENT] to the chips 'Player' link and the 7-segments accordingly
-----------------------------------------------------------------------------
@name Speedometer
@inputs Player:entity
@outputs A1 B1 C1 D1 E1 F1 G1 A2 B2 C2 D2 E2 F2 G2 Speed FirstNum SecondNum
class Foo
def subject(&blk)
if block_given?
blk.call(@subject) # How do I pass by reference and not by value here?
else
@subject
end
end
end
test 'An Array containing numbers' do
p subject #=> <Subject @name='' @object=nil>
subject 'An Array' do
subject ['one', 'two', 'three']
subject.pop
end
p subject #=> <Subject @name='An Array' @object=['one', 'two']>
end
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang='en-US' xml:lang='en-US' xmlns='http://www.w3.org/1999/xhtml'>
<head>
<title>Gridlock64</title>
<link href='reset.css' rel='stylesheet' type='text/css' />
<link href='style.css' rel='stylesheet' type='text/css' />
<meta content='mikey' name='description' />
<meta content='cars' name='keywords' />
</head>
#!/bin/bash
IFS="|"
#===---
(
echo "1"
testconnection=`wget --tries=3 --timeout=15 www.google.com -O /tmp/testinternet &>/dev/null 2>&1`
if [ $? != 0 ]; then
echo "#Internet Connection: Not connected"
#!/bin/bash
#===---
(
echo "1"
testconnection=`wget --tries=3 --timeout=15 www.google.com -O /tmp/testinternet &>/dev/null 2>&1`
if [ $? != 0 ]; then
echo "#Internet Connection: Not connected"
else
echo "#Internet Connection: Connected"
sudo -k
zenity --entry --hide-text \
--width=350 \
--title="Root Password" \
--text="Enter your root password:" | sudo -S -v
if [ "$?" != 0 ]; then
zenity --error --text="Sorry, bad password"
exit
fi
def token(size=6)
chars = ('0'..'9').to_a + ('a'..'z').to_a + ('A'..'Z').to_a
chars.sample(size).inject("") { |result, char| result << char }
end
p token # => "aN7drK"
p token # => "tVO3HG"
p token(8) # => "UqeYGPL2"
=begin