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
require 'pdf-reader' | |
regex = /Balance Due:(\s)+[$].*/ | |
reader = PDF::Reader.new("Sep2022Invoice.pdf") # this is an example | |
p reader.page_count # e.g. 3 | |
txt = reader.pages.last.text.split(/w+/).last # Balance Due: $44,480.07 | |
p regex.match(txt).to_s.split.last # $44,480.07 |
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
require 'rubygems' | |
class File | |
def self.sequential_read(file_path,chunk_size=nil) | |
open(file_path) do |f| | |
f.each_chunk(chunk_size) do |chunk| | |
yield chunk | |
end | |
end | |
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
require 'rubygems' | |
require 'json' | |
require 'active_support/core_ext' | |
require 'date' | |
require 'rest-client' | |
require 'fastercsv' | |
APP_ID = "<your_app_id>" | |
# e.g. Get monthy currency (USD) exchange rates from 31st Jan 2008 to 31st Dec 2010 | |
# http://openexchangerates.org/api/historical/2009-10-10.json?&app_id=<your_app_id> |
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
require 'rubygems' | |
require 'active_support/core_ext' | |
require 'date' | |
require 'rest-client' | |
# e.g. Get monthy exchange rates - USD to INR from 2008 to 2013 | |
# http://www.exchange-rates.org/Rate/USD/INR/06-13-2014 | |
start_date = Date.parse("2007-21-31") | |
(1..72).each do |month| |
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
ActiveRecord::ConnectionAdapters::OracleEnhancedAdapter.class_eval do | |
alias_method :orig_next_sequence_value, :next_sequence_value | |
def next_sequence_value(sequence_name) | |
if sequence_name == 'autogenerated' | |
id | |
else | |
orig_next_sequence_value(sequence_name) | |
end | |
end | |
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
module Devise | |
module Models | |
module Recoverable | |
module ClassMethods | |
def reset_password_by_token(attributes={}) | |
recoverable = find_or_initialize_with_error_by(:reset_password_token, attributes[:reset_password_token]) | |
recoverable.reset_password!(attributes[:password], attributes[:password_confirmation]) if recoverable.persisted? | |
recoverable.failed_attempts = 0 | |
recoverable.save(:validate => false) | |
recoverable |
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
VALUE rb_data_typed_object_alloc(VALUE klass, void *datap, const rb_data_type_t *type) | |
{ | |
NEWOBJ(data, struct RTypedData); | |
if (klass) Check_Type(klass, T_CLASS); | |
OBJSETUP(data, klass, T_DATA); | |
data->data = datap; | |
data->typed_flag = 1; |
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
#define TypedData_Make_Struct(klass, type, data_type, sval) (\ | |
(sval) = ALLOC(type),\ | |
memset((sval), 0, sizeof(type)),\ | |
TypedData_Wrap_Struct((klass),(data_type),(sval))\ | |
) | |
#define TypedData_Wrap_Struct(klass,data_type,sval)\ | |
rb_data_typed_object_alloc((klass),(sval),(data_type)) |
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
VALUE rb_iseq_new_main(NODE *node, VALUE filename, VALUE filepath) | |
{ | |
rb_thread_t *th = GET_THREAD(); | |
VALUE parent = th->base_block->iseq->self; | |
return rb_iseq_new_with_opt(node, rb_str_new2("<main>"), filename, filepath, INT2FIX(0), | |
parent, ISEQ_TYPE_MAIN, &COMPILE_OPTION_DEFAULT); | |
} |
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
def self.convert_file_to_include_CRLF unix_file_name, win_file_name | |
if RUBY_PLATFORM =~ /win32/ | |
path = "#{RAILS_ROOT}/tmp".gsub('/', '\\') | |
else | |
path = "#{RAILS_ROOT}/tmp" | |
end | |
success = system <<-CMD | |
cd #{path} | |
sed 's/$/\r/' #{unix_file_name} > #{win_file_name} |