Skip to content

Instantly share code, notes, and snippets.

module Sequel
module JDBC
module Oracle
class Dataset < JDBC::Dataset
# this, of course, brings the entire CLOB into memory (perhaps that is what we want)
def read_clob(clob)
# what about converting it to a Ruby IO object, as in:
# Java.java_to_ruby(org.jruby.RubyIO.new(JRuby.runtime, clob.getCharacterStream()).java_object)
reader = java.io.BufferedReader.new(clob.getCharacterStream())
@jacaetevha
jacaetevha / add_support_for_HTTP_OPTIONS.rb
Created August 26, 2009 16:13
Add support for the HTTP OPTIONS method to a Sinatra application.
# The HTTP OPTIONS method allows for cross-site HTTP requests.
# For more information see https://developer.mozilla.org/en/HTTP_access_control
# and, of course, the HTTP spec (section 9.2) at http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html
# In this example, we plan to use it in development mode only
configure :development do
# Open the Sinatra::Base class and add the method. We can't
# use 'options' as the method name because there is already
# an options method on the class.
class << Sinatra::Base
# this is the actual query, with pagination
Sequel::JDBC::Dataset.add_result( children, Classes.classes_for_parent(id.to_s).paginate(1, 20).sql )
# this is the count for the previous query, gets called due to pagination
Sequel::JDBC::Dataset.add_result( [{:count => 3}] )
@@ -121,6 +121,10 @@ module RestClient
display_log request_log
net.start do |http|
+ if payload.kind_of? File
+ req.body_stream = payload
+ payload = nil
+ end
res = http.request(req, payload) { |http_response| fetch_body(http_response) }
result = process_result(res)
db.system.js.findOne({_id: 'assetSizeBuckets'}).value(); // returns the following
[
{
"medium" : true,
"tsize" : 4186349249,
"count" : 114905,
"avg_size" : 36433.13388451329
},
{
"short" : true,
#!/bin/sh
# Fast User Switching from the command line
# I saved mine as /usr/local/bin/fus
CGSession='/System/Library/CoreServices/Menu Extras/User.menu/Contents/Resources/CGSession'
case "$#" in 0)
# display login screen
exec "$CGSession" -suspend exit ;;
esac
# No reason to display the login panel for the current user
require 'poi'
# given an Excel spreadsheet whose first sheet (Sheet 1) has this data:
# A B C D E
# 1 4 A 2010-01-04
# 2 3 B =DATE(YEAR($E$1), MONTH($E$1), A2)
# 3 2 C =DATE(YEAR($E$1), MONTH($E$1), A3)
# 4 1 D =DATE(YEAR($E$1), MONTH($E$1), A4)
workbook = POI::Workbook.open('spreadsheet.xlsx')
#!/bin/sh
#set -x
RUBY_DIR=$(dirname $(which ruby))/..
RUBY_DIR=`cd ${RUBY_DIR}; pwd`
RUBYGEMS_DIR="$RUBY_DIR/lib/ruby/gems/1.8/gems"
GEM_COLUMNIZE=$(ls -1d $RUBYGEMS_DIR/columnize*/lib | tr -d \\n)
GEM_RUBY_DEBUG_BASE=$(ls -1d $RUBYGEMS_DIR/ruby-debug-base-*/lib | tr -d \\n)
GEM_RUBY_DEBUG_CLI=$(ls -1d $RUBYGEMS_DIR/ruby-debug-*/cli | tr -d \\n)
GEM_SOURCES=$(ls -1d $RUBYGEMS_DIR/sources-*/lib | tr -d \\n)
%html
%head
%script{ :type => 'text/javascript', :src => 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.4/jquery.min.js' }
%script{ :type => 'text/javascript', :src => 'https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.9/jquery-ui.min.js' }
%script{ :type => 'text/javascript', :src => 'site.js' }
%body
%h2 HAML Example
%p
Some text here
%p#this_is_an_id
require 'benchmark'
n = 5_000_000
Benchmark.bm(15) do |x|
x.report("for loop:") { for i in 1..n; a = "1"; end }
x.report("times:") { n.times do ; a = "1"; end }
x.report("upto:") { 1.upto(n) do ; a = "1"; end }
end