Skip to content

Instantly share code, notes, and snippets.

@thbar
thbar / docx2pdf
Last active August 29, 2015 14:10 — forked from diogo-almeida/docx2pdf
# Path of LibreOffice installation
cd /Applications/LibreOffice.app/Contents/MacOS
# General command
./soffice --headless --convert-to <extention> <path+file>
# Automatically convert all .odt files to pdf
./soffice --headless --convert-to pdf ~/Downloads/*.odt
# To specify an output folder you can add the --outdir option
module Mongoid
module DeepCloning
def deep_clone(attrs = {}, obj = nil)
returning obj || self.class.new do |o|
o.write_attributes(@attributes.merge(attrs).except("_id", "versions").except(*o.class.associations.keys))
yield o if block_given?
o.save
@attributes.each_pair do |key, value|
next unless proxy = self.associations[key]
case proxy.association
@headius
headius / gist:702298
Created November 16, 2010 19:08
Maven gems...I love you.
~/projects/jruby ➔ gem install -v1.5.5 org.jruby.jruby-complete
Installing from Maven using install at /Users/headius/apache-maven-3.0/bin
Successfully installed org.jruby.jruby-complete-1.5.5-java
1 gem installed
Installing ri documentation for org.jruby.jruby-complete-1.5.5-java...
Installing RDoc documentation for org.jruby.jruby-complete-1.5.5-java...
~/projects/jruby ➔ gem install -v1.5.3 org.jruby.jruby-complete
Installing from Maven using install at /Users/headius/apache-maven-3.0/bin
Successfully installed org.jruby.jruby-complete-1.5.3-java
@nesquena
nesquena / index_users_emails.rb
Created July 14, 2011 00:11
Add concurrent index in Postgres Rails migration
class IndexUsersEmails < ActiveRecord::Migration
def self.up
execute "END"
add_pg_index :users, :email, :lock => false
execute "BEGIN"
end
end
module Watchable
def events
@events ||= Hash.new { |h,k| h[k] = [] }
end
def fire event, *args
events[event].each { |e| e[*args] }
end
def on event, &block
@peterhellberg
peterhellberg / multi_value.rb
Created March 18, 2012 20:30
Support for multiple return values in Ruby 1.9, the way Common Lisp does it… sort of
class MultiValue < BasicObject
attr_reader :secondary
def initialize(obj, *secondary)
@obj, @secondary = obj, secondary
end
def method_missing(sym, *args, &block)
@obj.__send__(sym, *args, &block)
end
@headius
headius / gist:3776559
Created September 24, 2012 15:34
Open a dir as a file on JRuby on Java 7+
require 'java'
java_import java.nio.channels.FileChannel
java_import java.nio.file.StandardOpenOption
java_import java.nio.file.FileSystems
path = FileSystems.default.get_path('/')
option = StandardOpenOption::READ
ch = FileChannel.open(path, option)
@keithrbennett
keithrbennett / locale_displayer.rb
Last active December 14, 2015 04:09
Example JRuby program to display the JVM's available locales and their number, currency, and date formats. Change the format constants to see more kinds of formatting (e.g. DateFormat::LONG/SHORT). - Keith R. Bennett, @keithrbennett
# Example JRuby program to display the JVM's available locales
# and their number, currency, and date formats.
#
# Keith R. Bennett, @keithrbennett
require 'java'
java_import 'java.util.Locale'
java_import 'java.text.DateFormat'
java_import 'java.text.NumberFormat'
# coding: utf-8
# Can ruby have method names have newlines/be crazy?
class BadKitty
FACE = "
|\\_/|
/ @ @ \\
( > º < )
`>>x<<´
@dmitriy-kiriyenko
dmitriy-kiriyenko / active_model_lint.rb
Created February 23, 2012 13:37
ActiveModel lint tests for rspec
# put the file into spec/support
shared_examples_for "ActiveModel" do
include ActiveModel::Lint::Tests
# to_s is to support ruby-1.9
ActiveModel::Lint::Tests.public_instance_methods.map{|m| m.to_s}.grep(/^test/).each do |m|
example m.gsub('_',' ') do
send m
end
end