问:
Using AND with multiple conditions for formatting google sheets/excel
I'm trying to highlight a cell if 3 different conditions are met in 3 other different cells.

```<code>A       B        C        D
</code>```

Highlight A: if B is greater than 5, C is empty, and D doesn't have a duplicate

When I use these formulas individually, they work:

```<code>=AND(b:b,>5)

=AND(isblank(c:c))

=AND(countif(A:A,A1)<2)
</code>```

But when I combine them this way, they don't work:

```<code>=AND(b:b,>5),(isblank(c:c)),(countif(A:A,A1)<2)
</code>```

What am I doing wrong?

Also, if a value occurs multiple times, is there a formula to highlight all but the first occurrence?

答:
Highlight A: if B is greater than 5, C is empty, and D doesn't have a duplicate

apply to range A1:A:

```<code>=(B1>5)*(C1="")*(COUNTIF(D:D, D1)<2)
</code>```

Also, if a value occurs multiple times, is there a formula to highlight all but the first occurrence?

use shorter:

```<code>=COUNTIF(A$1:A1, A1)>1
</code>```

or:

```<code>=ARRAYFORMULA(COUNTIFS(A$1:A, A1, ROW(A$1:A), "<="&ROW(A1))>1)
</code>```

Body:
I'm trying to highlight a cell if 3 different conditions are met in 3 other different cells.

A       B        C        D

Highlight A: if B is greater than 5, C is empty, and D doesn't have a duplicate

When I use these formulas individually, they work:

=AND(b:b,>5)

=AND(isblank(c:c))

=AND(countif(A:A,A1)<2)

But when I combine them this way, they don't work:

=AND(b:b,>5),(isblank(c:c)),(countif(A:A,A1)<2)

What am I doing wrong?

Also, if a value occurs multiple times, is there a formula to highlight all but the first occurrence?

Body:
Highlight A: if B is greater than 5, C is empty, and D doesn't have a duplicate

apply to range A1:A:

=(B1>5)*(C1="")*(COUNTIF(D:D, D1)<2)

Also, if a value occurs multiple times, is there a formula to highlight all but the first occurrence?

use shorter:

=COUNTIF(A$1:A1, A1)>1

or:

=ARRAYFORMULA(COUNTIFS(A$1:A, A1, ROW(A$1:A), "<="&ROW(A1))>1)


来源: stackexchange

问:
Access page controls in jquery
I have a web application in VS 2008. I used jquery for validation of different Forms and used it for other purposes. In VS 2008 I get the IDs of page controls in jquery like Ctl001_.... , but now I have upgraded the application to VS 2010 and now all my page controls are giving error in jquery because its changed its ID there as ContentBody_....., I can not convert all these to the new prefix ContentBody_.... because on the server my project runs on .Net Framework 3.5 and there the IDs are with the Prefix of Ctl001_....,
can any one tell me a way that I can easily get control's ID in jquery without depending on the .Net Framework.

any help would be greatly appreciated.

答:
You can use ends with selector: http://api.jquery.com/attribute-ends-with-selector/</p>

```<code>jQuery('[id$="_textBox1"]');
</code>```

ContentLicense: CC BY-SA 3.0

Title: Access page controls in jquery

Body:
You can use ends with selector: http://api.jquery.com/attribute-ends-with-selector/

jQuery('[id$="_textBox1"]');


问:
Create columns based on count in data.table
I have a data as below:

```<code>Col1  Col2   Col3  Col4
1     7000     73     6
1     7000     73     7
1     7000     73     8
1     7000     73     9
1     7000     73    10
1     7000     73    11
1     7000     73    12
1     4000    117     6
1     4000    117     9
</code>```

I want to count the number by Col1 and Col2. And then, based on the count to create 5 new columns. I know how to count but how can I create 5 new columns based on the count.

```<code>Col1  Col2   Count   NewCol1  NewCol2  NewCol3  NewCol4  NewCol5
1     7000       7         6        7        8        9       10
1     4000       2         6        9        NA      NA       NA
</code>```

Col3 can be ignored actually.

There is one thing that Count ranges from 1 to more than 5. Therefore, if Count > 5, I do not need to have NewCol6, NewCol7, and etc.

ContentLicense: CC BY-SA 4.0

Body:
I have a data as below:

Col1  Col2   Col3  Col4
1     7000     73     6
1     7000     73     7
1     7000     73     8
1     7000     73     9
1     7000     73    10
1     7000     73    11
1     7000     73    12
1     4000    117     6
1     4000    117     9

I want to count the number by Col1 and Col2. And then, based on the count to create 5 new columns. I know how to count but how can I create 5 new columns based on the count.

Col1  Col2   Count   NewCol1  NewCol2  NewCol3  NewCol4  NewCol5
1     7000       7         6        7        8        9       10
1     4000       2         6        9        NA      NA       NA

Col3 can be ignored actually.

There is one thing that Count ranges from 1 to more than 5. Therefore, if Count > 5, I do not need to have NewCol6, NewCol7, and etc.

Body:
Another data.table option:

DT[, as.list(head(c(Col4, rep(NA_real_, 5L)), 5L)), .(Col1, Col2)]

output:

   Col1 Col2 V1 V2 V3 V4 V5
1:    1 7000  6  7  8  9 10
2:    1 4000  6  9 NA NA NA

data:

library(data.table)
DT <- fread("Col1  Col2   Col3  Col4
1     7000     73     6
1     7000     73     7
1     7000     73     8
1     7000     73     9
1     7000     73    10
1     7000     73    11
1     7000     73    12
1     4000    117     6
1     4000    117     9")


问:
Laravel - How to Customize Datatable for index view blade
I am using Laravel-5.8 for my web application. In it I have a index view blade made with datatable which is derived from these two tables of dynamic input:

```<code>class AppraisalGoal extends Model
{
    protected $table = 'appraisal_goals';
    protected $primaryKey = 'id';

    protected $fillable = [
                  'goal_type_id',
                  'appraisal_identity_id',
                  'employee_id',
                  'company_id',
                  'is_published',
                  'is_approved',
                  'weighted_score',
                  'employee_comment',
                  'line_manager_comment',
                  'goal_title',
                  'appraisal_doc',
                  'appraisal_start_date',
                  'appraisal_end_date',
              ];

    public function goaltype()
    {
        return $this->belongsTo('App\Models\Appraisal\AppraisalGoalType','goal_type_id');
    }

    public function employee()
    {
        return $this->belongsTo('App\Models\Hr\HrEmployee','employee_id');
    }

    public function appraisalidentity()
    {
        return $this->belongsTo('App\Models\Appraisal\AppraisalIdentity','appraisal_identity_id');
    }

    public function appraisalgoaldetail(){
        return $this->hasMany('App\Models\Appraisal\AppraisalGoalDetail');
    }
}

class AppraisalGoalDetail extends Model
{
    protected $table = 'appraisal_goal_details';
    protected $fillable = [
                  'name',
                  'company_id',
                  'appraisal_goal_id',
                  'kpi_description',
                  'appraisal_doc',
                  'activity',
                  'start_date',
                  'end_date',
              ];

    public function appraisalgoal()
    {
        return $this->belongsTo('App\Models\Appraisal\AppraisalGoal');
    }
}
</code>```

Controller

```<code>public function index()
{
    $userEmployee = Auth::user()->employee_id;
    $goals = AppraisalGoal::where('employee_id', $userEmployee)->get();

    return view('appraisal.appraisal_goals.index')->with('goals', $goals);
}
</code>```

Currently, I have this index view blade:

which is derived from:

```<code>    <div class="card-body">
        <div class="table-responsive">
            <table class=" table table-bordered table-striped table-hover datatable">
                <thead>
                    <tr>
                        <th width="10">
                            #
                        </th>
                        <th>
                            Goal Type
                        </th>
                        <th>
                            Goal Title
                        </th>
                        <th>
                            Goal Description
                        </th>
                        <th>
                            Weight
                        </th>
                        <th>
                            Published
                        </th>
                        <th>
                            Approved
                        </th>
                        <th>
                            Line Manager's Comments
                        </th>
                        <th>
                            Start Date
                        </th>
                        <th>
                            End Date
                        </th>
                        <th>
                            Date Added
                        </th>
                        <th>

                        </th>
                    </tr>
                </thead>
                <tbody>
                    @foreach($goals as $key => $goal)
                            <td>
                                {{$key+1}}
                            </td>
                            <td>
                                {{$goal->goaltype->name ?? '' }}
                            </td>
                            <td>
                                {{$goal->goal_title ?? '' }}
                            </td>
                            <td>
                                {{$goal->goal_description ?? '' }}
                            </td>
                            <td>
                                {{$goal->weighted_score ?? '' }}
                            </td>
                            <td>
                                @if ($goal->is_published)
                                    <span class="badge bg-success">Published</span>
                                @else
                                    <span class="badge bg-danger">Pending</span>
                                </a>
                                @endif
                            </td>
                            <td>
                                @if ($goal->is_approved)
                                    <span class="badge bg-success" >Approved</span>
                                @else
                                    <span class="badge bg-danger">Pending</span>
                                @endif
                            </td>
                            <td>
                                {{$goal->line_manager_comment ?? '' }}
                            </td>
                            <td>
                                {{Carbon\Carbon::parse($goal->start_date)->format('d-m-Y') ?? '' }}
                            </td>
                            <td>
                                {{Carbon\Carbon::parse($goal->end_date)->format('d-m-Y') ?? '' }}
                            </td>
                            <td>
                                {{Carbon\Carbon::parse($goal->created_at)->format('d-m-Y') ?? '' }}
                            </td>
                            <td>
                                    @if($goal->is_published == 0)
                                    <a class="btn btn-xs btn-success" data-toggle="modal" data-target="#confirm-publish{{ $goal->id }}" data-original-title="Close">
                                        <span style="color:white;">Publish</span>
                                    </a>
                                    @else
                                        <span class="badge bg-danger">Published</span>
                                    @endif
                                @can('appraisal_goal_show')
                                    <a class="btn btn-xs btn-primary" href="{{ route('appraisal.appraisal_goals.show', $goal->id) }}">
                                        {{ trans('global.view') }}
                                    </a>
                                @endcan
                                @can('appraisal_goal_edit')
                                    <a class="btn btn-xs btn-info" href="{{ route('appraisal.appraisal_goals.edit', ['id'=>$goal->id]) }}">
                                        {{ trans('global.edit') }}
                                    </a>
                                @endcan
                                @can('appraisal_goal_delete')
                                    <a class="btn btn-xs btn-danger" data-toggle="modal" data-target="#confirm-delete{{ $goal->id }}" data-original-title="Close">
                                        <span style="color:white;">{{ trans('global.delete') }}</span>
                                    </a>
                                @endcan
                            </td>
                    </tr>
                    @endforeach
                </tbody>
            </table>
        </div>
    </div>
</code>```

datatable script

    ```

How do I re-write my code to make the index view blade look like the one shown below:

Thank you

答:
Please take a look at my answer on this post, it should give you an idea on how to use rowspans and colspans

How to create dynamic rowspan in table in laravel

Body:
I am using Laravel-5.8 for my web application. In it I have a index view blade made with datatable which is derived from these two tables of dynamic input:

class AppraisalGoal extends Model
{
    protected $table = 'appraisal_goals';
    protected $primaryKey = 'id';

    protected $fillable = [
                  'goal_type_id',
                  'appraisal_identity_id',
                  'employee_id',
                  'company_id',
                  'is_published',
                  'is_approved',
                  'weighted_score',
                  'employee_comment',
                  'line_manager_comment',
                  'goal_title',
                  'appraisal_doc',
                  'appraisal_start_date',
                  'appraisal_end_date',
              ];

    public function goaltype()
    {
        return $this->belongsTo('App\Models\Appraisal\AppraisalGoalType','goal_type_id');
    }

    public function employee()
    {
        return $this->belongsTo('App\Models\Hr\HrEmployee','employee_id');
    }

    public function appraisalidentity()
    {
        return $this->belongsTo('App\Models\Appraisal\AppraisalIdentity','appraisal_identity_id');
    }

    public function appraisalgoaldetail(){
        return $this->hasMany('App\Models\Appraisal\AppraisalGoalDetail');
    }
}

class AppraisalGoalDetail extends Model
{
    protected $table = 'appraisal_goal_details';
    protected $fillable = [
                  'name',
                  'company_id',
                  'appraisal_goal_id',
                  'kpi_description',
                  'appraisal_doc',
                  'activity',
                  'start_date',
                  'end_date',
              ];

    public function appraisalgoal()
    {
        return $this->belongsTo('App\Models\Appraisal\AppraisalGoal');
    }
}

Controller

public function index()
{
    $userEmployee = Auth::user()->employee_id;
    $goals = AppraisalGoal::where('employee_id', $userEmployee)->get();

    return view('appraisal.appraisal_goals.index')->with('goals', $goals);
}

Currently, I have this index view blade:

which is derived from:

                            #

                            Goal Type

                            Goal Title

                            Goal Description

                            Weight

                            Published

                            Approved

                            Line Manager's Comments

                            Start Date

                            End Date

                            Date Added

                    @foreach($goals as $key => $goal)

                                {{$key+1}}

                                {{$goal->goaltype->name ?? '' }}

                                {{$goal->goal_title ?? '' }}

                                {{$goal->goal_description ?? '' }}

                                {{$goal->weighted_score ?? '' }}

                                @if ($goal->is_published)
                                    Published
                                @else
                                    Pending

                                @endif

                                @if ($goal->is_approved)
                                    Approved
                                @else
                                    Pending
                                @endif

                                {{$goal->line_manager_comment ?? '' }}

                                {{Carbon\Carbon::parse($goal->start_date)->format('d-m-Y') ?? '' }}

                                {{Carbon\Carbon::parse($goal->end_date)->format('d-m-Y') ?? '' }}

                                {{Carbon\Carbon::parse($goal->created_at)->format('d-m-Y') ?? '' }}

                                    @if($goal->is_published == 0)
                                    id }}" data-original-title="Close">
                                        Publish

                                    @else
                                        Published
                                    @endif
                                @can('appraisal_goal_show')
                                    id) }}">
                                        {{ trans('global.view') }}

                                @endcan
                                @can('appraisal_goal_edit')
                                    $goal->id]) }}">
                                        {{ trans('global.edit') }}

                                @endcan
                                @can('appraisal_goal_delete')
                                    id }}" data-original-title="Close">
                                        {{ trans('global.delete') }}

                                @endcan

                    @endforeach

datatable script

How do I re-write my code to make the index view blade look like the one shown below:

Thank you


问:
Incorrect cell data display when scrolling UITableView
I am facing some weird problems. Whenever I scroll my table view, my data gets replaced with other cells. Each time, it gets replaced with different cell data. I am not seeing any particular pattern in this replacement.</p>

答:
```<code>cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:nil] autorelease];
</code>```


问:
rake aborted! Don't know how to build task 'snorby:setup'
I am trying to install snorby on my ubuntu 16.04 Desktop, But when I run RAILS_ENV=production bundle exec rake snorby:setup. I get the error rake aborted! Don't know how to build task 'snorby:setup'. Somebody can help me resolve the issue? Thanks veryy muchhhhh.
and this my 'Gamefile'

UPDATE : Upload my RAILS_ENV=production bundle exec rake -vT and file /lib/tasks/snorby.rake

```<code>source 'https://rubygems.org'

RAILS_VERSION = '3.2.22'
RSPEC_VERSION = '~> 2.0.0'
DATAMAPPER    = 'https://github.com/datamapper'
DM_VERSION    = '~> 1.2.0'

gem 'rubocop', require: false ## This is not the original gamefile, I added this gamefile to another package, which is rubocop. because before I get the message "Rake Aborted: needed Rubocop / task_file. You can notice" gem 'rubocop', require: false"

gem 'rake', '0.9.2'
gem 'request_store', '~> 1.0.5'
gem 'rails',                       RAILS_VERSION
gem 'jquery-rails'
gem 'bundler',                     '>= 1.0.0'
gem 'env'
gem 'json', '~> 1.8.3'

# Jruby
gem 'jruby-openssl',               :platforms => :jruby
gem 'warbler',                     :platforms => :jruby
gem 'jruby-rack-worker',           :platforms => :jruby
# gem 'glassfish', :platforms => :jruby

# DateTime Patches
gem 'home_run',                    :require => 'date', :platforms => :mri

gem 'activesupport',               RAILS_VERSION, :require => 'active_support'
gem 'actionpack',                  RAILS_VERSION, :require => 'action_pack'
gem 'actionmailer',                RAILS_VERSION, :require => 'action_mailer'
gem 'railties',                    RAILS_VERSION, :require => 'rails'
gem 'dm-core',                     DM_VERSION
gem 'dm-rails',                    DM_VERSION
gem 'dm-do-adapter',               DM_VERSION
gem 'dm-active_model',             DM_VERSION
gem 'dm-mysql-adapter',            DM_VERSION
gem 'dm-postgres-adapter',         DM_VERSION

gem 'dm-pager',                    '~> 1.1.0'
gem "dm-ar-finders",               DM_VERSION
gem 'dm-migrations',               DM_VERSION
gem 'dm-types',                    DM_VERSION
gem 'dm-validations',              DM_VERSION
gem 'dm-constraints',              DM_VERSION
gem 'dm-transactions',             DM_VERSION
gem 'dm-aggregates',               DM_VERSION
gem 'dm-timestamps',               DM_VERSION
gem 'dm-observer',                 DM_VERSION
gem 'dm-serializer',               DM_VERSION
gem 'dm-is-read_only',             '~> 0.3', :git => 'https://github.com/postmodern/dm-is-read_only.git'
gem 'dm-chunked_query',            '~> 0.3'

# Deploy with Capistrano
gem 'capistrano',                  '2.14.1'

# Rails Plugins
gem 'jammit',                      '~> 0.5.4'
gem 'cancan',                      '~> 1.6'
gem 'devise',                      '~> 1.4'
gem 'dm-devise',                   '~> 1.5'
gem 'rubycas-client'
gem 'devise_cas_authenticatable'
gem "mail",                        '~> 2.3'
gem "RedCloth",                    "~> 4.2.9", :require => 'redcloth'
gem 'chronic',                     '~> 0.3.0'
gem 'pdfkit',                      '~> 0.4.6'
gem 'ezprint',                     :git => 'https://github.com/mephux/ezprint.git', :branch => 'rails3', :require => 'ezprint'
gem 'daemons',                     '~> 1.1.0'

gem 'delayed_job',                 '~> 2.1.4'
gem 'delayed_job_data_mapper',     '~> 1.0.0.rc', :git => 'https://github.com/Snorby/delayed_job_data_mapper.git'

# Working On This
# gem 'delayed_job',                 '~> 3.0'
# gem 'delayed_job_data_mapper',     '~> 1.0.0.rc', :git => 'https://github.com/collectiveidea/delayed_job_data_mapper.git'

# Old - Remove Avatar Support
# gem 'rmagick',                     '~> 2.13.1'
# gem 'dm-paperclip',                '~> 2.4.1', :git => 'https://github.com/Snorby/dm-paperclip.git'

gem 'net-dns',                     '~> 0.8.0'
gem 'whois',                       '~> 2.3.0'
gem 'simple_form',                 '~> 1.2.2'
gem 'geoip',                       '~> 1.1.1'
gem 'netaddr',                     '~> 1.5.0'
gem 'dm-zone-types',               '~> 0.3'
gem 'timezone_local',              '~> 0.1.5'

group(:development) do
  gem "letter_opener"
  gem 'thin'
  gem 'byebug'
end

group(:test) do
  gem 'capybara'
  gem 'test-unit'
  gem 'rspec',                    RSPEC_VERSION
  gem 'rspec-core',               RSPEC_VERSION, :require => 'rspec/core'
  gem 'rspec-expectations',       RSPEC_VERSION, :require => 'rspec/expectations'
  gem 'rspec-rails',                  RSPEC_VERSION
  gem 'ansi'
  gem 'turn'
  gem 'minitest'
end

group(:doc) do
  gem 'dm-visualizer',  '~> 0.1.0'
end
</code>```

This is not the original gamefile, I added this gamefile to another package, which is rubocop. because before I get the message "Rake Aborted: needed Rubocop / task_file. You can notice" gem 'rubocop', require: false"

```<code># Snorby - All About Simplicity.
#
# Copyright (c) 2012 Dustin Willis Webber (dustin.webber at gmail.com)
#
# Snorby is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Foobar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

require "./lib/snorby/dm/types"
require "./lib/snorby/jobs"
require "./lib/snorby/worker"

namespace :snorby do

  desc 'Setup'
  task :setup => :environment do

    Rake::Task['secret'].invoke

    # Create the snorby database if it does not currently exist
    Rake::Task['db:create'].invoke

    # Snorby update logic
    Rake::Task['snorby:update'].invoke
  end

  desc 'Update Snorby'
  task :update => :environment do

    # Setup the snorby database
    Rake::Task['db:autoupgrade'].invoke

    # Load Default Records
    Rake::Task['db:seed'].invoke

    # Restart Worker
    Rake::Task['snorby:restart_worker'].invoke
  end

  desc 'Update Snorby DB'
  task :dbupdate => :environment do

    # Setup the snorby database
    Rake::Task['db:autoupgrade'].invoke

    # Load Default Records
    Rake::Task['db:seed'].invoke
  end

  desc 'Remove Old CSS/JS packages and re-bundle'
  task :refresh => :environment do
    `jammit`
  end

  desc 'Start Snorby Worker if not running'
  task :start_worker => :environment do

    if Snorby::Worker.running?
      exit 0
    end

    # otherwise, restart worker.
    Rake::Task['snorby:restart_worker'].invoke
  end

  desc 'Restart Worker/Jobs'
  task :restart_worker => :environment do

    if Snorby::Worker.running?
      puts '* Stopping the Snorby worker process.'
      Snorby::Worker.stop
    end

    count = 0
    stopped = false
    while !stopped

      stopped = true unless Snorby::Worker.running?
      sleep 5

      count += 1
      if count > 10
        STDERR.puts "[X] Error: Unable to stop the Snorby worker process."
        exit -1
      end
    end

    unless Snorby::Worker.running?
      puts "* Removing old jobs"
      Snorby::Jobs.find.all.destroy

      puts "* Starting the Snorby worker process."
      Snorby::Worker.start

      count = 0
      ready = false
      while !ready

        ready = true if Snorby::Worker.running?
        sleep 5

        count += 1
        if count > 10
          ready  = true
        end
      end

      if Snorby::Worker.running?
        Snorby::Jobs.find.all.destroy
        puts "* Adding jobs to the queue"
        Snorby::Jobs.run_now!
      else
        STDERR.puts "[X] Error: Unable to start the Snorby worker process."
        exit -1
      end
    end

  end

  desc 'Soft Reset - Reset Snorby metrics'
  task :soft_reset => :environment do

    # Reset Counter Cache Columns
    puts 'Reseting Snorby metrics and counter cache columns'
    Severity.update!(:events_count => 0)
    Sensor.update!(:events_count => 0)
    Signature.update!(:events_count => 0)

    puts 'This could take awhile. Please wait while the Snorby cache is rebuilt.'
    Snorby::Jobs.reset_cache(:all, true)
  end

  desc 'Hard Reset - Rebuild Snorby Database'
  task :hard_reset => :environment do

    # Drop the snorby database if it exists
    Rake::Task['db:drop'].invoke

    # Invoke the snorby:setup rake task
    Rake::Task['snorby:setup'].invoke

  end

end
</code>```

This file /lib/tasks/snorby.rake

This image output :

RAILS_ENV=production bundle exec rake snorby:setup

RAILS_ENV=production bundle exec rake -vT

EDIT : SOLVED My Problem.
you must install :

gem install bundler -v 1.17.1
gem install rails -v 4.2.2
gem install sprockets -v 3.7.2
gem install rake --version=0.9.2

or if you wanna install Suricata, Snorby, and barnyard2. I suggestion you follow this : guide install

答:
It most likely that you have install the Snorby to a specific environments,

please copy/paste your 'Gemfile', so we can have a look.

You can also list all rake tasks in production environment by

```<code>RAILS_ENV=production bundle exec rake -vT
</code>```

UPDATE:

Snorby seems to be a standalone web application, so the rake task is defined as any other custom rake tasks

You should be able to find a lib/tasks/snorby.rake file, If not I recommend you to re-download the repo from: https://github.com/Snorby/snorby/snorby, and follow the instructions in README.md

Another update:
This project seems stop updating since Nov 13, 2017, with 122 issues remain opening, I personally would not use this project for network security monitoring.

Body:
I am trying to install snorby on my ubuntu 16.04 Desktop, But when I run RAILS_ENV=production bundle exec rake snorby:setup. I get the error rake aborted! Don't know how to build task 'snorby:setup'. Somebody can help me resolve the issue? Thanks veryy muchhhhh.
and this my 'Gamefile'

UPDATE : Upload my RAILS_ENV=production bundle exec rake -vT and file /lib/tasks/snorby.rake

source 'https://rubygems.org'

RAILS_VERSION = '3.2.22'
RSPEC_VERSION = '~> 2.0.0'
DATAMAPPER    = 'https://github.com/datamapper'
DM_VERSION    = '~> 1.2.0'

gem 'rubocop', require: false ## This is not the original gamefile, I added this gamefile to another package, which is rubocop. because before I get the message "Rake Aborted: needed Rubocop / task_file. You can notice" gem 'rubocop', require: false"

gem 'rake', '0.9.2'
gem 'request_store', '~> 1.0.5'
gem 'rails',                       RAILS_VERSION
gem 'jquery-rails'
gem 'bundler',                     '>= 1.0.0'
gem 'env'
gem 'json', '~> 1.8.3'

# Jruby
gem 'jruby-openssl',               :platforms => :jruby
gem 'warbler',                     :platforms => :jruby
gem 'jruby-rack-worker',           :platforms => :jruby
# gem 'glassfish', :platforms => :jruby

# DateTime Patches
gem 'home_run',                    :require => 'date', :platforms => :mri

gem 'activesupport',               RAILS_VERSION, :require => 'active_support'
gem 'actionpack',                  RAILS_VERSION, :require => 'action_pack'
gem 'actionmailer',                RAILS_VERSION, :require => 'action_mailer'
gem 'railties',                    RAILS_VERSION, :require => 'rails'
gem 'dm-core',                     DM_VERSION
gem 'dm-rails',                    DM_VERSION
gem 'dm-do-adapter',               DM_VERSION
gem 'dm-active_model',             DM_VERSION
gem 'dm-mysql-adapter',            DM_VERSION
gem 'dm-postgres-adapter',         DM_VERSION

gem 'dm-pager',                    '~> 1.1.0'
gem "dm-ar-finders",               DM_VERSION
gem 'dm-migrations',               DM_VERSION
gem 'dm-types',                    DM_VERSION
gem 'dm-validations',              DM_VERSION
gem 'dm-constraints',              DM_VERSION
gem 'dm-transactions',             DM_VERSION
gem 'dm-aggregates',               DM_VERSION
gem 'dm-timestamps',               DM_VERSION
gem 'dm-observer',                 DM_VERSION
gem 'dm-serializer',               DM_VERSION
gem 'dm-is-read_only',             '~> 0.3', :git => 'https://github.com/postmodern/dm-is-read_only.git'
gem 'dm-chunked_query',            '~> 0.3'

# Deploy with Capistrano
gem 'capistrano',                  '2.14.1'

# Rails Plugins
gem 'jammit',                      '~> 0.5.4'
gem 'cancan',                      '~> 1.6'
gem 'devise',                      '~> 1.4'
gem 'dm-devise',                   '~> 1.5'
gem 'rubycas-client'
gem 'devise_cas_authenticatable'
gem "mail",                        '~> 2.3'
gem "RedCloth",                    "~> 4.2.9", :require => 'redcloth'
gem 'chronic',                     '~> 0.3.0'
gem 'pdfkit',                      '~> 0.4.6'
gem 'ezprint',                     :git => 'https://github.com/mephux/ezprint.git', :branch => 'rails3', :require => 'ezprint'
gem 'daemons',                     '~> 1.1.0'

gem 'delayed_job',                 '~> 2.1.4'
gem 'delayed_job_data_mapper',     '~> 1.0.0.rc', :git => 'https://github.com/Snorby/delayed_job_data_mapper.git'

# Working On This
# gem 'delayed_job',                 '~> 3.0'
# gem 'delayed_job_data_mapper',     '~> 1.0.0.rc', :git => 'https://github.com/collectiveidea/delayed_job_data_mapper.git'

# Old - Remove Avatar Support
# gem 'rmagick',                     '~> 2.13.1'
# gem 'dm-paperclip',                '~> 2.4.1', :git => 'https://github.com/Snorby/dm-paperclip.git'

gem 'net-dns',                     '~> 0.8.0'
gem 'whois',                       '~> 2.3.0'
gem 'simple_form',                 '~> 1.2.2'
gem 'geoip',                       '~> 1.1.1'
gem 'netaddr',                     '~> 1.5.0'
gem 'dm-zone-types',               '~> 0.3'
gem 'timezone_local',              '~> 0.1.5'

group(:development) do
  gem "letter_opener"
  gem 'thin'
  gem 'byebug'
end

group(:test) do
  gem 'capybara'
  gem 'test-unit'
  gem 'rspec',                    RSPEC_VERSION
  gem 'rspec-core',               RSPEC_VERSION, :require => 'rspec/core'
  gem 'rspec-expectations',       RSPEC_VERSION, :require => 'rspec/expectations'
  gem 'rspec-rails',                  RSPEC_VERSION
  gem 'ansi'
  gem 'turn'
  gem 'minitest'
end

group(:doc) do
  gem 'dm-visualizer',  '~> 0.1.0'
end

This is not the original gamefile, I added this gamefile to another package, which is rubocop. because before I get the message "Rake Aborted: needed Rubocop / task_file. You can notice" gem 'rubocop', require: false"

# Snorby - All About Simplicity.
#
# Copyright (c) 2012 Dustin Willis Webber (dustin.webber at gmail.com)
#
# Snorby is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# Foobar is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with Foobar.  If not, see <http://www.gnu.org/licenses/>.

require "./lib/snorby/dm/types"
require "./lib/snorby/jobs"
require "./lib/snorby/worker"

namespace :snorby do

  desc 'Setup'
  task :setup => :environment do

    Rake::Task['secret'].invoke

    # Create the snorby database if it does not currently exist
    Rake::Task['db:create'].invoke

    # Snorby update logic
    Rake::Task['snorby:update'].invoke
  end

  desc 'Update Snorby'
  task :update => :environment do

    # Setup the snorby database
    Rake::Task['db:autoupgrade'].invoke

    # Load Default Records
    Rake::Task['db:seed'].invoke

    # Restart Worker
    Rake::Task['snorby:restart_worker'].invoke
  end

  desc 'Update Snorby DB'
  task :dbupdate => :environment do

    # Setup the snorby database
    Rake::Task['db:autoupgrade'].invoke

    # Load Default Records
    Rake::Task['db:seed'].invoke
  end

  desc 'Remove Old CSS/JS packages and re-bundle'
  task :refresh => :environment do
    `jammit`
  end

  desc 'Start Snorby Worker if not running'
  task :start_worker => :environment do

    if Snorby::Worker.running?
      exit 0
    end

    # otherwise, restart worker.
    Rake::Task['snorby:restart_worker'].invoke
  end

  desc 'Restart Worker/Jobs'
  task :restart_worker => :environment do

    if Snorby::Worker.running?
      puts '* Stopping the Snorby worker process.'
      Snorby::Worker.stop
    end

    count = 0
    stopped = false
    while !stopped

      stopped = true unless Snorby::Worker.running?
      sleep 5

      count += 1
      if count > 10
        STDERR.puts "[X] Error: Unable to stop the Snorby worker process."
        exit -1
      end
    end

    unless Snorby::Worker.running?
      puts "* Removing old jobs"
      Snorby::Jobs.find.all.destroy

      puts "* Starting the Snorby worker process."
      Snorby::Worker.start

      count = 0
      ready = false
      while !ready

        ready = true if Snorby::Worker.running?
        sleep 5

        count += 1
        if count > 10
          ready  = true
        end
      end

      if Snorby::Worker.running?
        Snorby::Jobs.find.all.destroy
        puts "* Adding jobs to the queue"
        Snorby::Jobs.run_now!
      else
        STDERR.puts "[X] Error: Unable to start the Snorby worker process."
        exit -1
      end
    end

  end

  desc 'Soft Reset - Reset Snorby metrics'
  task :soft_reset => :environment do

    # Reset Counter Cache Columns
    puts 'Reseting Snorby metrics and counter cache columns'
    Severity.update!(:events_count => 0)
    Sensor.update!(:events_count => 0)
    Signature.update!(:events_count => 0)

    puts 'This could take awhile. Please wait while the Snorby cache is rebuilt.'
    Snorby::Jobs.reset_cache(:all, true)
  end

  desc 'Hard Reset - Rebuild Snorby Database'
  task :hard_reset => :environment do

    # Drop the snorby database if it exists
    Rake::Task['db:drop'].invoke

    # Invoke the snorby:setup rake task
    Rake::Task['snorby:setup'].invoke

  end

end

This file /lib/tasks/snorby.rake

This image output :

RAILS_ENV=production bundle exec rake snorby:setup

RAILS_ENV=production bundle exec rake -vT

EDIT : SOLVED My Problem.
you must install :

gem install bundler -v 1.17.1
gem install rails -v 4.2.2
gem install sprockets -v 3.7.2
gem install rake --version=0.9.2

or if you wanna install Suricata, Snorby, and barnyard2. I suggestion you follow this : guide install

Body:
It most likely that you have install the Snorby to a specific environments,

please copy/paste your 'Gemfile', so we can have a look.

You can also list all rake tasks in production environment by

RAILS_ENV=production bundle exec rake -vT

UPDATE:

Snorby seems to be a standalone web application, so the rake task is defined as any other custom rake tasks

You should be able to find a lib/tasks/snorby.rake file, If not I recommend you to re-download the repo from: https://github.com/Snorby/snorby/snorby, and follow the instructions in README.md

Another update:
This project seems stop updating since Nov 13, 2017, with 122 issues remain opening, I personally would not use this project for network security monitoring.


答:
The AND function requires additional brackets:

```<code>=AND((b:b>5),(isblank(c:c)),(countif(A:A,A1)<2))
</code>```

Title: Using AND with multiple conditions for formatting google sheets/excel

Body:
The AND function requires additional brackets:

=AND((b:b>5),(isblank(c:c)),(countif(A:A,A1)<2))


问:
What does "<bound method str.<native JS> of 's'>" mean?
(I'm using the website trinket.io because that is the only python website that isn't blocked at my school.)

I am trying to create a game with 2 different gamemodes. My code to get the gamemode is

```<code>gm = str(input("What gamemode do you want to play on? ([N]ormal or [S]udden Death)"))
gm = gm.lower
</code>```

If I try to run print(gm), it will print <bound method str.<native JS> of 's'> (Assuming you typed s in the input.)

Edit: All I had to do was add a () to the end of the gm.lower.

答:
change it to

```<code>gm = gm.lower()
</code>```

gm.lower is the method itself not the resulting string of the lower method of the str

Body:
(I'm using the website trinket.io because that is the only python website that isn't blocked at my school.)

I am trying to create a game with 2 different gamemodes. My code to get the gamemode is

gm = str(input("What gamemode do you want to play on? ([N]ormal or [S]udden Death)"))
gm = gm.lower

If I try to run print(gm), it will print <bound method str.<native JS> of 's'> (Assuming you typed s in the input.)

Edit: All I had to do was add a () to the end of the gm.lower.

Body:
change it to

gm = gm.lower()

gm.lower is the method itself not the resulting string of the lower method of the str


问:
Nesting  list items within list items of an Ordered List ?
I am attempting to figure out how to create an incremented ordered list currently aimed towards IE6 and IE7.

E.G. It should render something like below:

```<code>1.0
    1.1
    1.2
    1.3
2.0
    2.1
    2.2
</code>```

From what I understand, this is possible to create in CSS with something like this:

```<code>UL, OL { counter-reset: item; }
LI { display: block }
LI:before { content: counters(item, "."); counter-increment: item }
</code>```

However, of course, IE6 and IE7 don't support this.

What options are available to create a proper incremented list in IE6/7? Am I stuck having to hard code this.? Unfortunately, using JavaScript is not an option.

Are there any updated methodologies for newer browsers?

答: If javascript is not an option (and therefore also I assume no flash), I'm sorry to say you're out of options for a client-side solution. If you have a server-side script that is generating your HTML, you can push the ordering to the server and simply style the output on the client using CSS as an unordered-list with no bullet. IE6 is your limiting factor here, and there aren't many ways around that. Sorry to be the bearer of bad news.</p>

OwnerDisplayName: Martin M

Body:
I am attempting to figure out how to create an incremented ordered list currently aimed towards IE6 and IE7.

E.G. It should render something like below:

1.0
    1.1
    1.2
    1.3
2.0
    2.1
    2.2

From what I understand, this is possible to create in CSS with something like this:

UL, OL { counter-reset: item; }
LI { display: block }
LI:before { content: counters(item, "."); counter-increment: item }

However, of course, IE6 and IE7 don't support this.

What options are available to create a proper incremented list in IE6/7? Am I stuck having to hard code this.? Unfortunately, using JavaScript is not an option.

Are there any updated methodologies for newer browsers?

LastEditorDisplayName: Andrew Hare

OwnerDisplayName: Jarret Hardie

ContentLicense: CC BY-SA 2.5


问:
can we use order by clause with group by
Hi
   I am using following query --

```<code>select * from table_name order by status desc
</code>```

It shows the desired result with all records,but as n when i use following query -

```<code>select * from table_name group by category order by status desc
</code>```

It shows only 2 records of distinct category with sorted order.

Is it because i am using order by with group by.....

答:
It is confusing, because normally you would only be able to select fields and order by fields that are also in your group by.

MySQL does that differently and allows you in certain cases to order by fields that are not in the group by. These fields (status, in this case) are implicitly added to the group by. So you're actually grouping by category and status.

Body:
Hi
   I am using following query --

select * from table_name order by status desc

It shows the desired result with all records,but as n when i use following query -

select * from table_name group by category order by status desc

It shows only 2 records of distinct category with sorted order.

Is it because i am using order by with group by.....


问:
Sending emails for new user in Active Directory
I have created a trial account for Microsoft Azure. In Azure Active Directory, I'm trying to create a new user. Is there any way to notify this user via e-mail? Is there any way to send the email to user from Azure AD?</p>

答:
If you create new guest users, they will be notified with e-mail. If you add tenant users from the portal, they will have no email association.

Reference:

What is guest user in Azure AD?


问:
How to update multiple elements for each data
There are a lot of articles about how to update dom for each data. But what if I want to update multiple dom nodes for each data.

For example, for each data, generate div and span according to the number in the data.

```<code>[
  [1, 2],
  [2, 1],
]
</code>```

I want to yield like

```<code><div class="data">
  <div>1</div><span>2</span><span>2</span>
</div>
<div class="data">
  <div>2</div><div>2</div><span>1</span>
</div>
</code>```

Should start with

```<code>const selection = d3.selectAll("div.data");
selection.exit().remove();
selection.enter().append("div").attr("class", "data").merge(selection);
// Then I don't know how to add multiple dom according to the data value.
</code>```

答:
First of all, your question's title ("how to update multiple elements for each data") suggests that you want to update those elements, when in fact, by reading your actual question, you just want to create them (enter, in D3 lingo). Also, pay attention to the fact that you cannot use data() following d3.selectAll().

That being said, there are several solutions. One of them is using each() for your outer divs, and then appending how many elements you want (divs or spans) by using d3.range(), which will create an array whose length is based on the number you pass to it. The actual content of that array is irrelevant, since the text in both divs and spans correspond to the numbers in the inner arrays.

Here is a simple example, pay attention to the colors for each element (outer divs, inner divs and spans):

const body = d3.select("body");
const data = [
  [1, 2],
  [2, 1],
];
const dataDiv = body.selectAll(null)
  .data(data)
  .enter()
  .append("div")
  .attr("class", "data")
  .each(function(d) {
    d3.select(this).selectAll(null)
      .data(d3.range(d[0]))
      .enter()
      .append("div")
      .attr("class", "innerDiv")
      .html(d[0]);
    d3.select(this).selectAll(null)
      .data(d3.range(d[1]))
      .enter()
      .append("span")
      .html(d[1]);
  })```
<pre class="snippet-code-css lang-css prettyprint-override"><code>.data {
  margin: 10px;
  padding: 2px;
  display: inline-block;
  background-color: wheat;
}

.innerDiv {
  margin: 10px;
  padding: 2px;
  display: inline-block;
  background-color: yellowgreen;
}

span {
  margin: 10px;
  padding: 2px;
  background-color: salmon;
}</code>```

```
</div>
</div>
</p>

<p>And here is the generated HTML:</p>

```

1
22

2

2
1

```

Body:
There are a lot of articles about how to update dom for each data. But what if I want to update multiple dom nodes for each data.

For example, for each data, generate div and span according to the number in the data.

[
  [1, 2],
  [2, 1],
]

I want to yield like

1
22

2

2
1

Should start with

const selection = d3.selectAll("div.data");
selection.exit().remove();
selection.enter().append("div").attr("class", "data").merge(selection);
// Then I don't know how to add multiple dom according to the data value.

Body:
First of all, your question's title ("how to update multiple elements for each data") suggests that you want to update those elements, when in fact, by reading your actual question, you just want to create them (enter, in D3 lingo). Also, pay attention to the fact that you cannot use data() following d3.selectAll().

That being said, there are several solutions. One of them is using each() for your outer divs, and then appending how many elements you want (divs or spans) by using d3.range(), which will create an array whose length is based on the number you pass to it. The actual content of that array is irrelevant, since the text in both divs and spans correspond to the numbers in the inner arrays.

Here is a simple example, pay attention to the colors for each element (outer divs, inner divs and spans):

const body = d3.select("body");
const data = [
  [1, 2],
  [2, 1],
];
const dataDiv = body.selectAll(null)
  .data(data)
  .enter()
  .append("div")
  .attr("class", "data")
  .each(function(d) {
    d3.select(this).selectAll(null)
      .data(d3.range(d[0]))
      .enter()
      .append("div")
      .attr("class", "innerDiv")
      .html(d[0]);
    d3.select(this).selectAll(null)
      .data(d3.range(d[1]))
      .enter()
      .append("span")
      .html(d[1]);
  })

.data {
  margin: 10px;
  padding: 2px;
  display: inline-block;
  background-color: wheat;
}

.innerDiv {
  margin: 10px;
  padding: 2px;
  display: inline-block;
  background-color: yellowgreen;
}

span {
  margin: 10px;
  padding: 2px;
  background-color: salmon;
}

<script src="https://cdnjs.cloudflare.com/ajax/libs/d3/5.7.0/d3.min.js"></script>

And here is the generated HTML:

<div class="data">
  <div class="innerDiv">1</div><span>2</span><span>2</span>
</div>
<div class="data">
  <div class="innerDiv">2</div>
  <div class="innerDiv">2</div><span>1</span>
</div>


问:
In java, can i use string split to split by character?
For instance, I have the String variable abbaabbbba. I would like to use String split so each character would be separated, so it would be {a,b,b,a,a,b,b,b,b,a}. All the instructions I can find for string split say i need to have something, like a a space:

String mySplit = str.split("/");

Is there anyway to do this by character?

答:
You can use the toCharArray method like this:</p>

```<code>String myString = "abbaabbbba";
char[] myCharacters = myString.toCharArray();
</code>```

Body:
You can use the toCharArray method like this:

String myString = "abbaabbbba";
char[] myCharacters = myString.toCharArray();


问:
Angular | Bootstrap - Modal not showing

      <button type="button" class="close" (click)="toggleModal()">×</button>

```

<p>Above is my html, nothing happens when I click on the image that I am using as my modal trigger. This started when I add the ngIf="isModalShowing" function. Below is my typescript.</p>

```import { Component, OnInit, ViewChild } from '@angular/core';
import { NgModule } from '@angular/core';

@Component({
  selector: 'app-portfolio',
  templateUrl: './portfolio.component.html',
  styleUrls: ['./portfolio.component.scss']
})
export class PortfolioComponent implements OnInit {

  constructor() { }

  public ngOnInit() {

  }

  isModalShowing: boolean;

  toggleModal() {
    this.isModalShowing = !this.isModalShowing;
  }

}
```

答:
This might help you as you are using pure bootstrap.

pay attention to [ngClass] in app.component.html file

I added modal-backdrop class to the class list that gives a visual indication of an active modal.

https://stackblitz.com/edit/angular-jggbzx

Or else use ng-bootstrap that has better ways of doing this

Documentation

https://ng-bootstrap.github.io/#/components/modal/examples

Running Example

https://stackblitz.com/edit/angular-dwqv1u

Title: Angular | Bootstrap - Modal not showing

Body:
      <button type="button" class="close" (click)="toggleModal()">×</button>

Above is my html, nothing happens when I click on the image that I am using as my modal trigger. This started when I add the ngIf="isModalShowing" function. Below is my typescript.

import { Component, OnInit, ViewChild } from '@angular/core';
import { NgModule } from '@angular/core';

@Component({
  selector: 'app-portfolio',
  templateUrl: './portfolio.component.html',
  styleUrls: ['./portfolio.component.scss']
})
export class PortfolioComponent implements OnInit {

  constructor() { }

  public ngOnInit() {

  }

  isModalShowing: boolean;

  toggleModal() {
    this.isModalShowing = !this.isModalShowing;
  }

}


问:
RadWindow: Opening windows from C#
Need to open a webpage in a radWindow from a button click event. Attempted to do this from client side but, it appears and then immediately disappears. I Think the button click is causing a postback to the server... Therefore, I'm currently attempting to solve this issue with server side code (C#) posted below.

Problem: Need to open rad windows without adding them to the window collection or remove them from the window collection on close. They aren't being removed from the window collection on closing of the rad window. This results in the same window opening for the number of times the new button is pressed. First click opens one window, the second time the new button is clicked two windows open, etc... Any ideas?

C# - Multiple pages opening

```<code>    RadWindow newWindow = new RadWindow();
    newWindow.NavigateUrl = "WebPage.aspx";
    newWindow.Top = Unit.Pixel(22);
    newWindow.VisibleOnPageLoad = true;
    newWindow.Modal = true;
    newWindow.Left = Unit.Pixel(0);
    newWindow.Height = 530;
    newWindow.Width = 1000;
    winMgr.Windows.Add(newWindow);
</code>```

JavaScript - Post Back issue? Page opens and immediately disappears.

```<code>    var oManager = '<%=winMgr.ClientID %>';
    var oManager = window.radopen("WebPage.aspx", null);
    oManager.setSize(1000, 530); //Width, Height
    oManager.center();
    oManager.SetActive();
</code>```

Thanks for your help!

答:
First - the basics :)
Do you want to open the RadWindow on the client (via JavaScript) or on the server?

Case 1 - on the client: Alison is right - if you want to open the RadWindow on the client (and there is no server-side event hooked to that postback element), you need to cancel the postback. This is done either by using
OnClientClick="return myFunction();" and "return false;" at the end of the function itself (like Alison suggested), or:

OnClientClick="myFynction(); return false;"

When the client click is cancelled, there should be no postback.

Case 2 - on the server: RadWindow is shown from the server by setting VisibleOnPageLoad to true. Note that the RadWindow / RadWindowManager however, keeps their state across postbacks, that includes all server-side properties, including VisibleOnPageLoad. This being said, if you want to show RadWindow only once, you need to also set EnableViewState=false for the RadWindowManager that you are using.

Title: RadWindow: Opening windows from C#

Body:
Need to open a webpage in a radWindow from a button click event. Attempted to do this from client side but, it appears and then immediately disappears. I Think the button click is causing a postback to the server... Therefore, I'm currently attempting to solve this issue with server side code (C#) posted below.

Problem: Need to open rad windows without adding them to the window collection or remove them from the window collection on close. They aren't being removed from the window collection on closing of the rad window. This results in the same window opening for the number of times the new button is pressed. First click opens one window, the second time the new button is clicked two windows open, etc... Any ideas?

C# - Multiple pages opening

    RadWindow newWindow = new RadWindow();
    newWindow.NavigateUrl = "WebPage.aspx";
    newWindow.Top = Unit.Pixel(22);
    newWindow.VisibleOnPageLoad = true;
    newWindow.Modal = true;
    newWindow.Left = Unit.Pixel(0);
    newWindow.Height = 530;
    newWindow.Width = 1000;
    winMgr.Windows.Add(newWindow);

JavaScript - Post Back issue? Page opens and immediately disappears.

    var oManager = '<%=winMgr.ClientID %>';
    var oManager = window.radopen("WebPage.aspx", null);
    oManager.setSize(1000, 530); //Width, Height
    oManager.center();
    oManager.SetActive();

Thanks for your help!


问:
Flex box grid that fits to parent
I'm trying to have a list of items that wrap to the container size. I want the container to have a different background colour than the page background.

The code below isn't doing what I want.

An image is going to say so much more. This is what I'm after:

body {
  background-color: grey;
  margin: 0;
  font-family: Arial;
}

.text { color: white; }

.wrapper {
  display: flex;
  justify-content: center;
}

.content {
  padding: 10px;
  background-color: green;
}

.listings {
  display: flex;
  flex-flow: row wrap;
  justify-content: flex-start;
}

.item {
  width: 100px;
  padding: 15px;
  height: 100px;
  background-color: lightblue;
  border: 1px solid black;
  margin: 15px;
} ```
<pre class="snippet-code-html lang-html prettyprint-override"><code><body>
  <div class="wrapper">
    <div class="content">
      <div class="text">Just some text that should wrap and resize. More text blah blah.</div>
      <div class="listings">
        <div class="item">Listing 1</div>
        <div class="item">Listing 2</div>
        <div class="item">Listing 3</div>
        <div class="item">Listing 4</div>
        <div class="item">Listing 5</div>
      </div>
    </div>
  </div>
</body></code>```

答:
If it's a grid layout, why not just use grid instead?

body {
  background-color: grey;
  margin: 0;
  font-family: Arial;
}

.text { color: white; }

.wrapper {
  display: flex;
  justify-content: center;
}

.content {
  padding: 10px;
  background-color: green;
}

.listings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.item {
  padding: 15px;
  height: 100px;
  background-color: lightblue;
  border: 1px solid black;
  margin: 15px;
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><body>
  <div class="wrapper">
    <div class="content">
      <div class="text">Just some text that should wrap and resize. More text blah blah.</div>
      <div class="listings">
        <div class="item">Listing 1</div>
        <div class="item">Listing 2</div>
        <div class="item">Listing 3</div>
        <div class="item">Listing 4</div>
        <div class="item">Listing 5</div>
      </div>
    </div>
  </div>
</body></code>```

Title: Flex box grid that fits to parent

Body:
I'm trying to have a list of items that wrap to the container size. I want the container to have a different background colour than the page background.

The code below isn't doing what I want.

An image is going to say so much more. This is what I'm after:

body {
  background-color: grey;
  margin: 0;
  font-family: Arial;
}

.text { color: white; }

.wrapper {
  display: flex;
  justify-content: center;
}

.content {
  padding: 10px;
  background-color: green;
}

.listings {
  display: flex;
  flex-flow: row wrap;
  justify-content: flex-start;
}

.item {
  width: 100px;
  padding: 15px;
  height: 100px;
  background-color: lightblue;
  border: 1px solid black;
  margin: 15px;
}

Just some text that should wrap and resize. More text blah blah.

Listing 1

Listing 2

Listing 3

Listing 4

Listing 5

Body:
If it's a grid layout, why not just use grid instead?

body {
  background-color: grey;
  margin: 0;
  font-family: Arial;
}

.text { color: white; }

.wrapper {
  display: flex;
  justify-content: center;
}

.content {
  padding: 10px;
  background-color: green;
}

.listings {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
}

.item {
  padding: 15px;
  height: 100px;
  background-color: lightblue;
  border: 1px solid black;
  margin: 15px;
}

<body>
  <div class="wrapper">
    <div class="content">
      <div class="text">Just some text that should wrap and resize. More text blah blah.</div>
      <div class="listings">
        <div class="item">Listing 1</div>
        <div class="item">Listing 2</div>
        <div class="item">Listing 3</div>
        <div class="item">Listing 4</div>
        <div class="item">Listing 5</div>
      </div>
    </div>
  </div>
</body>


问:
distributing lists with lists to remove lists of lists in python
I have a list:

```<code>example_list = [x, y, [1, 2, 3], [4,5,6]]
</code>```

I need to turn into two lists:

```<code>j = [x, y, 1, 2, 3]
k = [x, y, 4, 5, 6]
</code>```

This example list does not come up with regularity, only when there are two objects on one page that I am scraping--say contact_page.  Generally, there is only one contact so the list is:

normal_example_list = [x, y, [1, 2, 3]]

where 'x' comes from function 1, 'y' comes from function 2, and [1, 2, 3] comes from function 3 (contact_page) and I put them all together with normal_example_list.append()

when there is only one list from contact_page I can just flatten it out.  I am looking for a rule that would iterate over a list and remove the 1st list within the list and then the 2nd list within the list, while keeping all other variables in the list in their positions.

Thinking this through after retyping my query something like

```<code>p = []
for i in contact_page:
    p.append(x)
    p.append(y)
    p.append(i)
</code>```

This would be more cumbersome to make functional in my code, but it may work.  I was hoping for a fix like (in words)

```<code>if example_list contains a list:
    new_list1 = [values common to both lists, [first list within list]]
    new_list2 = [values common to both lists, [second list within list]]
</code>```

from that I can flatten it out.

答:
It appears you want to extract all the lists from the input list and create a list for each, combined with all the non-list elements from the input list.

Something like:

```<code>xs = [1, 2, [3, 4, 5], [6, 7, 8], 9, [10]]
singles = [x for x in xs if not isinstance(x, list)]
result = [singles + x for x in xs if isinstance(x, list)]
print(result)
</code>```

Gets you:

```<code>[[1, 2, 9, 3, 4, 5], [1, 2, 9, 6, 7, 8], [1, 2, 9, 10]]
</code>```

Body:
I have a list:

example_list = [x, y, [1, 2, 3], [4,5,6]]

I need to turn into two lists:

j = [x, y, 1, 2, 3]
k = [x, y, 4, 5, 6]

This example list does not come up with regularity, only when there are two objects on one page that I am scraping--say contact_page.  Generally, there is only one contact so the list is:

normal_example_list = [x, y, [1, 2, 3]]

where 'x' comes from function 1, 'y' comes from function 2, and [1, 2, 3] comes from function 3 (contact_page) and I put them all together with normal_example_list.append()

when there is only one list from contact_page I can just flatten it out.  I am looking for a rule that would iterate over a list and remove the 1st list within the list and then the 2nd list within the list, while keeping all other variables in the list in their positions.

Thinking this through after retyping my query something like

p = []
for i in contact_page:
    p.append(x)
    p.append(y)
    p.append(i)

This would be more cumbersome to make functional in my code, but it may work.  I was hoping for a fix like (in words)

if example_list contains a list:
    new_list1 = [values common to both lists, [first list within list]]
    new_list2 = [values common to both lists, [second list within list]]

from that I can flatten it out.

Body:
It appears you want to extract all the lists from the input list and create a list for each, combined with all the non-list elements from the input list.

Something like:

xs = [1, 2, [3, 4, 5], [6, 7, 8], 9, [10]]
singles = [x for x in xs if not isinstance(x, list)]
result = [singles + x for x in xs if isinstance(x, list)]
print(result)

Gets you:

[[1, 2, 9, 3, 4, 5], [1, 2, 9, 6, 7, 8], [1, 2, 9, 10]]


问:
Find pixel indices within a shape: Opencv and Python
Suppose I have a mask of a hollow, curved (and not necessarily convex) shape that I've received from my pre-processing steps:

I now want to try and select all pixels that occur inside that shape and add them to the mask, as so:

How can I do this in Python?

Code for generating the examples:

import cv2
import numpy as np
import matplotlib.pyplot as plt

# Parameters for creating the circle
COLOR_BLUE = (255, 0, 0)
IMAGE_SHAPE = (256, 256, 3)
CIRCLE_CENTER = tuple(np.array(IMAGE_SHAPE) // 2)[:-1]
CIRCLE_RADIUS = 30
LINE_THICKNESS = 5 # Change to -1 for example of filled circle

# Draw on a circle
img = np.zeros(IMAGE_SHAPE, dtype=np.uint8)
img_circle = cv2.circle(img, CIRCLE_CENTER, CIRCLE_RADIUS, COLOR_BLUE, LINE_THICKNESS)
circle_mask = img_circle[:, :, 0]

# Show the image
plt.axis("off")
plt.imshow(circle_mask)
plt.show()
```

答:
Here are two other methods:

Method #1: cv2.findContours + cv2.drawContours

Find contours then fill in the contour

```<code>cnts = cv2.findContours(circle_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(circle_mask, [c], -1, (255,255,255), -1)
</code>```

Method #2: cv2.findContours
 + cv2.fillPoly

Again find contours then fill in using a different filling function

```<code>cv2.fillPoly(circle_mask, cnts, (255,255,255))
</code>```

Full code

```<code>import cv2
import numpy as np

# Parameters for creating the circle
COLOR_BLUE = (255, 0, 0)
IMAGE_SHAPE = (256, 256, 3)
CIRCLE_CENTER = tuple(np.array(IMAGE_SHAPE) // 2)[:-1]
CIRCLE_RADIUS = 30
LINE_THICKNESS = 5 # Change to -1 for example of filled circle

# Draw on a circle
img = np.zeros(IMAGE_SHAPE, dtype=np.uint8)
img_circle = cv2.circle(img, CIRCLE_CENTER, CIRCLE_RADIUS, COLOR_BLUE, LINE_THICKNESS)
circle_mask = img_circle[:, :, 0].astype(np.uint8)

# Method #1
cnts = cv2.findContours(circle_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(circle_mask, [c], -1, (255,255,255), -1)

# Method #2
# cv2.fillPoly(circle_mask, cnts, (255,255,255))

# Show the image
cv2.imshow('circle_mask', circle_mask)
cv2.waitKey()
</code>```

Body:
Here are two other methods:

Method #1: cv2.findContours + cv2.drawContours

Find contours then fill in the contour

cnts = cv2.findContours(circle_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(circle_mask, [c], -1, (255,255,255), -1)

Method #2: cv2.findContours
 + cv2.fillPoly

Again find contours then fill in using a different filling function

cv2.fillPoly(circle_mask, cnts, (255,255,255))

Full code

import cv2
import numpy as np

# Parameters for creating the circle
COLOR_BLUE = (255, 0, 0)
IMAGE_SHAPE = (256, 256, 3)
CIRCLE_CENTER = tuple(np.array(IMAGE_SHAPE) // 2)[:-1]
CIRCLE_RADIUS = 30
LINE_THICKNESS = 5 # Change to -1 for example of filled circle

# Draw on a circle
img = np.zeros(IMAGE_SHAPE, dtype=np.uint8)
img_circle = cv2.circle(img, CIRCLE_CENTER, CIRCLE_RADIUS, COLOR_BLUE, LINE_THICKNESS)
circle_mask = img_circle[:, :, 0].astype(np.uint8)

# Method #1
cnts = cv2.findContours(circle_mask, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
cnts = cnts[0] if len(cnts) == 2 else cnts[1]
for c in cnts:
    cv2.drawContours(circle_mask, [c], -1, (255,255,255), -1)

# Method #2
# cv2.fillPoly(circle_mask, cnts, (255,255,255))

# Show the image
cv2.imshow('circle_mask', circle_mask)
cv2.waitKey()


问:
Memory Footprint calculation of a java list and GC calculation
I have an application that creates a hashMap of size 1300. The value in the hash map is an object called employee Data and key is just a string - EmpName. The object has a list. Rest other fields in the object are either String or double. The list size in the object varies between 4 to 5000. I want to do a rough calculation of the memory consumption. Could you please help me with it? I also want to know how GC will free this memory.

I did some calculation:
The other fields will consume around 512 bytes each
I am not sure how to calculate the consumption of the list. The list contains all double value.
Also I am not how much memory of the object will increase with different size of the list and how will it contribute the overall memory consumption.

答:
This could be the answer you're looking for.

Memory usage for a specific list of object

The objects will be Garbage-Collected once the list no longer references to the objects; i.e; when the object is removed from the list.


问:
How to transform an Application.Transpose with a pastespecial to put only value and not format?
```<code>Dim ar as variable

Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1) =
Application.Transpose(ar)
</code>```

It work perfectly except it paste the format. I have strange number in my list and it should be paste as text because excel convert those number into date or different value.

How to add the following with the Application.Transpose?
.PasteSpecial xlPasteValues

Edit2: Below code should sort value in column B of sheet2 and transpose them in Sheet1. However, it does not transpose value. I did something wrong?

```<code>Private Sub Workbook_Open()
ThisWorkbook.RefreshAll
DoEvents

Dim r As Range
Dim rng As Range
Dim ar As Variant
Dim var As Variant

With Sheets("Sheet2").Range("B2").CurrentRegion
With CreateObject("scripting.dictionary")
For Each rng In Range("B3", Range("B" & Rows.Count).End(xlUp))
var = .Item(rng.Value)
Next
ar = .Keys
End With
End With
With Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1)
.NumberFormat = "@"
.Value = Application.Transpose(ar)
End With
</code>```

答:
What you show is not pasting any formats at all (assuming ar is a variant containing values, and not an array of cell ranges).

Try (not tested):

```<code>With Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1)
    .numberformat = "@"
    .value = Application.Transpose (ar)
end with
</code>```

Edit:

Now that you have posted additional code, showing how you populated ar, it is more clear what is going on.

```<code>ar = .Keys
</code>```

produces a one dimensional array.

```<code>Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1)
</code>```

returns a vertical cell range.

And your source region:

```<code>Range("B3", Range("B" & Rows.Count).End(xlUp))
</code>```

is also a vertical region.

You need to understand about passing arrays between VBA and the worksheets.  If the link is still live, a  good explanation is Chip Pearson's VBA Arrays and Worksheet Ranges.

Your one dimensional VBA array should go to a horizontal worksheet range.  To fill a vertical worksheet range, you'd need a 2D array.

And your destination range needs to be created as a horizontal range; you have created it as a vertical range.

So the relevant part of your code, with some editing for robustness, and indenting for readability, would read:

```<code>Dim r As Range
Dim rng As Range
Dim ar As Variant
Dim var As Variant

With Worksheets("sheet2")
    Set r = .Range("B3", .Range("B" & .Rows.Count).End(xlUp))
End With

With CreateObject("scripting.dictionary")
    For Each rng In r
        var = .Item(rng.Value)
    Next
    ar = .Keys
End With

With Sheets("Sheet1").Range("A4").Resize(columnsize:=UBound(ar) + 1)
    .NumberFormat = "@"
    .Value = ar
End With

End Sub
</code>```

This will paste a vertical range of data from Sheet2!B3:Bn into a horizontal range starting at Sheet1!A4.  Which is what I think you want.

Edit 2:

Unless you are going to have some other reason for using the Dictionary object, a shorter, equivalent version of the code would be:

```<code>  Dim ar As Variant
  Dim var As Variant

With Worksheets("sheet2")
    ar = .Range("B3", .Range("B" & .Rows.Count).End(xlUp))
End With

With Sheets("Sheet1").Range("A4").Resize(columnsize:=UBound(ar))
    .NumberFormat = "@"
    .Value = WorksheetFunction.Transpose(ar)
End With
</code>```

Note that, in this case,

we fill our VBA array in a single step

in sizing the destination range, we do NOT add the +1

we DO transpose the array before writing it to the destination

If you read through the reference above, you should be able to work out the logic of these changes.

Body:
Dim ar as variable

Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1) =
Application.Transpose(ar)

It work perfectly except it paste the format. I have strange number in my list and it should be paste as text because excel convert those number into date or different value.

How to add the following with the Application.Transpose?
.PasteSpecial xlPasteValues

Edit2: Below code should sort value in column B of sheet2 and transpose them in Sheet1. However, it does not transpose value. I did something wrong?

Private Sub Workbook_Open()
ThisWorkbook.RefreshAll
DoEvents

Dim r As Range
Dim rng As Range
Dim ar As Variant
Dim var As Variant

With Sheets("Sheet2").Range("B2").CurrentRegion
With CreateObject("scripting.dictionary")
For Each rng In Range("B3", Range("B" & Rows.Count).End(xlUp))
var = .Item(rng.Value)
Next
ar = .Keys
End With
End With
With Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1)
.NumberFormat = "@"
.Value = Application.Transpose(ar)
End With

Body:
What you show is not pasting any formats at all (assuming ar is a variant containing values, and not an array of cell ranges).

Try (not tested):

With Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1)
    .numberformat = "@"
    .value = Application.Transpose (ar)
end with

Edit:

Now that you have posted additional code, showing how you populated ar, it is more clear what is going on.

ar = .Keys

produces a one dimensional array.

Sheets("Sheet1").Range("A4").Resize(UBound(ar) + 1)

returns a vertical cell range.

And your source region:

Range("B3", Range("B" & Rows.Count).End(xlUp))

is also a vertical region.

You need to understand about passing arrays between VBA and the worksheets.  If the link is still live, a  good explanation is Chip Pearson's VBA Arrays and Worksheet Ranges.

Your one dimensional VBA array should go to a horizontal worksheet range.  To fill a vertical worksheet range, you'd need a 2D array.

And your destination range needs to be created as a horizontal range; you have created it as a vertical range.

So the relevant part of your code, with some editing for robustness, and indenting for readability, would read:

Dim r As Range
Dim rng As Range
Dim ar As Variant
Dim var As Variant

With Worksheets("sheet2")
    Set r = .Range("B3", .Range("B" & .Rows.Count).End(xlUp))
End With

With CreateObject("scripting.dictionary")
    For Each rng In r
        var = .Item(rng.Value)
    Next
    ar = .Keys
End With

With Sheets("Sheet1").Range("A4").Resize(columnsize:=UBound(ar) + 1)
    .NumberFormat = "@"
    .Value = ar
End With

End Sub

This will paste a vertical range of data from Sheet2!B3:Bn into a horizontal range starting at Sheet1!A4.  Which is what I think you want.

Edit 2:

Unless you are going to have some other reason for using the Dictionary object, a shorter, equivalent version of the code would be:

  Dim ar As Variant
  Dim var As Variant

With Worksheets("sheet2")
    ar = .Range("B3", .Range("B" & .Rows.Count).End(xlUp))
End With

With Sheets("Sheet1").Range("A4").Resize(columnsize:=UBound(ar))
    .NumberFormat = "@"
    .Value = WorksheetFunction.Transpose(ar)
End With

Note that, in this case,

we fill our VBA array in a single step

in sizing the destination range, we do NOT add the +1

we DO transpose the array before writing it to the destination

If you read through the reference above, you should be able to work out the logic of these changes.


问:
How to add System.Windows dll to Visual Studio 2010 express?
I am developing a small application using C# and VS2010 as IDE with .NET Framework 4.

I want to use CaptureSource class in order to capture video from laptop's webcam.

For that i need to add a namespace System.Windows.DependencyObject.

How can I add this? In the Solution Explorer, if I right clicked on Referenced, then .NET tab, I wont be able to see System.Windows. Please see the attached file the same.

Please anyone help me in adding this System.Windows dll.

Thanks in Advance

Sri

答:
According to this MSDN Page the class is in the WindowsBase.dll file.

```<code>Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)
</code>```

DependencyObject is a class you cannot add it as a namespace.  The closest thing you can do is add the namespace it is located in:

```<code>using System.Windows;
</code>```

Body:
According to this MSDN Page the class is in the WindowsBase.dll file.

Namespace:  System.Windows
Assembly:  WindowsBase (in WindowsBase.dll)

DependencyObject is a class you cannot add it as a namespace.  The closest thing you can do is add the namespace it is located in:

using System.Windows;


问:
intl extension installed but cant see in phpinfo()
I am using centos 7 with lamp +webmin control panel php 7.2,I need intl intl extension,I followed few tutorials from google and intl extension is installed(I am sure because if I try to install again it says already installed latest updated )see bellow snnipest

[root@xxxxxxx ~]# sudo yum --enablerepo=remi install php-intl
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * Webmin: download.webmin.com
 * base: ftp.hosteurope.de
Excluding mirror: mirror.fra10.de.leaseweb.net
 * centos-sclo-rh: mirror.alpix.eu
 * centos-sclo-sclo: mirror.checkdomain.de
Excluding mirror: mirror.de.leaseweb.net
Excluding mirror: mirror.nl.leaseweb.net
 * epel: ftp-stud.hs-esslingen.de
 * extras: centos.mirror.iphh.net
 * remi: remi.mirror.liteserver.nl
 * remi-php56: remi.mirror.liteserver.nl
 * remi-php72: remi.mirror.liteserver.nl
 * remi-safe: remi.mirror.liteserver.nl
 * updates: ftp.hosteurope.de
Package php-intl-7.2.27-1.el7.remi.x86_64 already installed and latest version
Nothing to do

Already added extension=php_intl or extension=intl in both php.ini

Configuration File (php.ini) Path     /etc/opt/rh/rh-php72

Loaded Configuration File   /home/two4cloudspace/etc/php7.2/php.

and then restarted,but still I cant find intl extension in phpinfo() output
in my phpinfo() output showing my module directory is

/opt/rh/rh-php72/root/usr/lib64/php/modules

but php -r "echo ini_get('extension_dir');" showing my module directory is

/usr/lib64/php/modules

and I tried to find intl.so file in both directory and I found the file in

/usr/lib64/php/modules

but cant find in

/opt/rh/rh-php72/root/usr/lib64/php/modules

and then I downloaded the intl.so and uploaded to /opt/rh/rh-php72/root/usr/lib64/php/modules and restarted but still same issue.
if I command php -m I can see all modules and intl is included there.

but I cant find it in phpinfo() or where need to intl extension there it says intl missing
what am I doing wrong or how do I solve it?

答: You are mixing up different RPM packages providing PHP (run rpm -qa | grep php | sort and rpm -qf $(which php), it will reveal before mentioned). The directory /opt/rh/rh-php72/root/usr/lib64/php/modules belongs to rh-php72-php and not to Remi. Thus sudo yum install --enablerepo=centos-sclo-rh rh-php72-php-intl helps if you need /opt/rh/rh-php72/root/usr/lib64/php/modules/intl.so; don't forget to restart your webserver afterwards (if you don't use php-fpm rather mod_php).


问:
AWS lambda intermittently times out connecting to S3
I'm a n00b to AWS.

I have a Lambda written in Java that processes S3 events from an SQS queue. The events are triggered by the creation of files in a specified directory in the S3 bucket.

The Lambda's processing of single S3 event received from the queue (i.e. creating one file) works as expected.

If I create a batch of between 5 and 10 files at the same time, multiple instances of the Lambda - usually between 3 and 5 in number - are initiated to process the resulting events. Some will work without issue but at least one of these (and some times more than one) will fail. The behaviour is (somewhat frustratingly) inconsistent.

During the execution of a Lambda that fails, the first error occurs when it tries to connect to the AWS Secrets Manager:

```<code>com.amazonaws.http.conn.ssl.SdkTLSSocketFactory - connecting to secretsmanager.ap-southeast-2.amazonaws.com/<ip>:<port>
c.a.http.conn.ClientConnectionManagerFactory - java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
... stack trace...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to secretsmanager.ap-southeast-2.amazonaws.com:<port> [secretsmanager.ap-southeast-2.amazonaws.com/<ip>, secretsmanager.ap-southeast-2.amazonaws.com/<ip>, secretsmanager.ap-southeast-2.amazonaws.com/<ip>] failed: connect timed out
... stack trace...
Caused by: java.net.SocketTimeoutException: connect timed out
</code>```

The connection is retried a couple of further times by the Lambda but always fails. The Lambda code catches the exception and tries to do some cleaning up but then also cannot connect to the S3 bucket:

```<code>com.amazonaws.http.conn.ssl.SdkTLSSocketFactory - Connecting socket to <s3 bucket>.s3.ap-southeast-2.amazonaws.com/<ip>:<port> with timeout 10000
c.a.http.conn.ClientConnectionManagerFactory - java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
... stack trace...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to <s3 bucket>.s3.ap-southeast-2.amazonaws.com:<port> [<s3 bucket>.s3.ap-southeast-2.amazonaws.com/<ip>] failed: connect timed out
... stack trace...
Caused by: java.net.SocketTimeoutException: connect timed out
</code>```

As this behaviour is inconsistent, I am not sure of an approach to identifying what the issue is - I can't work out why some instances of the Lambda would fail completely when others running at the same time work without any problems.

I am using the following libraries from com.amazonaws in my Java project:

```<code>aws-lambda-java-core: 1.2.0
aws-java-sdk-s3: 1.11.714
aws-java-sdk-events: 1.11.714
aws-java-sdk-secretsmanager: 1.11.718
aws-java-sdk-sqs: 1.11.719
</code>```

Thanks in advance for any assistance.

答:
The issue was a networking one - one of the private subnets that the Lambda's VPC uses had a mis-configured route table that was assigned to a non-existent NAT gateway.

Once the correct NAT gateway was added, the Lambda worked as expected.

Many thanks to John Rotenstein for his help with diagnosing this issue.

Body:
I'm a n00b to AWS.

I have a Lambda written in Java that processes S3 events from an SQS queue. The events are triggered by the creation of files in a specified directory in the S3 bucket.

The Lambda's processing of single S3 event received from the queue (i.e. creating one file) works as expected.

If I create a batch of between 5 and 10 files at the same time, multiple instances of the Lambda - usually between 3 and 5 in number - are initiated to process the resulting events. Some will work without issue but at least one of these (and some times more than one) will fail. The behaviour is (somewhat frustratingly) inconsistent.

During the execution of a Lambda that fails, the first error occurs when it tries to connect to the AWS Secrets Manager:

com.amazonaws.http.conn.ssl.SdkTLSSocketFactory - connecting to secretsmanager.ap-southeast-2.amazonaws.com/<ip>:<port>
c.a.http.conn.ClientConnectionManagerFactory - java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
... stack trace...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to secretsmanager.ap-southeast-2.amazonaws.com:<port> [secretsmanager.ap-southeast-2.amazonaws.com/<ip>, secretsmanager.ap-southeast-2.amazonaws.com/<ip>, secretsmanager.ap-southeast-2.amazonaws.com/<ip>] failed: connect timed out
... stack trace...
Caused by: java.net.SocketTimeoutException: connect timed out

The connection is retried a couple of further times by the Lambda but always fails. The Lambda code catches the exception and tries to do some cleaning up but then also cannot connect to the S3 bucket:

com.amazonaws.http.conn.ssl.SdkTLSSocketFactory - Connecting socket to <s3 bucket>.s3.ap-southeast-2.amazonaws.com/<ip>:<port> with timeout 10000
c.a.http.conn.ClientConnectionManagerFactory - java.lang.reflect.InvocationTargetException: null
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
... stack trace...
Caused by: org.apache.http.conn.ConnectTimeoutException: Connect to <s3 bucket>.s3.ap-southeast-2.amazonaws.com:<port> [<s3 bucket>.s3.ap-southeast-2.amazonaws.com/<ip>] failed: connect timed out
... stack trace...
Caused by: java.net.SocketTimeoutException: connect timed out

As this behaviour is inconsistent, I am not sure of an approach to identifying what the issue is - I can't work out why some instances of the Lambda would fail completely when others running at the same time work without any problems.

I am using the following libraries from com.amazonaws in my Java project:

aws-lambda-java-core: 1.2.0
aws-java-sdk-s3: 1.11.714
aws-java-sdk-events: 1.11.714
aws-java-sdk-secretsmanager: 1.11.718
aws-java-sdk-sqs: 1.11.719

Thanks in advance for any assistance.


问:
Is there a way to use condition variables to sleep, when there is only one type of thread?
In one of my courses, my professor asks us to implement a small program that spawns 5 threads and use a mutex to check if it's the threads respective turn. However, he also requested that we use a condition variable to avoid busy waiting for their turn.

From first glance this doesn't make much sense to me, because we cannot guarantee that any signal is going to wake up the correct thread. It seems like this is bound to be a deadlock unless the infinitely unlikely scenario occurs that the correct sleeping thread is woken up every time. Am I missing something?

答:
Your professor gave you the necessary information to complete the task.

From first glance this doesn't make much sense to me, because we cannot guarantee that any signal is going to wake up the correct thread.

Yes, the setup you are thinking of is used when you don't care which thread is waked up, e.g. when you have a worker pool and you just need a free thread, any free thread to assign the work to.

But if you think about it you can see you can create setups with locks and condition variables that result in your desired behavior, i.e. waking up a specific thread.

Hint: a condition variable has notify_all

Hint: or, alternatively, you can have more than 1 condition variable.

Think a bit about it and try different things.


问:
F-Score difference between cross_val_score and StratifiedKFold
I want to use a Random Forest Classifier on imbalanced data where X is a np.array representing the features and y is a np.array representing the labels (labels with 90% 0-values, and 10% 1-values). As I was not sure how to do stratification within Cross Validation and if it makes a difference I also manually cross validated with StratifiedKFold. I would expect not same but somewhat similar results. As this is not the case I guess that I wrongly use one method but I don´t understand which one. Here is the code

```<code>from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import StratifiedKFold, cross_val_score, train_test_split
from sklearn.metrics import f1_score

rfc = RandomForestClassifier(n_estimators = 200,
                             criterion = "gini",
                             max_depth = None,
                             min_samples_leaf = 1,
                             max_features = "auto",
                             random_state = 42,
                             class_weight = "balanced")

X_train_val, X_test, y_train_val, y_test = train_test_split(X, y, test_size = 0.20, random_state = 42, stratify=y)
</code>```

I also tried the Classifier without the class_weight argument. From here I proceed to compare both methods with the f1-score

```<code>cv = cross_val_score(estimator=rfc,
                     X=X_train_val,
                     y=y_train_val,
                     cv=10,
                     scoring="f1")
print(cv)
</code>```

The 10 f1-scores from cross validation are all around 65%.
Now the StratifiedKFold:

```<code>skf = StratifiedKFold(n_splits=10, shuffle=True, random_state=42)
for train_index, test_index in skf.split(X_train_val, y_train_val):
    X_train, X_val = X_train_val[train_index], X_train_val[test_index]
    y_train, y_val = y_train_val[train_index], y_train_val[test_index]
    rfc.fit(X_train, y_train)
    rfc_predictions = rfc.predict(X_val)
    print("F1-Score: ", round(f1_score(y_val, rfc_predictions),3))
</code>```

The 10 f1-scores from  StratifiedKFold gets me values around 90%. This is where I get confused as I don´t understand the large deviations between both methods. If I just fit the Classifier to the train data and apply it to the test data I get f1-scores of around 90% as well which lets me believe that my way of applying cross_val_score is not correct.

答:
One possible reason for the difference is that cross_val_score uses StratifiedKFold with the default shuffle=False parameter, whereas in your manual cross-validation using StratifiedKFold you have passed shuffle=True. Therefore it could just be an artifact of the way your data is ordered that cross-validating without shuffling produces worse F1 scores.

Try passing shuffle=False when creating the skf instance to see if the scores match the cross_val_score, and then if you want to use shuffling when using cross_val_score just manually shuffle the training data before applying cross_val_score.

Body:
I want to use a Random Forest Classifier on imbalanced data where X is a np.array representing the features and y is a np.array representing the labels (labels with 90% 0-values, and 10% 1-values). As I was not sure how to do stratification within Cross Validation and if it makes a difference I also manually cross validated with StratifiedKFold. I would expect not same but somewhat similar results. As this is not the case I guess that I wrongly use one method but I don´t understand which one. Here is the code

from sklearn.ensemble import RandomForestClassifier
from sklearn.model_selection import StratifiedKFold, cross_val_score, train_test_split
from sklearn.metrics import f1_score

rfc = RandomForestClassifier(n_estimators = 200,
                             criterion = "gini",
                             max_depth = None,
                             min_samples_leaf = 1,
                             max_features = "auto",
                             random_state = 42,
                             class_weight = "balanced")

X_train_val, X_test, y_train_val, y_test = train_test_split(X, y, test_size = 0.20, random_state = 42, stratify=y)

I also tried the Classifier without the class_weight argument. From here I proceed to compare both methods with the f1-score

cv = cross_val_score(estimator=rfc,
                     X=X_train_val,
                     y=y_train_val,
                     cv=10,
                     scoring="f1")
print(cv)

The 10 f1-scores from cross validation are all around 65%.
Now the StratifiedKFold:

skf = StratifiedKFold(n_splits=10, shuffle=True, random_state=42)
for train_index, test_index in skf.split(X_train_val, y_train_val):
    X_train, X_val = X_train_val[train_index], X_train_val[test_index]
    y_train, y_val = y_train_val[train_index], y_train_val[test_index]
    rfc.fit(X_train, y_train)
    rfc_predictions = rfc.predict(X_val)
    print("F1-Score: ", round(f1_score(y_val, rfc_predictions),3))

The 10 f1-scores from  StratifiedKFold gets me values around 90%. This is where I get confused as I don´t understand the large deviations between both methods. If I just fit the Classifier to the train data and apply it to the test data I get f1-scores of around 90% as well which lets me believe that my way of applying cross_val_score is not correct.


问:
Scapy: Processing partial TLS segments
I am trying to extract TLS meta-data from a pcap using Scapy. I am able to successfully parse the packets and individual messages such as the client-hello, server-hello etc and their fields. What I am having trouble with is when the TLS record is spread across multiple TCP packets/segments. This happens mostly for large TLS messages, such as application data or when server sends multiple TLS messages (server hello, certificate, etc) in one TLS frame. In such cases, scapy says it has the TLS/SSLv2 layer, but I am unable to extract any meaningful information from such frames. When I look at the same pcap in wireshark, wireshark displays

```<code>Reassembled TCP segments (T bytes): #X (x), #Y(y), #Z(z)
</code>```

Where T is the combined total; X, Y, Z are frame-ids and x,y,z are number of bytes in each frame that contributed to the total T. Wireshark is reassembly the entire TLS payload before it parses the TLS frame.

I have something like this in my code:

```<code>if pkt.haslayer(TCP) and pkt.haslayer(TLS):
  parseTLS(pkt)
elif pkt.haslayer(TCP) and pkt.haslayer(SSLv2):
  parseSSLv2(pkt)
</code>```

When it encounters a partial TLS packet, the code always falls through to the SSLv2. Is there a way for me to accurately identify a packet as a partial tls-segment and accumulate and then process the complete TLS frame similar to wireshark? If so, how do I go about it. Any pointers or help is appreciated. Thanks.

答:
Not sure if there is a better solution, but here's what I did to get around my problem. The accumulated frame-sizes seem to agree with what Wireshark does when it reassembles TLS frame from multiple packets.

Note: This solution assumes there are no misordered packets or duplicates. Also, the solution shown here is not complete. The code below only shows how to accumulate TLS frames when they span multiple IP packets for a single TCP stream. Please follow Janus's suggestion (mentioned in the comments below) or come up with your own solution to accumulate different the streams.

```<code>def extractDataFromPcap(pcapfile):
  load_layer("tls")

  try:
    reader = PcapReader(pcapfile)

    # tls frame accumulation related variables.
    tls_accumulate = False
    tls_leftover_len = 0
    tls_blist = list()

    for pkt in reader:
      try:
        if tls_accumulate and pkt.haslayer(TCP):
          ip_tcp_hdr_overhead = ((pkt[IP].ihl*4) + (pkt[TCP].dataofs*4))
          pkt_payload_len = (pkt[IP].len - ip_tcp_hdr_overhead)
          tls_leftover_len = (tls_leftover_len - pkt_payload_len)
          tls_blist.append(raw(pkt[TCP].payload))

          if tls_leftover_len <= 0:
            # got complete TLS frame
            tls_raw_bytes = b''.join(tls_blist)

            # parse accumulated frame.
            tls = TLS(tls_raw_bytes)
            #... process tls object

            # reset accumlation variables.
            tls_accumulate = False
            tls_leftover_len = 0
            tls_blist = list()
          else:
            continue

        if pkt.haslayer(TCP) and pkt.haslayer(TLS):
          if not tls_accumulate:
            # Process new TLS frame.
            # Pkt over head: ip-hdr-len + tcp-hdr-len
            ip_tcp_hdr_overhead = ((pkt[IP].ihl*4) + (pkt[TCP].dataofs*4))
            pkt_payload_len = (pkt[IP].len - ip_tcp_hdr_overhead)
            if pkt[TLS].len > pkt_payload_len:
              # partial TLS frame. Start accumulating.
              tls_accumulate = True
              tls_leftover_len = (pkt[TLS].len - pkt_payload_len)
              tls_blist.append(raw(pkt[TCP].payload))
            else:
              # complete TLS frame
              # ... process complete TLS Frame
      except Exception as error:
        pkt.show()
        print("tcp-processing error: %s", error)
        sys.exit(-1)

  except Exception as error:
    print("packet processing error: %s", error)
    sys.exit(-1)
</code>```

Title: Scapy: Processing partial TLS segments

Body:
I am trying to extract TLS meta-data from a pcap using Scapy. I am able to successfully parse the packets and individual messages such as the client-hello, server-hello etc and their fields. What I am having trouble with is when the TLS record is spread across multiple TCP packets/segments. This happens mostly for large TLS messages, such as application data or when server sends multiple TLS messages (server hello, certificate, etc) in one TLS frame. In such cases, scapy says it has the TLS/SSLv2 layer, but I am unable to extract any meaningful information from such frames. When I look at the same pcap in wireshark, wireshark displays

Reassembled TCP segments (T bytes): #X (x), #Y(y), #Z(z)

Where T is the combined total; X, Y, Z are frame-ids and x,y,z are number of bytes in each frame that contributed to the total T. Wireshark is reassembly the entire TLS payload before it parses the TLS frame.

I have something like this in my code:

if pkt.haslayer(TCP) and pkt.haslayer(TLS):
  parseTLS(pkt)
elif pkt.haslayer(TCP) and pkt.haslayer(SSLv2):
  parseSSLv2(pkt)

When it encounters a partial TLS packet, the code always falls through to the SSLv2. Is there a way for me to accurately identify a packet as a partial tls-segment and accumulate and then process the complete TLS frame similar to wireshark? If so, how do I go about it. Any pointers or help is appreciated. Thanks.

Body:
Not sure if there is a better solution, but here's what I did to get around my problem. The accumulated frame-sizes seem to agree with what Wireshark does when it reassembles TLS frame from multiple packets.

Note: This solution assumes there are no misordered packets or duplicates. Also, the solution shown here is not complete. The code below only shows how to accumulate TLS frames when they span multiple IP packets for a single TCP stream. Please follow Janus's suggestion (mentioned in the comments below) or come up with your own solution to accumulate different the streams.

def extractDataFromPcap(pcapfile):
  load_layer("tls")

  try:
    reader = PcapReader(pcapfile)

    # tls frame accumulation related variables.
    tls_accumulate = False
    tls_leftover_len = 0
    tls_blist = list()

    for pkt in reader:
      try:
        if tls_accumulate and pkt.haslayer(TCP):
          ip_tcp_hdr_overhead = ((pkt[IP].ihl*4) + (pkt[TCP].dataofs*4))
          pkt_payload_len = (pkt[IP].len - ip_tcp_hdr_overhead)
          tls_leftover_len = (tls_leftover_len - pkt_payload_len)
          tls_blist.append(raw(pkt[TCP].payload))

          if tls_leftover_len <= 0:
            # got complete TLS frame
            tls_raw_bytes = b''.join(tls_blist)

            # parse accumulated frame.
            tls = TLS(tls_raw_bytes)
            #... process tls object

            # reset accumlation variables.
            tls_accumulate = False
            tls_leftover_len = 0
            tls_blist = list()
          else:
            continue

        if pkt.haslayer(TCP) and pkt.haslayer(TLS):
          if not tls_accumulate:
            # Process new TLS frame.
            # Pkt over head: ip-hdr-len + tcp-hdr-len
            ip_tcp_hdr_overhead = ((pkt[IP].ihl*4) + (pkt[TCP].dataofs*4))
            pkt_payload_len = (pkt[IP].len - ip_tcp_hdr_overhead)
            if pkt[TLS].len > pkt_payload_len:
              # partial TLS frame. Start accumulating.
              tls_accumulate = True
              tls_leftover_len = (pkt[TLS].len - pkt_payload_len)
              tls_blist.append(raw(pkt[TCP].payload))
            else:
              # complete TLS frame
              # ... process complete TLS Frame
      except Exception as error:
        pkt.show()
        print("tcp-processing error: %s", error)
        sys.exit(-1)

  except Exception as error:
    print("packet processing error: %s", error)
    sys.exit(-1)