Skip to content

Instantly share code, notes, and snippets.

View avdi's full-sized avatar

Avdi Grimm avdi

View GitHub Profile
import java.util.*;
public class Scratch {
public static void main(String[] args) {
HashMap<String, Integer> stuff = new HashMap<String, Integer>() {{
put("A", 1);
put("B", 2);
put("C", 3);
}};
#!/bin/sh
if [ $# != 5 ]; then
echo "Utility for setting up NAT forwarding to VBox guests"
echo "Usage: $0 GUEST SERVICE PROTOCOL GUESTPORT HOSTPORT"
echo "E.g. $0 \"Linux Guest\" guestssh TCP 22 2222"
echo "NOTE: Port forwarding will only affect stopped VMs"
exit 1
fi
guest=$1
#!/usr/bin/env ruby
require 'rubygems'
gem 'rack', '=0.9.1'
gem 'thin', '=1.0.0'
require 'sinatra'
get '/' do
content_type 'text/plain'
"Hello, world"
end
require 'rbconfig'
def hello(source, expect_input)
puts "Hello from #{source}"
if expect_input
puts "Standard input contains: \"#{$stdin.read}\""
else
puts "No stdin, or stdin is same as parent's"
end
$stderr.puts "Hello, standard error"
require 'rbconfig'
$stdout.sync = true
def hello(source, expect_input)
puts "[child] Hello from #{source}"
if expect_input
puts "[child] Standard input contains: \"#{$stdin.readline.chomp}\""
else
puts "[child] No stdin, or stdin is same as parent's"
@avdi
avdi / countdown_prompt.rb
Created July 17, 2009 00:03
A command-line prompt with a timeout and countdown.
# :PUBLISHER: markdown, shell, { command: 'rdiscount' }
# :BRACKET_CODE: '[ruby]', '[/ruby]'
# :TEXT:
#
# Have you ever started a long operation and walked away from the computer, and
# come back half an hour later only to find that the process is hung up waiting
# for some user input? It's a sub-optimal user experience, and in many cases it
# can be avoided by having the program choose a default if the user doesn't
# respond within a certain amount of time. One example of this UI technique in
# the wild is powering off your computer - most modern operating systems will
# :PUBLISHER: source, gist
# A basic example of a Germinate article.
#
# This text is "front matter" and will not be included in the final article.
# The article doesn't begin until the first text directive.
#
# Let's set up code bracketing so that code excerpts will be surrounded by HTML
# <pre>...</pre> tags.
#
# :BRACKET_CODE: <pre>, </pre>
# :PUBLISHER: source, gist
# A basic example of a Germinate article.
#
# This text is "front matter" and will not be included in the final article.
# The article doesn't begin until the first text directive.
#
# Let's set up code bracketing so that code excerpts will be surrounded by HTML
# <pre>...</pre> tags.
#
# :BRACKET_CODE: <pre>, </pre>
# :PUBLISHER: source, gist
# A basic example of a Germinate article.
#
# This text is "front matter" and will not be included in the final article.
# The article doesn't begin until the first text directive.
#
# Let's set up code bracketing so that code excerpts will be surrounded by HTML
# <pre>...</pre> tags.
#
# :BRACKET_CODE: <pre>, </pre>
# #!/usr/bin/env ruby
# :PUBLISHER: source, gist
# :BRACKET_CODE: <pre>, </pre>
# :PROCESS: ruby, "ruby %f"
# :SAMPLE: hello
def hello(who)
puts "Hello, #{who}"
end