working on it ...

Filters

Explore Public Snippets

Sort by

Found 427 snippets matching: extraction

    public by antlong  489216  15  7  1

    Extract JPG images from a PDF

    A command line tool to extract jpg images from pdf files.
    #!/usr/bin/env python
    import sys
    
    
    def main():
        """Extract JPG's from PSD's.
        
        Usage:
          python extract.py filename.pdf
        
        Note:
          All extracted images will be saved to the directory 
          the script is initialized in.
        """
        try:
            pdf = file(sys.argv[1], "rb").read()
        except Exception:
            print "Usage: `python extract.py filename.pdf`"
            return
    
        startmark, endmark = "\xff\xd8", "\xff\xd9"
        startfix, endfix, i, njpg = 0, 2, 0, 0
    
        while True:
            istream = pdf.find("stream", i)
            if istream < 0:
                break
            istart = pdf.find(startmark, istream, istream+20)
            if istart < 0:
                i = istream+20
                continue
            iend = pdf.find("endstream", istart)
            if iend < 0:
                raise Exception("Couldn't find end of stream.")
            iend = pdf.find(endmark, iend-20)
            if iend < 0:
                raise Exception("Couldn't find end of JPG.")
         
            istart += startfix
            iend += endfix
            jpg = pdf[istart:iend]
            with open("jpg%d.jpg" % njpg, "wb") as _f:
                _f.write(jpg)
            njpg += 1
            i = iend
    
        print "Extracted %s JPG files." % njpg
    
    main()
    

    public by p.kontalis  99041  2  5  0

    VTiger Extraction Customers' Data by City

    Extract from Vtiger Customers' List with address and to whom they have been assigned
    SET @city = '[CITY NAME]'; #Replace [CITY NAME] with your preferable city name
    SET @db_name='[DATABASE NAME]'; #Replace [DATABASE NAME] with your database name
    SET @myquery = CONCAT('
    SELECT	', @db_name, '.vtiger_account.accountid AS \'Company Code\',
    		', @db_name, '.vtiger_account.accountname AS \'Company\', 
    		', @db_name, '.vtiger_account.phone AS \'Phone 1\', 
    		', @db_name, '.vtiger_account.otherphone AS \'Phone 2\', 
    		', @db_name, '.vtiger_account.email1 AS \'Email 1\', 
    		', @db_name, '.vtiger_account.email2 AS \'Email 2\', 
    		', @db_name, '.vtiger_account.website AS \'Website\', 
    		', @db_name, '.vtiger_account.fax AS \'Fax\',
    		', @db_name, '.vtiger_accountbillads.bill_city AS \'City\',
    		', @db_name, '.vtiger_accountbillads.bill_code AS \'TK\',
    		', @db_name, '.vtiger_accountbillads.bill_country AS \'Country\',
    		', @db_name, '.vtiger_accountbillads.bill_state AS \'State\',
    		', @db_name, '.vtiger_accountbillads.bill_street AS \'Street\',
    		', @db_name, '.vtiger_accountbillads.bill_pobox AS \'TK\', 
    		', @db_name, '.vtiger_users.last_name AS \'Αssignment το\'
    FROM ', @db_name, '.vtiger_account
    INNER JOIN ', @db_name, '.vtiger_accountbillads 
    ON ', @db_name, '.vtiger_account.accountid = ', @db_name, '.vtiger_accountbillads.accountaddressid
    INNER JOIN ', @db_name, '.vtiger_crmentity
    ON ', @db_name, '.vtiger_account.accountid = ', @db_name, '.vtiger_crmentity.crmid	
    LEFT JOIN ', @db_name, '.vtiger_users
    ON ', @db_name, '.vtiger_crmentity.smownerid = ', @db_name, '.vtiger_users.id
    WHERE ', @db_name, '.vtiger_accountbillads.bill_city=@city
    AND ', @db_name, '.vtiger_crmentity.setype=\'Accounts\' 
    ');
    PREPARE stmt FROM @myquery;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;
                
    

    public by johansonkatherine  4880  0  6  3

    Java code for Changing Color Space of PDF Document

    This code shows how java developers can change color space of PDF document from RGB color to CMYK and vice versa by using Aspose.PDF for Java Library. The following methods have been implemented in the Operator class for changing colors. Use it to change some specific RGB/CMYK colors to CMYK/RGB color space, keeping the remaining PDF document as it
    Document doc = new Document(myDir + "input_color.pdf");
    OperatorCollection contents = doc.getPages().get_Item(1).getContents();
    System.out.println("Values of RGB color operators in the pdf document");
    for (int j = 1; j <= contents.size(); j++)
        {
    	Operator oper = contents.get_Item(j);
    	if (oper instanceof Operator.SetRGBColor || oper instanceof Operator.SetRGBColorStroke)
    	try {
    	    //Converting RGB to CMYK color
    	    System.out.println(oper.toString());
    
    	    double[] rgbFloatArray = new double[]
    	        {
    		    	Double.valueOf(oper.getParameters().get(0).toString()),
    		    	Double.valueOf(oper.getParameters().get(1).toString()),
    		    	Double.valueOf(oper.getParameters().get(2).toString()),
    	        };
    	    double[] cmyk = new double[4];
    	    if (oper instanceof Operator.SetRGBColor)
    	    {
    		((Operator.SetRGBColor)oper).getCMYKColor(rgbFloatArray, cmyk);
    		contents.set_Item(j, new Operator.SetCMYKColor(cmyk[0], cmyk[1], cmyk[2], cmyk[3]));
    		}
    		else if (oper instanceof Operator.SetRGBColorStroke)
    		{
    		    ((Operator.SetRGBColorStroke)oper).getCMYKColor(rgbFloatArray, cmyk);
    		   contents.set_Item(j, new Operator.SetCMYKColorStroke(cmyk[0], cmyk[1], cmyk[2], cmyk[3]));
    		}
    		    else
    throw new java.lang.Throwable("Unsupported command");
    
    	} catch (Throwable e) {
    	    e.printStackTrace();
    	}
    		        }
    doc.save(myDir + "input_colorout.pdf");
    
    //Testing the result
    System.out.println("Values of converted CMYK color operators in the result pdf document");
    doc = new Document(myDir + "input_colorout.pdf");
    contents = doc.getPages().get_Item(1).getContents();
    for (int j = 1; j <= contents.size(); j++)
        {
    	Operator oper = contents.get_Item(j);
    	if (oper instanceof Operator.SetCMYKColor || oper instanceof Operator.SetCMYKColorStroke)
    	{
    	   System.out.println(oper.toString());
    	}
       }
    

    public by fabio.nosenzo  2803  0  5  0

    Excel VBA String Extraction

    Extract a string in Excel VBA from another string
    ' originary string
    Dim sString As String
    ' extracted string
    Dim sNewString As String
    ' starting index for extraction
    Dim lIndex As Long
    ' number of char to be extracted
    Dim iCharNum As Integer
    
    sNewString = Mid(sString, iIndex, iCharNum)
    
    

    external by Kieranties  160  1  2  0

    Quick and dirty function to download VMs from http://Modern.ie and trigger extraction

    Quick and dirty function to download VMs from http://Modern.ie and trigger extraction: Get-IEVM.ps1
    <#
      .EXAMPLE
      PS> $source = "https://az412801.vo.msecnd.net/vhd/VMBuild_20140402/2012/IE11_Win8.1/Windows/IE11.Win8.1.For.WindowsHyperV.WMIv2.txt"
      PS> $destination = (mkdir "$env:USERPROFILE\downloads\vm" -Force)
      PS> $vmDest = (mkdir "$env:USERPROFILE\vms" -Force)
      PS> Get-IEVM $source $destination -extract $vmDest
    #>
    Function Get-IEVM {
        param(
            [Parameter(Mandatory=$true)]
            [string]$source,
            [Parameter(Mandatory=$true)]
            [string]$destination,
            [string]$extract
        )
    
        $entries = (Invoke-WebRequest $source).content -split [Environment]::NewLine
        $entries | % {
            Write-Host "Downloading - $_"
            Start-BitsTransfer $_ $destination
        }
      
        if($extract){
            Push-Location $destination
            (gi *.exe) | % { cmd /c $_ -s2 "-d$extract" }
            Pop-Location
        }
        Write-Host Complete
    }
    
    

    external by Stephan Hagemann  137  0  2  0

    Extraction of persistence engine out of ticketee sample app

    Extraction of persistence engine out of ticketee sample app: extract_persistence.sh
    #!/bin/bash --login
    
    ensure() {
      "$@" || exit 1
    }
    
    cd r4ia_examples/ticketee;
    
    git checkout . && git clean -fd
    
    rvm use 2.2.1@r4ia --create
    
    gem install bundler
    
    bundle
    
    ##########
    ### CREATE PERSISTENCE COMPONENT AND MOVE CODE
    ##########
    
    rails plugin new components/persistence \
        --full \
        --skip-bundle --skip-git \
        --skip-test-unit \
        --skip-action-view --skip-sprockets --skip-javascript \
        --dummy-path=spec/dummy
    
    mv app/models/* components/persistence/app/models
    mkdir -p components/persistence/spec/models
    mv spec/models/* components/persistence/spec/models
    
    #cd components/persistence && ensure eval rspec
    
    cp spec/spec_helper.rb components/persistence/spec/spec_helper.rb
    cp spec/rails_helper.rb components/persistence/spec/rails_helper.rb
    
    #cd components/persistence && ensure eval rspec
    
    echo '# This file is copied to spec/ when you run "rails generate rspec:install"
    ENV["RAILS_ENV"] ||= "test"
    require "spec_helper"
    require File.expand_path("../dummy/config/environment", __FILE__)
    require "rspec/rails"
    
    # Requires supporting ruby files with custom matchers and macros, etc, in
    # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are
    # run as spec files by default. This means that files in spec/support that end
    # in _spec.rb will both be required and run as specs, causing the specs to be
    # run twice. It is recommended that you do not name files matching this glob to
    # end with _spec.rb. You can configure this pattern with the --pattern
    # option on the command line or in ~/.rspec, .rspec or `.rspec-local`.
    #
    # The following line is provided for convenience purposes. It has the downside
    # of increasing the boot-up time by auto-requiring all files in the support
    # directory. Alternatively, in the individual `*_spec.rb` files, manually
    # require only the support files necessary.
    #
    Dir[Rails.root.join("spec/support/**/*.rb")].each { |f| require f }
    
    # Checks for pending migrations before tests are run.
    # If you are not using ActiveRecord, you can remove this line.
    ActiveRecord::Migration.maintain_test_schema!
    
    RSpec.configure do |config|
      # Remove this line if you"re not using ActiveRecord or ActiveRecord fixtures
      config.fixture_path = "#{::Rails.root}/spec/fixtures"
    
      # If you"re not using ActiveRecord, or you"d prefer not to run each of your
      # examples within a transaction, remove the following line or assign false
      # instead of true.
      config.use_transactional_fixtures = false
    
      # RSpec Rails can automatically mix in different behaviours to your tests
      # based on their file location, for example enabling you to call `get` and
      # `post` in specs under `spec/controllers`.
      #
      # You can disable this behaviour by removing the line below, and instead
      # explicitly tag your specs with their type, e.g.:
      #
      #     RSpec.describe UsersController, :type => :controller do
      #       # ...
      #     end
      #
      # The different available types are documented in the features, such as in
      # https://relishapp.com/rspec/rspec-rails/docs
      config.infer_spec_type_from_file_location!
    
      config.include Warden::Test::Helpers, type: :feature
      config.after(type: :feature) { Warden.test_reset! }
      config.include Devise::TestHelpers, type: :controller
    end
    ' > components/persistence/spec/rails_helper.rb
    
    #cd components/persistence && ensure eval rspec
    
    mkdir -p components/persistence/db/migrate
    mv db/migrate/* components/persistence/db/migrate
    
    #cd components/persistence && rake db:migrate RAILS_ENV=test && ensure eval rspec
    
    mkdir -p components/persistence/app/uploaders
    mv app/uploaders/* components/persistence/app/uploaders
    
    #cd components/persistence && rake db:migrate RAILS_ENV=test && ensure eval rspec
    
    echo '
    $:.push File.expand_path("../lib", __FILE__)
    
    # Maintain your gems version:
    require "persistence/version"
    
    # Describe your gem and declare its dependencies:
    Gem::Specification.new do |s|
      s.name        = "persistence"
      s.version     = Persistence::VERSION
      s.authors     = ["TODO: Write your name"]
      s.email       = ["TODO: Write your email address"]
      s.homepage    = "TODO"
      s.summary     = "TODO: Summary of Persistence."
      s.description = "TODO: Description of Persistence."
      s.license     = "MIT"
    
      s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
    
      s.add_dependency "rails", "4.2.1"
      s.add_dependency "devise", "3.4.1"
    
      s.add_development_dependency "sqlite3"
      s.add_development_dependency "rspec-rails", "3.2.1"
    end
    ' > components/persistence/persistence.gemspec
    
    #cd components/persistence && rake db:migrate RAILS_ENV=test && ensure eval rspec
    
    echo '
    require "devise"
    
    module Persistence
      require "persistence/engine"
    end
    ' > components/persistence/lib/persistence.rb
    
    #cd components/persistence && bundle && rake db:migrate RAILS_ENV=test && ensure eval rspec
    
    echo '
    $:.push File.expand_path("../lib", __FILE__)
    
    # Maintain your gems version:
    require "persistence/version"
    
    # Describe your gem and declare its dependencies:
    Gem::Specification.new do |s|
      s.name        = "persistence"
      s.version     = Persistence::VERSION
      s.authors     = ["TODO: Write your name"]
      s.email       = ["TODO: Write your email address"]
      s.homepage    = "TODO"
      s.summary     = "TODO: Summary of Persistence."
      s.description = "TODO: Description of Persistence."
      s.license     = "MIT"
    
      s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
    
      s.add_dependency "rails", "4.2.1"
      s.add_dependency "devise", "3.4.1"
      s.add_dependency "carrierwave", "0.10.0"
    
      s.add_development_dependency "sqlite3"
      s.add_development_dependency "rspec-rails", "3.2.1"
    end
    ' > components/persistence/persistence.gemspec
    
    echo '
    require "devise"
    require "carrierwave"
    
    module Persistence
      require "persistence/engine"
    end
    ' > components/persistence/lib/persistence.rb
    
    #cd components/persistence && bundle && rake db:migrate RAILS_ENV=test && ensure eval rspec
    
    echo '
    $:.push File.expand_path("../lib", __FILE__)
    
    # Maintain your gems version:
    require "persistence/version"
    
    # Describe your gem and declare its dependencies:
    Gem::Specification.new do |s|
      s.name        = "persistence"
      s.version     = Persistence::VERSION
      s.authors     = ["TODO: Write your name"]
      s.email       = ["TODO: Write your email address"]
      s.homepage    = "TODO"
      s.summary     = "TODO: Summary of Persistence."
      s.description = "TODO: Description of Persistence."
      s.license     = "MIT"
    
      s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
    
      s.add_dependency "rails", "4.2.1"
      s.add_dependency "devise", "3.4.1"
      s.add_dependency "carrierwave", "0.10.0"
      s.add_dependency "searcher"
    
      s.add_development_dependency "sqlite3"
      s.add_development_dependency "rspec-rails", "3.2.1"
    end
    ' > components/persistence/persistence.gemspec
    
    echo '
    source "https://rubygems.org"
    
    gemspec
    
    gem "searcher", github: "radar/searcher", ref: "c2975124e11677825481ced9539f16f0cb0640de"
    ' > components/persistence/Gemfile
    
    echo '
    require "devise"
    require "carrierwave"
    require "searcher"
    
    module Persistence
      require "persistence/engine"
    end
    ' > components/persistence/lib/persistence.rb
    
    #cd components/persistence && bundle && rake db:migrate RAILS_ENV=test && ensure eval rspec
    
    mkdir -p components/persistence/config/initializers
    mv config/initializers/devise.rb components/persistence/config/initializers
    
    pushd components/persistence && bundle && rake db:migrate RAILS_ENV=test && ensure eval rspec; popd
    
    ##########
    ### CLEAN UP PERSISTENCE COMPONENT
    ##########
    
    rm -rf components/persistence/app/assets
    rm -rf components/persistence/app/controllers
    rm -rf components/persistence/app/helpers
    rm -rf components/persistence/app/mailers
    rm -rf components/persistence/app/models/concerns
    rm -rf components/persistence/app/models/.keep
    rm -rf components/persistence/app/views
    rm -rf components/persistence/lib/tasks
    
    ##########
    ### PREP PERSISTENCE COMPONENT FOR EXTERNAL USE
    ##########
    
    echo '
    module Persistence
      class Engine < ::Rails::Engine
        initializer :append_migrations do |app|
          unless app.root.to_s.match root.to_s+File::SEPARATOR
            app.config.paths["db/migrate"].concat config.paths["db/migrate"].expanded
          end
        end
      end
    end
    ' > components/persistence/lib/persistence/engine.rb
    
    echo '
    $:.push File.expand_path("../lib", __FILE__)
    
    # Maintain your gems version:
    require "persistence/version"
    
    # Describe your gem and declare its dependencies:
    Gem::Specification.new do |s|
      s.name        = "persistence"
      s.version     = Persistence::VERSION
      s.authors     = ["Stephan Hagemann"]
      s.email       = ["stephan.hagemann@gmail.com"]
      s.summary     = "Persistence."
    
      s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.rdoc"]
    
      s.add_dependency "rails", "4.2.1"
      s.add_dependency "devise", "3.4.1"
      s.add_dependency "carrierwave", "0.10.0"
      s.add_dependency "searcher"
    
      s.add_development_dependency "sqlite3"
      s.add_development_dependency "rspec-rails", "3.2.1"
    end
    ' > components/persistence/persistence.gemspec
    
    ##########
    ### USE PERSISTENCE IN MAIN APP
    ##########
    
    echo '
    source "https://rubygems.org"
    ruby "2.2.1"
    
    path "components" do
      gem "persistence"
    end
    
    # Bundle edge Rails instead: gem "rails", github: "rails/rails"
    gem "rails", "4.2.1"
    
    gem "sqlite3", group: [:development, :test]
    gem "pg",      group:  :production
    
    # Use SCSS for stylesheets
    gem "sass-rails", "~> 5.0"
    # Use Uglifier as compressor for JavaScript assets
    gem "uglifier", ">= 1.3.0"
    # Use CoffeeScript for .coffee assets and views
    gem "coffee-rails", "~> 4.1.0"
    # See https://github.com/rails/execjs#readme for more supported runtimes
    # gem "therubyracer", platforms: :ruby
    
    # Use jquery as the JavaScript library
    gem "jquery-rails"
    # Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder
    gem "jbuilder", "~> 2.0"
    # bundle exec rake doc:rails generates the API under doc/api.
    gem "sdoc", "~> 0.4.0", group: :doc
    
    # Use ActiveModel has_secure_password
    # gem "bcrypt", "~> 3.1.7"
    
    # Use Unicorn as the app server
    # gem "unicorn"
    
    # Use Capistrano for deployment
    # gem "capistrano-rails", group: :development
    
    gem "bootstrap-sass", "~> 3.3"
    gem "font-awesome-rails", "~> 4.3"
    gem "simple_form", "~> 3.1.0"
    gem "devise", "~> 3.4.1"
    gem "pundit", "~> 0.3.0"
    gem "searcher", github: "radar/searcher"
    gem "active_model_serializers", "~> 0.9.3"
    
    gem "carrierwave", "~> 0.10.0"
    gem "fog", "~> 1.29.0"
    gem "rails_12factor", group: :production
    gem "puma", group: :production
    
    gem "sinatra"
    
    group :development, :test do
      # Call "byebug" anywhere in the code to stop execution and get a debugger console
      gem "byebug"
    
      # Access an IRB console on exception pages or by using <%= console %> in views
      gem "web-console", "~> 2.0"
    
      # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring
      gem "spring"
    
      gem "rspec-rails", "~> 3.2.1"
    end
    
    group :test do
      gem "capybara", "~> 2.4"
      gem "factory_girl_rails", "~> 4.5"
      gem "selenium-webdriver", "~> 2.45"
      gem "database_cleaner", "~> 1.4"
      gem "email_spec", "~> 1.6.0"
    end
    ' > Gemfile
    
    bundle && rake db:migrate RAILS_ENV=test && ensure eval rspec
    
    
    

    external by Trevor Rowe  126  0  2  0

    A simple **untested** extraction from the V1 SDK for Ruby from AWS::SQS::Queue#poll.

    A simple **untested** extraction from the V1 SDK for Ruby from AWS::SQS::Queue#poll.: gistfile1.rb
    # A simple extraction from the V1 SDK for Ruby from AWS::SQS::Queue#poll.
    # No effort was made to test this code.
    #
    # @example Basic Usage
    #
    #   poller = QueuePoller.new(queue_url)
    #   poller.poll { |msg| puts msg.body}
    #
    # @example Customized API client
    #
    #   sqs = Aws::SQS::Client.new(region:'us-west-2')
    #
    #   poller = QueuePoller.new(queue_url, client:sqs)
    #   poller.poll { |msg| puts msg.body}
    #
    class QueuePoller
    
      DEFAULT_WAIT_TIME_SECONDS = 15
    
      def initialize(queue_url, client:nil)
        @queue_url = queue_url
        @client = client || Aws::SQS::Client.new
      end
    
      # Polls continually for messages.  For example, you can use
      # this to poll indefinitely:
      #
      #     queue.poll { |msg| puts msg.body }
      #
      # Or, to poll indefinitely for the first message and then
      # continue polling until no message is received for a period
      # of at least ten seconds:
      #
      #     queue.poll(:initial_timeout => false,
      #                :idle_timeout => 10) { |msg| puts msg.body }
      #
      # As with the block form of {#receive_message}, this method
      # automatically deletes the message then the block exits
      # normally.
      #
      # @yieldparam [ReceivedMessage] message Each message that was received.
      #
      # @param [Hash] opts Options for polling.
      #
      # @option opts [Integer] :wait_time_seconds The number of seconds
      #   the service should wait for a response when requesting a new message.
      #   Defaults to {DEFAULT_WAIT_TIME_SECONDS}. Use `nil` to
      #   use the queue's global long polling wait time setting.
      #   See {#wait_time_seconds} to set the global long poll setting
      #   on the queue.
      #
      # @option opts [Integer] :idle_timeout The maximum number of
      #   seconds to spend polling while no messages are being
      #   returned.  By default this method polls indefinitely
      #   whether messages are received or not.
      #
      # @option opts [Integer] :initial_timeout The maximum number
      #   of seconds to spend polling before the first message is
      #   received.  This option defaults to the value of
      #   `:idle_timeout`.  You can specify `false` to poll
      #   indefinitely for the first message when `:idle_timeout` is
      #   set.
      #
      # @option opts [Integer] :batch_size The maximum number of
      #   messages to retrieve in a single request.  By default
      #   messages are received one at a time.  Valid values:
      #   integers from 1 to 10.
      #
      # @option opts [Integer] :visibility_timeout The duration (in
      #   seconds) that the received messages are hidden from
      #   subsequent retrieve requests.  Valid values: integer from
      #   0 to 43200 (maximum 12 hours)
      #
      # @option opts [Array<Symbol, String>] :attributes The
      #   attributes to populate in each received message.  Valid values:
      #
      #   * `:all` (to populate all attributes)
      #   * `:sender_id`
      #   * `:sent_at`
      #   * `:receive_count`
      #   * `:first_received_at`
      #
      #   See {ReceivedMessage} for documentation on each
      #   attribute's meaning.
      #
      # @option opts [Float, Integer] :poll_interval As of
      #   v1.7.2, this option is no longer used. See the
      #   `:wait_time_seconds` option for long polling instead.
      #
      # @return [nil]
      def poll(opts = {}, &block)
        opts[:limit] = opts.delete(:batch_size) if
          opts.key?(:batch_size)
    
        opts[:wait_time_seconds] = DEFAULT_WAIT_TIME_SECONDS unless
          opts.has_key?(:wait_time_seconds)
    
        last_message_at = Time.now
        got_first = false
        loop do
          got_msg = false
          receive_messages(opts) do |message|
            got_msg = got_first = true
            last_message_at = Time.now
            yield(message)
          end
          unless got_msg
            return if hit_timeout?(got_first, last_message_at, opts)
          end
        end
        nil
    
      end
    
      private
    
      def receive_messages(opts = {}, &block)
        resp = @client.receive_message(receive_opts(opts))
    
        failed = verify_receive_message_checksum resp
    
        raise Errors::ChecksumError.new(failed) unless failed.empty?
    
        messages = resp[:messages].map do |m|
          ReceivedMessage.new(self, m[:message_id], m[:receipt_handle],
            :body => m[:body],
            :md5 => m[:md5_of_body],
            :request_id => (resp[:response_metadata] || {})[:request_id],
            :attributes => m[:attributes],
            :message_attributes => m[:message_attributes])
        end
    
        if block
          call_message_block(messages, block)
        elsif opts[:limit] && opts[:limit] != 1
          messages
        else
          messages.first
        end
      end
    
      def receive_opts(opts)
        receive_opts = { :queue_url => @queue_url }
        receive_opts[:visibility_timeout] = opts[:visibility_timeout] if
          opts[:visibility_timeout]
        receive_opts[:max_number_of_messages] = opts[:limit] if
          opts[:limit]
        receive_opts[:wait_time_seconds] = opts[:wait_time_seconds] if
          opts[:wait_time_seconds]
        receive_opts[:message_attribute_names] = opts[:message_attribute_names] if
          opts[:message_attribute_names]
    
        if names = opts[:attributes]
          receive_opts[:attribute_names] = names.map do |name|
            name = ReceivedMessage::ATTRIBUTE_ALIASES[name.to_sym] if
              ReceivedMessage::ATTRIBUTE_ALIASES.key?(name.to_sym)
            name = Core::Inflection.class_name(name.to_s) if name.kind_of?(Symbol)
            name
          end
        end
    
        receive_opts
      end
    
      def hit_timeout?(got_first, last_message_at, opts)
        initial_timeout = opts[:initial_timeout]
        idle_timeout = opts[:idle_timeout]
    
        timeout = (got_first ||
                   # if initial_timeout is false (as opposed
                   # to nil) then we skip the branch and poll
                   # indefinitely until the first message
                   # comes
                   (!initial_timeout && initial_timeout != false) ?
                   idle_timeout :
                   initial_timeout) and
          Time.now - last_message_at > timeout
      end
    
    end
    
    
    

    external by Peter Schon  125  0  2  0

    Javascript function arguments extraction with PyV8

    Javascript function arguments extraction with PyV8: js_arg_extract_w_pyv8
    import PyV8
    
    
    class Globals(PyV8.JSClass):
        def __init__(self):
            super(Globals, self).__init__()
            self.coords = []
    
        def PutMarkers(self, selector, coords):
            coords = PyV8.convert(coords)
    
            for coord in coords['data']:
                self.coords.append({
                    'lat': coord['lat'],
                    'lng': coord['lng'],
                    'id': coord['id']
                })
    
        def ready(self, function):
            function()
    
        def __getattr__(self, attr):
            class Hook(object):
                def __call__(this, *args, **kwargs):
                    return self
                def __getattr__(this, item):
                    return getattr(self, item)
    
            return Hook()
    
    script_content = """
    $(document).ready(function(){
        new AwesomeLibrary.PutMarkers('#map', {
            data: [{id: 1, lat: '47.160971', lng: '16.4878386'}]
        });
    });"""
    
    context_globals = Globals()
    with PyV8.JSContext(context_globals) as ctx:
        ctx.eval(script_content)
    
    print(context_globals.coords)
    
    

    external by gdkchan  2349  97  3  0

    OpenLoad Stream URL Extraction

    OpenLoad Stream URL Extraction: OLDownload
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.IO;
    using System.Net;
    using System.Text.RegularExpressions;
    
    namespace OLDownload
    {
        class Program
        {
            const string UserAgent = "Mozilla / 5.0(Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
            const string NumbersJs = "https://openload.co/assets/js/obfuscator/numbers.js";
    
            static void Main(string[] args)
            {
                Console.WriteLine("OpenLoad Stream URL Extractor by gdkchan");
                Console.WriteLine("This is basically just a small test and not guaranteed to work");
    
                Console.Write(Environment.NewLine);
    
                Console.WriteLine("Type or paste the URL of the file below:");
    
                string URL = Console.ReadLine();
    
                URL = GetStreamURL(URL);
    
                Console.Write(Environment.NewLine);
    
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Download URL:");
                Console.ResetColor();
    
                Console.WriteLine(URL);
    
                Console.Write(Environment.NewLine);
    
                Console.WriteLine("Press any key to exit...");
                Console.ReadKey();
            }
    
            private static string GetStreamURL(string URL)
            {
                string HTML = HttpGet(URL);
                string NJs = HttpGet(NumbersJs);
    
                string LinkImg = Regex.Match(HTML, "src=\"data:image/png;base64,([A-Za-z0-9+/=]+?)\"").Groups[1].Value;
                string SigNums = Regex.Match(NJs, "window.signatureNumbers='([a-z]+?)'").Groups[1].Value;
    
                System.Diagnostics.Debug.WriteLine(LinkImg);
                System.Diagnostics.Debug.WriteLine(SigNums);
    
                byte[] ImgData = Convert.FromBase64String(LinkImg);
    
                string Output = string.Empty;
    
                using (MemoryStream MS = new MemoryStream(ImgData))
                {
                    using (Bitmap Img = new Bitmap(MS))
                    {
                        for (int Y = 0; Y < Img.Height; Y++)
                        {
                            for (int X = 0; X < Img.Width; X++)
                            {
                                Color Col = Img.GetPixel(X, Y);
    
                                if (Col == Color.FromArgb(0, 0, 0))
                                {
                                    //Black color = end of data
                                    Y = Img.Height;
                                    break;
                                }
    
                                Output += (char)Col.R;
                                Output += (char)Col.G;
                                Output += (char)Col.B;
                            }
                        }
                    }
                }
    
                string[,] ImgStr = new string[10, Output.Length / 200];
                string[,] SigStr = new string[10, SigNums.Length / 260];
    
                for (int i = 0; i < 10; i++)
                {
                    //Fill Array of Image String
                    for (int j = 0; j < ImgStr.GetLength(1); j++)
                    {
                        ImgStr[i, j] = Output.Substring(i * ImgStr.GetLength(1) * 20 + j * 20, 20);
                    }
    
                    //Fill Array of Signature Numbers
                    for (int j = 0; j < SigStr.GetLength(1); j++)
                    {
                        SigStr[i, j] = SigNums.Substring(i * SigStr.GetLength(1) * 26 + j * 26, 26);
                    }
                }
    
                List<string> Parts = new List<string>();
    
                string Ones = string.Empty;
    
                for (int i = 0; i < 10; i++)
                {
                    if (!Regex.IsMatch(Ones, "^1?$|^(11+?)\\1+$"))
                    {
                        string Str = string.Empty;
                        float Sum = 99f; //On JS as VAR_NAME = 'c'['charCodeAt'](0);
    
                        for (int j = 0; j < SigStr.GetLength(1); j++)
                        {
                            for (int ChrIdx = 0; ChrIdx < ImgStr[i, j].Length; ChrIdx++)
                            {
                                if (Sum > 122f) Sum = 98f; //122 is as AAEncode(?) on JS, and 98 as b (like c above)
    
                                char Chr = (char)((int)Math.Floor(Sum));
    
                                if (SigStr[i, j][ChrIdx] == Chr && j >= Str.Length)
                                {
                                    Str += ImgStr[i, j][ChrIdx];
                                    Sum += 2.5f; //Value as AAEncode(?) on JS
                                }
                            }
                        }
    
                        Parts.Add(Str.Replace(",", string.Empty));
                    }
    
                    Ones += '1';
                }
    
                string StreamURL = "https://openload.co/stream/";
    
                StreamURL += Parts[3] + "~";
                StreamURL += Parts[1] + "~";
                StreamURL += Parts[2] + "~";
                StreamURL += Parts[0];
    
                return StreamURL;
            }
    
            private static string HttpGet(string URL)
            {
                WebRequest Request = WebRequest.Create(URL);
                ((HttpWebRequest)Request).UserAgent = UserAgent;
    
                WebResponse Response = Request.GetResponse();
                StreamReader Reader = new StreamReader(Response.GetResponseStream());
    
                return Reader.ReadToEnd();
            }
        }
    }
    
    
    

    external by Ralph Jansen  3593  58  3  0

    A JSON extraction rule for Visual Studio webtest that extracts a value from a JSON response

    A JSON extraction rule for Visual Studio webtest that extracts a value from a JSON response: JsonPropertyExtractionRule.cs
    using Microsoft.VisualStudio.TestTools.WebTesting;
    using Newtonsoft.Json;
    using Newtonsoft.Json.Linq;
    using System.ComponentModel;
    
    namespace Extensions.ExtractionRules
    {
        /// <summary>
        /// A JSON extraction rule for Visual Studio webtest that extracts a value from a JSON response.
        /// </summary>
        [DisplayName("JSON Property Extraction Rule")]
        [Description("Extracts the value from a JSON property out of the response")]
        public class JsonPropertyExtractionRule : ExtractionRule
        {
            /// <summary>
            /// The name of the JSON property to extract from the JSON result.
            /// </summary>
            [DisplayName("Property name")]
            [Description("The name of the JSON property to extract from the JSON result")]
            public string JSonPropertyName { get; set; }
    
            /// <summary>
            /// Extract a JSON value from the response.
            /// </summary>
            public override void Extract(object sender, ExtractionEventArgs e)
            {
                var jsonBody = JsonConvert.DeserializeObject(e.Response.BodyString);
                var o = JObject.FromObject(jsonBody);
                string value = (string)o.SelectToken(JSonPropertyName);
    
                if (!string.IsNullOrWhiteSpace(value))
                {
                    e.WebTest.Context.Add(ContextParameterName, value);
                    e.Message = $"Property '{JSonPropertyName}' has the value '{value}'";
                    e.Success = true;
                }
                else
                {
                    e.Message = $"Property '{JSonPropertyName}' not found in response";
                    e.Success = false;
                }
            }
        }
    }
    
    
    • Public Snippets
    • Channels Snippets