Skip to content

Instantly share code, notes, and snippets.

# create the template
template = PageOfflineTemplate.new
template.quote = quote
template.pages = quote.build_pages
# Here I render a template with layout to a string then a PDF
pdf = PDFKit.new template.render_to_string(:template=>"quotes/review.html.haml")
~/projects/jruby ➔ cat my_java_thing.rb
require 'java'
java_package 'foo.bar'
class SomeJavaThing
java_signature 'void main(String[] args)'
def self.main(args)
puts args.to_a
end
#! /bin/ruby1.8.7 -Ku
require 'socket'
require 'open-uri'
require 'time'
require 'json'
require 'base64'
def cut str, len=100
a = str.scan /./u
#
# A basic, synthetic benchmark of the impact HTTP client has
# on the speed of talking to ElasticSearch in the Tire gem.
#
# In general, Curb seems to be more then two times faster the RestClient, in some cases it's three
# to five times faster. I wonder if keep-alive has anything to do with it, but it probably does.
#
# Run me with:
# $ git clone git://github.com/karmi/tire.git
# $ cd tire
# encoding: utf-8
# code from: http://techtime.getharvest.com/blog/harvest-is-now-on-ruby-1-dot-9-3
# and also: https://gist.github.com/1976864
# Serialized columns in AR don't support UTF-8 well, so set the encoding on those
class ActiveRecord::Base
def unserialize_attribute_with_utf8(attr_name)
traverse = lambda do |object, block|
if object.kind_of?(Hash)
@elvuel
elvuel / .jrubyrc
Last active December 14, 2015 15:09 — forked from tychobrailleur/.jrubyrc
# Example of .jrubyrc
# Set compilation mode. JIT = at runtime; FORCE = before execution. (JIT, FORCE, OFF, OFFIR)
# compile.mode = FORCE
# Dump to console all bytecode generated at runtime.
# compile.dump = true
# Enable verbose JIT logging (reports failed compilation)
# jit.logging.verbose = true

Sass/Less Comparison

In this document I am using Sass's SCSS syntax. You can choose to use the indented syntax in sass, if you prefer it, it has no functional differences from the SCSS syntax.

For Less, I'm using the JavaScript version because this is what they suggest on the website. The ruby version may be different.

Variables

@elvuel
elvuel / gist:4315708
Created December 17, 2012 04:13 — forked from mttkay/gist:974084
# patch OAuth class to be able to create multipart requests (required for image uploading)
# NOTE that for my purpose I simply made it "auto-sensing" that an image is passed and
# only then creates a multipart body. You may simply want to use some flag instead or whatever.
module OAuth
class Consumer
alias_method :create_default_http_request, :create_http_request
protected
def create_http_request(http_method, path, *arguments)
# CHANGE THIS -- I only did this because it was for a quick-and-dirty script that had to upload pictures
@elvuel
elvuel / CXF_Spring_JRuby.rb
Created December 6, 2012 03:58 — forked from jcalvert/CXF_Spring_JRuby.rb
Ruby SOAP Performance
require 'java'
require './cxf-deps.jar'
require './client.jar'
require 'benchmark'
context = com.vetstreet.Context.instance
hello_dao = context.get_bean "helloDao"
Benchmark.bm do |x|
x.report do
t = []
1000.times do
@elvuel
elvuel / whitespace-a-like.rb
Created November 30, 2012 02:22 — forked from Dan-Q/whitespace-a-like.rb
Encode a Ruby program into a version composed almost entirely of unicode whitespace characters. Decodes itself on the fly.
#!/usr/bin/env ruby
# encoding: utf-8
CHARS = %w{                       ​ ‌ ‍    }
def encode(string)
string.chars.map{|c|"#{CHARS[c[0]/16]}#{CHARS[c[0]%16]}"}.join
end
program = <<-EOF