Skip to content

Instantly share code, notes, and snippets.

View 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
View deep_cloning.rb
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 Nov 16, 2010
Maven gems...I love you.
View gist:702298
~/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 Jul 14, 2011
Add concurrent index in Postgres Rails migration
View index_users_emails.rb
class IndexUsersEmails < ActiveRecord::Migration
def self.up
execute "END"
add_pg_index :users, :email, :lock => false
execute "BEGIN"
end
end
View watchable.rb
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 Mar 18, 2012
Support for multiple return values in Ruby 1.9, the way Common Lisp does it… sort of
View multi_value.rb
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 Sep 24, 2012
Open a dir as a file on JRuby on Java 7+
View gist:3776559
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)
View account.rb
class Account
include Mongoid::Document
include Mongoid::Timestamps
field :subdomain, :type => String
embeds_many :users
accepts_nested_attributes_for :users
validates_presence_of :name, :subdomain
validates_uniqueness_of :subdomain, :case_sensitive => false
@keithrbennett
keithrbennett / locale_displayer.rb
Last active Dec 14, 2015
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
View locale_displayer.rb
# 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'
View bad_kitty.rb
# coding: utf-8
# Can ruby have method names have newlines/be crazy?
class BadKitty
FACE = "
|\\_/|
/ @ @ \\
( > º < )
`>>x<<´