This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Add to ~/.riplrc | |
module Ripl::MultiLineHistory | |
attr_reader :last_buffer | |
# hacks multi-line's loop_once | |
def loop_once |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ ruby sparql_client_example.rb | |
+--------------------------------------------------------------------+-------------------------------------------------+-------------------------------------+ | |
| s | p | o | | |
+--------------------------------------------------------------------+-------------------------------------------------+-------------------------------------+ | |
| http://dbpedia.org/resource/Elizabeth_Peabody__Teacher | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing | | |
| http://dbpedia.org/resource/Bonython_Hall | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing | | |
| http://dbpedia.org/resource/Zemfira | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://www.w3.org/2002/07/owl#Thing | | |
| http://dbpedia.org/resource/Myles_Ke |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
a = 10 ** 2 | |
a + 10 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$ boson dump_rdf http://datagraph.org/jhacker/foaf.nt | |
+------------------------------------+-------------------------------------------------+---------------------------------------------------+ | |
| subject | predicate | object | | |
+------------------------------------+-------------------------------------------------+---------------------------------------------------+ | |
| http://datagraph.org/jhacker/foaf | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://xmlns.com/foaf/0.1/PersonalProfileDocument | | |
| http://datagraph.org/jhacker/foaf | http://xmlns.com/foaf/0.1/maker | http://datagraph.org/jhacker/#self | | |
| http://datagraph.org/jhacker/foaf | http://xmlns.com/foaf/0.1/primaryTopic | http://datagraph.org/jhacker/#self | | |
| http://datagraph.org/jhacker/#self | http://www.w3.org/1999/02/22-rdf-syntax-ns#type | http://xmlns.com/foaf/0.1/Person |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GemspecBuilder builds a Gem::Specification object by looking up a gem's config in the config file ~/.gems.yml. | |
# GemspecBuilder assumes the current directory's basename is the gem name (unless told otherwise) and needs to be | |
# run inside the gem's root directory in order for the gemspec to build correctly. | |
# | |
# The builder merges the default gemspec hash in config[:default] with any gem-specific configuration in config[:gems][gem_name]. | |
# Gemspec hashes are assumed to have the same attribute-value pairs as Gem::Specification objects (described here: | |
# http://rubygems.rubyforge.org/rdoc/Gem/Specification.html). The only difference is the :files attribute which takes globbed expressions | |
# and is converted with Dir.glob. | |
# | |
# For an example config see mine: http://github.com/cldwalker/dotfiles/blob/master/.gems.yml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module MyCore | |
def self.config | |
{:force=>true} | |
end | |
# My overridden version that also handles arrays of hashes with :url | |
def browser(*urls) | |
urls.map! {|e| e[:url] } if urls[0].is_a?(Hash) and urls[0].has_key?(:url) | |
system('open', *urls) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# In example.rb | |
module Example | |
extend self | |
# This method does something | |
def command1(arg1, arg2, options = {}) | |
end | |
# This method does something else | |
def command2(arg1, arg2, options = {}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
module Chars | |
extend self | |
def scale(args, options={}) | |
scale = options[:scale] | |
chars = args.map { |x| Chars.char(x.to_i).map { |row| row.split("") } } | |
print_chars scale_vertically(scale_horizontally(chars, scale), scale) | |
end | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Customize description to include model class | |
class Hirb::Helpers::MyActiveRecordTable < Hirb::Helpers::AutoTable | |
def self.render(rows, options={}) | |
@model_class = rows.is_a?(Array) ? rows[0].class : rows.class | |
super | |
end | |
def self.model_class; @model_class; end | |
def render_table_description |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
['readline', 'rubygems', 'bond', File.dirname(__FILE__) + '/../config/boot'].each {|e| require e } | |
Bond.start | |
["#{RAILS_ROOT}/config/environment", 'console_app', 'console_with_helpers'].each {|e| require e} | |
history_file = File.join(ENV["HOME"], '.myrb_history') | |
IO.readlines(history_file).each {|e| Readline::HISTORY << e.chomp } if File.exists?(history_file) | |
while (input = Readline.readline('>> ', true)) != 'exit' | |
begin puts "=> #{eval(input).inspect}"; rescue Exception; puts "Error: #{$!}" end | |
end | |
File.open(history_file, 'w') {|f| f.write Readline::HISTORY.to_a.join("\n") } |