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
| require 'parser/current' | |
| class Processor < AST::Processor | |
| attr_accessor :verbose | |
| def initialize(*args) | |
| super | |
| self.verbose = false | |
| end |
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
| # More information available at https://www.owasp.org/index.php/Blind_SQL_Injection | |
| POSITIVE_DELAY = 2 | |
| CHARS = ('A'..'Z').to_a + ('a'..'z').to_a + ('0'..'9').to_a | |
| def query(table, field, id, char, pos) | |
| %Q[SELECT CASE WHEN substr(#{field}, #{pos}, 1) = \'#{char}\' THEN pg_sleep(#{POSITIVE_DELAY}) ELSE NULL END FROM #{table} WHERE id = #{id} ;] | |
| end | |
| def timeit |
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
| prices = [ | |
| 247901, | |
| 313230, | |
| 362438, | |
| 361772, | |
| 345520, | |
| 338346, | |
| 329087, | |
| 328406, | |
| 342284, |
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
| PROPERTY_TAX_RATE = 0.015 | |
| home_value = 1_000_000.0 | |
| deposit = 500_000 | |
| #loan_amount = home_value - deposit | |
| yearly_property_tax = home_value * PROPERTY_TAX_RATE | |
| monthly_property_tax = yearly_property_tax / 12.0 | |
| monthly_property_tax_adjustment = monthly_property_tax * 0.36 | |
| principal = 500_000.0 | |
| monthly_interest_rate = 0.03 / 12 |
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
| require 'google/cloud/vision' | |
| def log(s); puts s; end | |
| module GoogleCloudVision | |
| class OcrPdfService | |
| attr_accessor :pdf_filename | |
| def initialize(pdf_filename) | |
| fail "GOOGLE_CLOUD_KEYFILE env variable required" unless ENV['GOOGLE_CLOUD_KEYFILE'] |
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
| # These commands are to be run in different tmux panes to quickly copy the | |
| # contents of one hard drive to another. `rsync` is used for it's robustness, | |
| # interruptibility, and efficiency in incremental updates. | |
| # | |
| # After the initial clone, the same `rsync` command can be run to copy just the | |
| # new/changed files from source to target. | |
| # tmux pane 1 | |
| rsync --partial -a /Volumes/ushuaia/ /Volumes/amsterdam/ |
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
| #!/usr/bin/env ruby | |
| require 'test/unit' | |
| class TestSums < Test::Unit::TestCase | |
| def setup | |
| @a = [2, 5, 18, 27] | |
| @sum = 0 | |
| end |
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
| def update_tree(options = {}, &block) | |
| authorize!(action_name.to_sym, resource_class) | |
| parent_id = params[:parent_id] | |
| # check that parent shoud by node which is visible for the user. | |
| authorize!(:list, params[:parent_id]) | |
| err_exit = proc { |r| | |
| render json: { |
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
| module TreeListHelper | |
| # the collection need to be the root parents | |
| def tree_list(collection) | |
| content_tag(:ul) do | |
| collection.each do |item| | |
| if item.children.any? | |
| concat( | |
| content_tag(:li, id: item.id) do | |
| concat(item.name) | |
| concat(tree_list(item.children)) |
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
| require 'matrix' | |
| require 'pp' | |
| # This is how you can define new matrix | |
| a = Matrix[ [1,2], [3,4]] | |
| b = Matrix[ [4,3], [2,1]] | |
| pp a | |
| pp b |