This file contains hidden or 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
| # Simple example of aes-256-cbc encryption for Ruby/Rails to encrypt URL params (or any text) | |
| require 'openssl' | |
| require 'base64' | |
| require 'uri' | |
| plaintext = 'id=example_id&user_id=the_user_id&username=voxtrot&user_first_name=john&user_last_name=doe&user_image=http://i1.nyt.com/images/misc/nytlogo379x64.gif' | |
| # |
This file contains hidden or 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
| class ActiveRecord::Base | |
| def self.import!(record_list) | |
| raise ArgumentError "record_list not an Array of Hashes" unless record_list.is_a?(Array) && record_list.all? {|rec| rec.is_a? Hash } | |
| return record_list if record_list.empty? | |
| (1..record_list.count).step(1000).each do |start| | |
| key_list, value_list = convert_record_list(record_list[start-1..start+999]) | |
| sql = "INSERT INTO #{self.table_name} (#{key_list.join(", ")}) VALUES #{value_list.map {|rec| "(#{rec.join(", ")})" }.join(" ,")}" | |
| self.connection.insert_sql(sql) |
This file contains hidden or 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
| # Beginning Rubyists: simply run >> ruby hex-convertions.rb to see examples | |
| # or use irb to build the code on the fly | |
| # you can convert HEX to DEC using the method .to_i(base), | |
| # which converts a string to a decimal number from the specified base number | |
| puts "00".to_i(16) | |
| puts "FF".to_i(16) |
This file contains hidden or 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
| // | |
| // Regular Expression for URL validation | |
| // | |
| // Author: Diego Perini | |
| // Created: 2010/12/05 | |
| // Updated: 2018/09/12 | |
| // License: MIT | |
| // | |
| // Copyright (c) 2010-2018 Diego Perini (http://www.iport.it) | |
| // |
NewerOlder

