text:
Q: Big Data or relational database (like MySQL cluster)? I am going to deal with a huge amount of data in my project. I have read about big data concepts but never used it yet. But reading all those Big Data Documents I am still not sure whether my requirement needs Big Data or is it good to handle with traditional relational database.
Here is some information about my DB.
My main DB is a repository for different data sources. Each of this data sources deals with same kind of data (data in same domain), but some data sources contain extra fields which in not available in others and some contain less. In other words some of the data fields in these data sources are same, but some are different. So my core DB should contain all those fields. Total fields in my core DB should be approximately 2000 fields and it may contain 10 to 20 million records.
The DB operation which is happening in my core DB will be data insertion and reading (searching). Since it deals with huge amount of data I was thinking to use big data concepts. But I am still not sure whether this suits for big data. Because some amount of my data has similar characteristics (same fields) and some contain extra information. And I need all the kind of searching fast in my DB.
Thanks.

A: Relational databases like MySQL can handle billions of rows / records so the decision will depend on your use case(s). For Big Data NoSQL systems, it is very important to understand how the strengths and limitations of each system map to your use case(s) as they can behave very differently.
Here are some MySQL examples:

*

*1.1 billion rows on Percona DB (fork of MySQL)

*0.95 billion rows on MySQL
In the second example, they moved from MySQL to Redis because they need to store the equivalent of 359 billion rows, far more than the 950 million they were storing in MySQL.
Given that you say you have fast searching requirements, it is important to understand what kind of searches you need as different databases have different searches they support. Additionally, some supported searches may have limited functionality. If you have search requirements that go beyond the core data store functionality, often times a full text solution will be added, for example, using Cassandra for the data store and Elasticsearch for the search component.
To provide some background for this decision, it's useful and important to consider your requirements with respect to the CAP Theorem which states that distributed computer systems can provide some but not all of the following guarantees (from Wikipedia):

*

*Consistency (all nodes see the same data at the same time)

*Availability (a guarantee that every request receives a response
about whether it succeeded or failed)

*Partition tolerance (the system continues to operate despite arbitrary message loss or failure of part of the system)

http://en.wikipedia.org/wiki/CAP_theorem
Graphically, you can see how different database solutions including MySQL and NoSQL solutions map out here:

If you provide more information on your use case(s), you can get more detailed responses.


text:
Q: Factory de Relação N:N Estou com uma aplicação onde os usuários podem ver ou não determinado módulo do sistema de acordo com suas permissões. Essas permissões são gravadas no banco de dados de forma N:N e gerenciadas no UserPolicy, conforme exemplo:
UserPolicy.php
public function viewReports(User $user)
{
    foreach($user->module as $m){
        if($m->id === 3)
            return true;
    }
}

UserPolicyTest.php
public function testCanViewReports()
{
    $user = factory(User::class)->make();
    $user->module()->sync([3]);

    $this->assertTrue($user->can('viewReports', User::class));
}

O teste passa, só que os dados registrados com $user->module()->sync([3]); ficam gravados no banco de dados (na tabela user_module).

Como faço para que os registros sejam excluídos, ou não precisem ser
  criados, no banco de dados?

A: Para realizar um rollback de todas as alterações do seu teste, você pode usar uma trait dentro da classe teste.
importe a DatabaseTransactions e use dentro de seu teste da seguinte forma.
<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;
use App\User;

// Importe a DatabaseTransactions
use Illuminate\Foundation\Testing\DatabaseTransactions;

class ExampleTest extends TestCase
{
    // Use a trait DatabaseTransactions dessa forma
    use DatabaseTransactions;

    public function testSeuTesteAqui()
    {
        $user = factory(User::class)->create();
        // Aqui o usuário vai ser criado mas quando o teste terminar ele não existirá mais.
    }
}

A: Sua pergunta é clara, porém, o processo de construção lógico um pouco equivocado. Vamos lá...
Laravel disponibiliza 2 funções para gerenciar relacionamentos N:N, attach() e sync(). A função attach() registra novos valores na tabela auxiliar, enquanto sync() excluí todos e então registra novos valores.
Chamar a função sync() e não desejar que a tabela seja alterada é ilógico.
Se a resposta acima foi util para você, tudo certo, se não, continue lendo.
Talvez a pergunta que você tenha que fazer é:

Por que estou me preocupando se os registros são inseridos/alterados?

Então, assumo que você utiliza o mesmo banco de dados para desenvolvimento local e para testes, isso dificulta o desenvolvimento TDD, resultando em situações como a que você enfrenta.
Minha sugestão:
Crie um novo banco de dados ou, o que é recomendado: instale e utilize o SQL Lite.
Em config/database.php, configure uma nova nova conexão (se optou por utilizar o recomendado, a conexão com o sqllite já vem configurada).
Abra o arquivo phpunit.xml e adicione a seguinte linha na tag php.
<env name="DB_CONNECTION" value="sqllite" />

Onde, value="" recebe o nome da conexão.
Espero ter ajudado. :D

redpajama_set_name: RedPajamaStackExchange


text:
Q: How to insert a text (not a node) in Summernote and move the cursor back X characters? In Summernote, one can easily insert a text like so:
$('#summernote').summernote('editor.insertText', 'hello world'));
One could also insert a node like so:
$('#summernote').summernote('insertNode', node);
When inserting the Node, the cursor conveniently stays within the boundaries of the tag, for example when inserting the kbd tag, the cursor stays in between : <kbd> Cursor </kbd>
My question is how could one insert a text (not a tag) like "aa" and maintains the cursor in between the the two a's "a cursor a". So the only thing that I can think of is to control the cursor which I don't know how after many hours of researching. It doesn't have to be through cursor control if one knows a better way.


text:
Q: splitting strings using re.split() I have a many emails in a string. I need to split this string into separate emails. Each email starts with "From:" in a new line. If there were no "From:" anywhere else in the body then the following works -
list_of_email_strings = re.split("From:", my_email_text_string)

I need to though ignore "From:" that does not occur right after a new line. The following (with caret) does  not work -
list_of_email_strings = re.split("^From:", my_email_text_string)

Solution ?

A: You can combine \n with a non-consuming lookahead assertion (?=...) which has the advantage of not eating the string upon which you're splitting (e.g. "From:" stays intact).
list_of_email_strings = re.split("\n(?=From:)", my_email_text_string)

E.g.:
>>> s = "From: ...\nFrom: ...\nFrom: ..."
>>> re.split("\n(?=From:)", s)
['From:...', 'From:...', 'From:...']

As compared to:
>>> re.split("\nFrom:", s)
['From: ...', ' ...', ' ...']

A: Similar to wim's answer, but with From: being added back into the emails as needed:
list = ['From:' + msg for msg in ('\n' + text).split('\nFrom:')]

However, there are native Python modules which give you finer and more reliable control over reading in email files like the one you describe. email and mailbox come to mind.
Assuming these are standard mbox style emails in which each file starts with a "From:" and then some header lines, possibly a digest, etc. - like those used by sendmail or Postfix - something like this will work if you either first write the string to file or just use an existing file:
mbox = mailbox.mbox(path_to_mailbox_file)
mbox.lock()  # only if you're using an active mailbox file
message_strings = [message.as_string() for message in mbox]
mbox.unlock()  # again, only if you're using an acture mailbox file
mbox.close()

To get the number of messages, just use len(mbox).
There are a ton of other useful features. I've made a few scripts using these mudules and been very hapy with the results. (Note that as_string may reformat some of the header.)


text:
Q: External RC oscillator fuse programmed instead of external crystal fuse Is there anyway to revive an Atmega8A? avrdude says avrdude: error: program enable: target doesn't answer. 1 ever since I programemd the fuse incorrectly. There is an external crystal and its two load caps on the board and it has worked with those in the recent past.

A: In the external RC oscillator mode, the oscillator block onboard the chip will not work with a crystal. You would need to connect a resistor and a capacitor as shown in app note AVR051:

If it's hard to disconnect the crystal (e.g. because the chip is already integrated onto a PCB), you may even be able to leave the crystal connected as long as the RC frequency is relatively small compared to the crystal frequency - this isn't the best setup, but it should get you far enough to fix the fuse bits as an emergency measure.
An alternative (if you have access to most of the AVR pins) is to use the HVPP mode of the microcontroller; you'll need a special programmer that can apply +12 V (!) to the RESET pin. An example of such a programmer is described here. This also has the benefit of working even if the RESET pin has been disabled with bad fuse settings.

A: You can override the crystal with an external 1..4MHz square wave generator at XTAL1. An Arduino output with a fast set_bit/clear_bit loop can provide this if you don't have a function generator at hand. Avrdude should be able to erase the chip and correct the fuses with that clock. I have recovered a lot of atmega88's that way.


text:
Q: Change Detection and Image registration
The image shows 4 images.
Image2 has been co-registered as per Image1, so that change detection can be performed. This results in a black portion in the right side and bottom side of the aligned image(3rd one), because that portion is not available in Image2. Or we can say,there is a loss of information in aligned image,when compared to Image2(due to registration).
4th image shows the detected changes in white on a black background. As we can see,in the right and bottom portions of 4th image,some change has been detected(white regions).
As per my requirement,these changes need not be reported. The reason is Image1 contains more information than Image2,which is being shown by black portions in aligned image(3rd). Therefore that extra information need not be qualified as change.
The area blackened by co-registration should be neglected by my change detection algorithm.
How can I achieve that? I am looking for ideas to detect such blackened areas.

A: If you can transform a uniform white image using the same parameters, you'd have a b/w mask of "reachable" pixels, that you can e.g. AND with the change detection result


text:
Q: Effecting a Shift of an FCOLORBOX within a Simple Lettrine Consider the code
\documentclass{book}
\usepackage{type1cm,lettrine}
\usepackage{xcolor}
%\usepackage{lipsum}
\usepackage[tracking=true]{microtype}

\begin{document}
\thispagestyle{empty}
\large

\lettrine[lines=3,loversize=.4,lraise=.15,nindent=.80em,findent=.20em]{\fboxsep10pt\fboxrule15pt\fcolorbox{red}{yellow!75!brown}{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box.
\end{document}

which produces

QUESTION: How may I horizontally (and vertically) effect a shift of the fcolorbox containing the letter within the outer red box?
EDIT: Is it possible to do this without redefining the fcolorbox?
I compile the code with pdflatex.
Thank you.

A: \fcolorbox will draw a box with the same inner padding and border width in all directions.
The longbox allows you to separately set the top, bottom left and right widths of the padding and border. It is then possible to move the inner yellow box inside the outer red box by manipulating these parameters.
Two lengths, \xshift and \yshift, were defined using the lower-left-corner of the outer red box as the origin.
The original \fcolorbox has a 15pt border and 10pt padding inside. The figure shows that the longbox faithfully reproduces it.

Obviously the maximum values for shifts are, in this example, 25pt, to keep the yellow box within the red box.
The second figure shows three examples. depth=1 was added  to accommodate a fourth line.

\documentclass[12pt,a4paper]{article}

\usepackage{longfbox}% added <<<<<<<<<<<<
\newlength{\yshift}
\newlength{\xshift}

\usepackage{type1cm,lettrine}
\usepackage{xcolor}

\usepackage[tracking=true]{microtype}
\begin{document}

\thispagestyle{empty}
\large

\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1 ]{\fboxsep10pt\fboxrule15pt\fcolorbox{red}{yellow!75!brown}{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box. \emph{With a text more the three lines  lraise must be changed or depth added.}

\bigskip

\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
    \lfbox[border-top-width=15pt,
    border-bottom-width=15pt,
    border-left-width=15pt,
    border-right-width=15pt,
    padding-right=10pt,
    padding-left=10pt,
    padding-top=10pt,
    padding-bottom=10pt,
    border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box. (done with \textbf{longfbox})

\newpage

\setlength{\yshift}{0pt}    % bottom left corner
\setlength{\xshift}{0pt}
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
    \lfbox[border-top-width=\dimexpr 25pt- \yshift,
    border-bottom-width=\yshift,
    border-left-width=\xshift,
    border-right-width=\dimexpr 25pt- \xshift,
    padding-right=10pt,
    padding-left=10pt,
    padding-top=10pt,
    padding-bottom=10pt,
    border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box. (done with \textbf{longfbox} X = 0pt, Y = 0pt))

\vspace{25pt}

\setlength{\yshift}{4pt}
\setlength{\xshift}{10pt}
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
    \lfbox[border-top-width=\dimexpr 25pt- \yshift,
    border-bottom-width=\yshift,
    border-left-width=\xshift,
    border-right-width=\dimexpr 25pt- \xshift,
    padding-right=10pt,
    padding-left=10pt,
    padding-top=10pt,
    padding-bottom=10pt,
    border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box.
 (done with \textbf{longfbox}; X = 10pt, Y = 4pt)

\vspace{15pt}

\setlength{\yshift}{25pt}   % top right corner
\setlength{\xshift}{25pt}
\lettrine[lines=3,loversize=.4,lraise=.4,nindent=.80em,findent=.20em, depth=1]{%
    \lfbox[border-top-width=\dimexpr 25pt- \yshift,
    border-bottom-width=\yshift,
    border-left-width=\xshift,
    border-right-width=\dimexpr 25pt- \xshift,
    padding-right=10pt,
    padding-left=10pt,
    padding-top=10pt,
    padding-bottom=10pt,
    border-color=red,background-color= yellow!75!brown,]{\color{red}I}}{would} like to shift (vertically, horizontally) the yellow box containing the letter within the outer red box.
(done with \textbf{longfbox}; X = 25pt, Y =  25pt)

\end{document}


text:
Q: Checking status of program This always works if I just type:if [ ! "$(pgrep vlc)" ]; then echo not running; else echo running; fi in the command prompt, but as soon as I make it a script, give it chmod +x and run it I always get "running" as the output. Can someone give me a lead?
#!/bin/bash
export DISPLAY=:0

if [ ! "$(pgrep vlc)" ]; then echo not running; else echo running; fi

A: If the name of your script contains 'vlc', pgrep founds that script running and condition in if is false, even though real VLC is not running.

A: You could insert
   echo "$(pgrep vlc)"

before the if stament

A: You can be more selective with your pgrep command. It's not necessary to use command substitution and brackets.
#!/bin/bash
export DISPLAY=:0

if ! pgrep -f "/path/to/vlc " >/dev/null; then echo not running; else echo running; fi

A: another option to avoid mixup with your own script is to use ps's '-C' flag
(I dont know how portable it is though)
if ps -C vlc > /dev/null ; then echo running; else echo not runing; fi


text:
Q: Need to display syntax highlighted source code on my webpage Currently I'm working on a website where user can post text that can contain source code examples.
A little bit like here on stackoverflow. Where I can type javascript and php and jquery and css and many other languages and they will been syntax higlighted on the page! :)
Like this:
<?php echo "Hello friends";?>

How do I do it in the best possible way?

A: I believe you are looking for Highlight.js; give it a try, it's fairly trivial to set up and use:

BASIC USAGE
Link the library and a stylesheet from your page and hook highlighting
  to the page load event:
<link rel="stylesheet" href="styles/default.css">

This will highlight all code on the page marked up as
 ..
.

A: Have a look at this project: https://github.com/igorpan/PHPygmentizator
It is a PHP library that uses Pygments to highlight a wide range of languages and supports a lot of different styles.

A: Use php's htmlsafe
http://php.net/manual/en/function.htmlspecialchars.php
<?php
$new = htmlspecialchars("Test", ENT_QUOTES);
echo $new; // <a          href='test'>Test</a>
?>

( off top of my head I can't remember what flag,  but there is a flag that outputs the safe ASCII versions thatrender correctly in browser )
Then use bootstraps code class
http://twitter.github.com/bootstrap/base-css.html#code


text:
Q: point giving me errors when drawing rectangle private Point hLocation;

I am stuck on this.  Please help.

Error 2 The type or namespace name 'Point' could not be found (are you
  missing a using directive or an assembly reference?)

A: Didn't you read the exception message? It seems pretty self explanatory:

are you missing a using directive or an assembly reference?

The Point structure is declared in the System.Drawing assembly inside the System.Drawing namespace. So make sure that you have referenced this assembly in your project and that you have brought the namespace into scope with a using directive:
using System.Drawing;

A: Either you must declare your variable with the namespace:
    private System.Drawing.Point hLocation;

Or you must include the namespace above your class declaration:
    using System.Drawing;

The second way is better since you will likely be using the Point type more than once in your class.  Having to reference it as System.Drawing.Point over and over again will be redundant.


text:
Q: How to save list of children data in onetomany in Springboot jpa Parent data is saving but list of children data is not saving in table.
data from postman
{"billno":"nur-1001", "grandTotal": 5000,"billcart":[{"itemcode":"SU10027", "soldPrice":0},{"itemcode":"SU10027","soldPrice":1100}]}

Bill is parent Entity & billcart is child entity
@NoArgsConstructor @AllArgsConstructor @Data @Entity
public class Bill {
    @Id
    @GeneratedValue(strategy=GenerationType.IDENTITY)
    private Long id;
    private String billno;
    private Long grandTotal;

    @OneToMany(mappedBy = "bill", cascade = CascadeType.ALL)
    @JsonIgnore
    private List<Billcart> billcart = new ArrayList<>();

    public Bill( String billno, Long grandTotal, List<Billcart> billcart) {
        this.billno = billno;
        this.grandTotal = grandTotal;
        this.billcart = billcart;
        this.billcart.forEach(e -> e.setBill(this));
    }
}

child entity
@NoArgsConstructor @AllArgsConstructor @Data @Entity
public class Billcart {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;
    private String itemcode;
    private Integer soldPrice;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "bill_id")
    private Bill bill;

controller
public void saveBill(@RequestBody Bill request) {
List<Billcart> billscart = request.getBillcart().stream()
                .map(e -> new Billcart(e))
                .collect(Collectors.toList());

        Bill bill = new Bill(request.getBillno(), request.getGrandTotal() , billscart);
        billRepository.save(bill);


text:
Q: Key-value хранилище для Android Существуют ли для Android NoSQL-хранилища аналогичные Redis или Memcache?
Стандартный SharedPreferenses не подходит, т.к. может хранить только простые типы данных. А, мне нужно сохранить объект или массив объектов.

A: Если вам не нужно хранить большое количество объектов, тогда SharedPreferenses - самый лучший вариант. Как выше уже сказали, достаточно написать generic-метод для сериализации объектов в json-строку и десериализацию из json через Gson.
Самое главное, нужно помнить, что физически SharedPreferences - это обычный xml-файл (хоть и базовой системой кэширования). Да, получается, что вы храните json внутри xml. Но, повторюсь, это не является проблемой в случае хранения ограниченного количества объектов.
Если же объектов много и их нужно часто изменять - тогда только БД.


text:
Q: Thermodynamic System: Windmill There is a closed system that is just a windmill attached to a rotating shaft that can mechanically power something. I know the system produces work on the surroundings from the rotating shaft and this is positive work, but is there also a negative work input from the wind pushing the blades of the windmill?
Also, would there be any heat transfer in this scenario?

A: Let's start, as per the OP's comments, with the convention that when we take two systems A and B, and A is doing work on B, then: from the perspective of A, the work is positive; and from the perspective of B, the work is negative.
Now, from the perspective of the windmill. the work that the wind does is indeed negative: the wind is adding exergy to our windmill system. And most of that work will then transfer into positive work done by the windmill through the rotating shaft.
However, these transfers of exergy don't come for free: some heat is generated in the process, from friction in the system. As to exactly where the heat transfers are, will depend on the initial temperatures of the surroundings and the windmill, and the amount of heat generated by friction. But typically, the friction would raise the windmill's temperature above the temperature of the surroundings, so heat would get transferred from within the windmill system, to outside it.


text:
Q: How can re enable pop in Gmail from C# code? I have a program that downloads mails from my Gmail, i have selected the radio button : Enable POP for all mail (even mail that's already been downloaded)
After i download my mail my Gmail changes the status above to: POP is enabled for all mail that has arrived since current Date
I did not physical change the radio buttons but it seams like it auto sets it to download only new mail.
I need my windows to down load all my all the time.
How can i set in my code that Gmails must enable all downloads all the time? with out me having to go re select the radio button every time.

Windows Service
 namespace EmailWindowsService
{
    public partial class MyEmailService : ServiceBase
    {
        private static System.Timers.Timer aTimer; //Create a timer
        public MyEmailService()
        {
            InitializeComponent();
            if (!System.Diagnostics.EventLog.SourceExists("MySource")) // Log every event
            {
                System.Diagnostics.EventLog.CreateEventSource(
                    "MySource", "MyNewLog"); // Create event source can view in Server explorer
            }
            eventLogEmail.Source = "MySource";
            eventLogEmail.Log = "MyNewLog";
            // Timer Code
             aTimer = new System.Timers.Timer(1 * 60 * 1000); // 60 seconds
             aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent); // Call time elapsed event
             aTimer.Enabled = true;
            // Timer Code
        }
        protected override void OnStart(string[] args)
        {
            eventLogEmail.WriteEntry("Started");
        }
        protected override void OnStop()
        {
            eventLogEmail.WriteEntry("Stopped");
        }
        protected override void OnPause()
        {
            eventLogEmail.WriteEntry("Paused");
        }
        protected override void OnContinue()
        {
            eventLogEmail.WriteEntry("Continuing");
        }
        protected override void OnShutdown()
        {
            eventLogEmail.WriteEntry("ShutDowned");
        }
        private void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            clsRetriveEmail Emails = new clsRetriveEmail();
            eventLogEmail.WriteEntry("Populateing database with mail"); // log event
            Emails.EmailGetList(); // Call class
        }
        }
    }

Class
namespace EmailWindowsService
{
    class clsRetriveEmail
    {
        public void EmailGetList()
        {
            using (Pop3Client objClient = new Pop3Client())
            {
                //Athentication This is stored in the app.config file
                objClient.Connect(Properties.Settings.Default.mailServer, Properties.Settings.Default.port, Properties.Settings.Default.ssl); // mailserver eg gmail is pop.gmail.com, Port common ports 995 110 sll Security best to set to true
                objClient.Authenticate(Properties.Settings.Default.username, Properties.Settings.Default.password);  // Email Address and password
                //Count Emails and begin Looping though them
                int emailCount = objClient.GetMessageCount();
                for (int i = emailCount; i >= 1; i--)
                {
                   OpenPop.Mime.Message msg = objClient.GetMessage(i); //Get message Number. Message decleard as msg
                    //Set the values to throw into Database
                   int emailID = i;
                   String emailTo = Properties.Settings.Default.username;
                   String emailFrom = msg.Headers.From.Address;
                   String emailSubject = msg.Headers.Subject;
                   DateTime emailSentDate = msg.Headers.DateSent;
                    // The connection String can be changed in the app.config file
                    // Connect to database
                    using (var conn = new SqlConnection(Properties.Settings.Default.dbConnectionString))
                    using (var cmd = conn.CreateCommand())
                    {
                            // Writes to database (local) instance
                            conn.Open();
                            cmd.CommandText = "EmailLogFill";
                            cmd.CommandType = CommandType.StoredProcedure;
                            cmd.Parameters.AddWithValue("@id", emailID);
                            cmd.Parameters.AddWithValue("@to", emailTo);
                            cmd.Parameters.AddWithValue("@from", emailFrom);
                            cmd.Parameters.AddWithValue("@subject", emailSubject);
                            cmd.Parameters.AddWithValue("@date", emailSentDate);
                            cmd.ExecuteNonQuery();
                    }
                }
            }
        }
    }
}

A: You don't need to re enable the radio button, when a pop client downloads the mail, it cant be view by other pop clients. How outlook does this is by using the recent mode.
Try this its not all your mail but the last 30 days.
Just Add recent: to your username e.g recent:Me@gmail.com.
Recent mode fetches the last 30 days of mail, regardless of whether it's been sent to another POP1 client already.
Link to back it up.
http://support.google.com/mail/bin/answer.py?hl=en&answer=47948


text:
Q: SQLAlchemy Session.commit() hangs I am using scoped_sessions from SQLAlchemy (to MySQL) and running the SQL commit inside tornado's threadpool. In my unit test, the first time Session.commit() passes but the second Session.commit() hangs. I am closing the session properly after the first time commit. I enabled SQLAlchemy logging and I can see that there is nothing emitted after INSERT INTO ... for the second commit.

A: Having same issue (hang in later commit) brought me to this question earlier today. I've managed to resolve the issue by making sure that only one session is in place.
In my case I'm running integration tests with session test for each test and doing roll back in tear-down as described in docs. I've got all DB stuff wrapped in DatabaseService class which is responsible for the test setup (a derived TestDatabaseClass doing the session setup in ctor).
The problem was that I managed to initialize the DatabaseService instance (with test setup) twice and experienced the hang in the later created nested session's commit (or in explicit flush call). So making sure that only one DatabaseService exists and all DB queries goes thru one session did resolve the problem for me.

A: What does you session init look like? Are you not using autoflush? Try calling session.flush() after the commit.

A: The problem was that I had a pending transaction in between the two tests. That was causing the next commit to just not  happen.


text:
Q: Update Trigger SQL Server I have two tables call it Table_A and Table_B. I want to create a trigger such that whenever the payment field in Table_A is updated a new record should be inserted into Table_B to show the difference in the amounts of total payments before and total payments now. The two table are below :
Table_A
A_id | payment |
 1   |  1000   |
 2   |   200   |

Table_B
B_id |  difference |

My implementation of the trigger is below. I am unsure how to calculate this difference:
CREATE TRIGGER trigger_Difference
ON Table_A
FOR UPDATE
AS
BEGIN
 DECLARE @Difference as INT
 DECLARE @PreviousDiff as INT

 BEGIN
    SELECT @PreviousDiff = SUM(payment)
    FROM Table_A
 END

 if update(payment)
    BEGIN
        SELECT @Difference = ***don't know what to put here***
        FROM inserted

        INSERT INTO Table_B (difference) VALUES (@Difference)
    END
END

A: Another solution of this problem is to use the OUTPUT clause in the stored procedure which does the updating or just adapt this method to your needs.
IF OBJECT_ID('TABLE_A') IS NOT NULL DROP TABLE TABLE_A
IF OBJECT_ID('TABLE_B') IS NOT NULL DROP TABLE TABLE_B
IF OBJECT_ID('sp_Payment_Update') IS NOT NULL DROP PROC sp_Payment_Update
GO

CREATE TABLE TABLE_A (
    A_ID INT IDENTITY(1,1),
    Payment INT
)

CREATE TABLE TABLE_B (
    B_ID INT ,
    OldPayment INT,
    NewPayment INT
)
GO

INSERT INTO TABLE_A VALUES (1000),(1200)
GO

CREATE PROC sp_Payment_Update
    @A_ID INT,
    @Payment INT
AS BEGIN

    UPDATE TABLE_A
    SET Payment = @Payment
        OUTPUT
            INSERTED.A_ID,
            DELETED.Payment,
            INSERTED.Payment
        INTO TABLE_B
    WHERE A_ID = @A_ID

    SELECT * FROM TABLE_A
    SELECT * FROM TABLE_B
END
GO

EXEC sp_Payment_Update 1, 1500

The update code itself will log as many changes you make with it in TABLE_B also you can put a UpdateDate column in TABLE_B with a default value of GETDATE() to make it more informative.


text:
Q: Handle Streaming video external Screen I'm here again with a new problem, basically now I got a requirement which the application needs to stream video on the mobile (Android), but it should not display the application content or the video in any other external output (if the application has a second output its should be showing a different layout), I've been trying to use some examples from Android and also looking at the API.
I can't show the external image in case it has another output presented. Any ideas how I can achieve this. am I missing something?
At the moment I'm trying to achieve my goal using MediaRouter, DisplayManager Presentation.
1 Option - Using MediaRouter
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        MediaRouter mediaRouter = (MediaRouter) getSystemService(Context.MEDIA_ROUTER_SERVICE);
        MediaRouter.RouteInfo route = mediaRouter.getSelectedRoute();

        if (route != null) {
             Display presentationDisplay = route.getPresentationDisplay();
             if (presentationDisplay != null) {
                 Presentation presentation = new DemoPresentation(this, presentationDisplay);
                 presentation.show();
             }
         }
         // Keep going here because theresnt presentation (secundary output) available

         setContentView(R.layout.video_player);
        }

2 Option - Using DisplayManager
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    mDisplayManager = (DisplayManager) getSystemService(Context.DISPLAY_SERVICE);
    Display[] presentationDisplays = mDisplayManager.getDisplays(DisplayManager.DISPLAY_CATEGORY_PRESENTATION);
    if (presentationDisplays.length > 0) {
        // If there is more than one suitable presentation display, then we could consider
        // giving the user a choice.  For this example, we simply choose the first display
        // which is the one the system recommends as the preferred presentation display.
        Display display = presentationDisplays[0];
        Presentation presentation = new DemoPresentation(this, display);
        presentation.show();
    }
    // Keep going here because theresnt presentation (secundary output) available

    setContentView(R.layout.video_player);
}

This is Presentation
  private final class DemoPresentation extends Presentation {
   final PresentationContents mContents = null;

   public DemoPresentation(Context context, Display display) {
       super(context, display);

   }

   @Override
   protected void onCreate(Bundle savedInstanceState) {
       // Be sure to call the super class.
       super.onCreate(savedInstanceState);
       // Get the resources for the context of the presentation.
       // Notice that we are getting the resources from the context of the presentation.
       // Inflate the layout.
       setContentView(R.layout.show_layout_external_screen);

  }

examples from  http://developer.android.com/reference/android/app/Presentation.html


text:
Q: Access companion object from case class (or vice-versa) using scala type macros I'm trying to create a value on a companion object based on the fields of a case class.
I'd like to do something like this:
case class A(
  val a: Int,
  val b: String
) extends MyTypeMacro

I'd like for this to add to add a value to its companion object...
object A {
  //Generate...
  val c: B = //Code value derived from case class fields...
}

Because companion objects and classes have access to each other, shouldn't
I be able to accomplish this by accessing the companion object from within the case class type macro?
Also... I'd like to add 'val c' whether object A is defined or not.

A: Unfortunately that's not possible yet. We're playing with something along these lines, but it's very early stage, so I can't say anything definitive.


text:
Q: Probability in Repetition question I just want to make sure that I am doing this correctly, and am hoping you guys can tell me if my thinking is correct. Thanks in advance!
If the chance of an outcome is 7/100
Then the chance of not having the outcome must be 93/100
So can I say that if I were to try an event x number of times, each time with a 7/100 chance of getting the outcome, i would have a (93/100)^x chance of not getting the outcome every single time?
And if so, does that give me approx. a 50% chance of getting the outcome if I try 10 times?
Please let me know if I'm thinking through this correctly or if there is anything I have missed; I just randomly thought of this today and it seems "iffy"


text:
Q: How to apply wordpress filter to ajax loaded data? I have created an ajax function and a filter for content, but my filter does not work when I am getting data using ajax response. Please help me. Here is my code:
add_action("wp_ajax_nopriv_thb_infinite_ajax", "thb_infinite_ajax");
add_action("wp_ajax_thb_infinite_ajax", "thb_infinite_ajax");
function thb_infinite_ajax() {
   $args = array(
        'p' => $previous_post->ID,
        'no_found_rows' => true,
        'posts_per_page' => 1
    );
    $query = new WP_Query($args);
    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();

        the_content();
    endwhile; else : endif;
}

add_filter ( 'the_content', 'wpsabox_author_box', 5 );

wpsabox_author_box($content) {
    return $content.'----';
}

JS code:
$.ajax( ajaxurl, {
    method : 'POST',
    data : {
        action : 'thb_infinite_ajax',
        post_id : tempid
    },
    beforeSend: function() {
        id = null;
    },
    success : function(data) {
        //container.removeClass('thb-loading');
        $( ".thb-loading" ).remove();
        $(data).appendTo( '#infinite-article' );
    }
});

Thanks in advance

A: Try this ...may be helpful to you  I change the_content function
function thb_infinite_ajax() {
   $args = array(
        'p' => $previous_post->ID,
        'no_found_rows' => true,
        'posts_per_page' => 1
    );
    $query = new WP_Query($args);
    if ($query->have_posts()) : while ($query->have_posts()) : $query->the_post();

        $result = get_the_content($post->ID);
    endwhile; else : endif;
echo $result;
}


text:
Q: Which Predictive Model? I'm lost when trying to choose the type of predictive model for my problem. Is it autoregressive model, nonlinear time series, Markov Chain or other? Can Someone please give me some advise?
78, 18, 51, 89, 19, 43, 62, 28, 94, 49
Suppose, everyday I'm given 10 data, and an example was listed above. They're numbers generated by two devices, namely Device A and Device B. Each of them is capable to generate numbers from 0 to 9.
The first number in the data is generated by Device A, while the second number is generated by Device B. For instance, for the first data of "78", "7" was generated by Device A and "8" was generated by Device B. Similarly, for the last data of "49", "4" was generated by Device A, and "9" was generated by Device B.
I want to be able to predict the next outcome variable after the last "49".
I have a total of 300 historical data for 30 day.
From my initial investigation for the 300 data, every device tend to produce repeated sequences. For instance, Device A will repeat the sequence "6-2-9-4" (as in the last 4 data). That means this sequence appeared twice within the 300 historical data for Device A. For another example, the sequence "8-1-9-9" (the 2nd to the 5th data) in Device B appeared twice, too. Each of them produces at least three repeated sequences.
I'd like to predict the next outcome variable after the last "49". Which model is more appropriate?
Thank you in advance!


text:
Q: How do I get ZFS working after upgrade to 16.04? I upgraded from 14.04 to 16.04 just recently and in the process my ZFS stopped working.  I was previously using ZFS packages from a PPA, but I have followed the directions to remove/purge them here: ZFS install on Ubuntu 16.04LTS
After the install I get an error when running an ZFS command:
:~$ sudo zfs get all
The ZFS modules are not loaded.
Try running '/sbin/modprobe zfs' as root to load them.

If I try to follow the directions I get the following error:
:~$ sudo /sbin/modprobe zfs
modprobe: ERROR: could not insert 'zfs': Invalid argument

When I reinstall ZFS I get some errors, but I'm not sure if these are related to my problem?
:~$ sudo apt-get install zfsutils-linux
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following additional packages will be installed:
  libnvpair1linux libuutil1linux libzfs2linux libzpool2linux zfs-doc zfs-zed
Suggested packages:
  zfs-initramfs
The following NEW packages will be installed:
  libnvpair1linux libuutil1linux libzfs2linux libzpool2linux zfs-doc zfs-zed zfsutils-linux
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 897 kB of archives.
After this operation, 2,902 kB of additional disk space will be used.
Do you want to continue? [Y/n] y
Get:1 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 zfs-doc all 0.6.5.6-0ubuntu16 [50.1 kB]
Get:2 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libuutil1linux amd64 0.6.5.6-0ubuntu16 [27.5 kB]
Get:3 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libnvpair1linux amd64 0.6.5.6-0ubuntu16 [23.4 kB]
Get:4 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libzpool2linux amd64 0.6.5.6-0ubuntu16 [384 kB]
Get:5 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 libzfs2linux amd64 0.6.5.6-0ubuntu16 [106 kB]
Get:6 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 zfsutils-linux amd64 0.6.5.6-0ubuntu16 [276 kB]
Get:7 http://us.archive.ubuntu.com/ubuntu xenial-updates/main amd64 zfs-zed amd64 0.6.5.6-0ubuntu16 [29.8 kB]
Fetched 897 kB in 0s (2,402 kB/s)
Selecting previously unselected package zfs-doc.
(Reading database ... 172013 files and directories currently installed.)
Preparing to unpack .../zfs-doc_0.6.5.6-0ubuntu16_all.deb ...
Unpacking zfs-doc (0.6.5.6-0ubuntu16) ...
Selecting previously unselected package libuutil1linux.
Preparing to unpack .../libuutil1linux_0.6.5.6-0ubuntu16_amd64.deb ...
Unpacking libuutil1linux (0.6.5.6-0ubuntu16) ...
Selecting previously unselected package libnvpair1linux.
Preparing to unpack .../libnvpair1linux_0.6.5.6-0ubuntu16_amd64.deb ...
Unpacking libnvpair1linux (0.6.5.6-0ubuntu16) ...
Selecting previously unselected package libzpool2linux.
Preparing to unpack .../libzpool2linux_0.6.5.6-0ubuntu16_amd64.deb ...
Unpacking libzpool2linux (0.6.5.6-0ubuntu16) ...
Selecting previously unselected package libzfs2linux.
Preparing to unpack .../libzfs2linux_0.6.5.6-0ubuntu16_amd64.deb ...
Unpacking libzfs2linux (0.6.5.6-0ubuntu16) ...
Selecting previously unselected package zfsutils-linux.
Preparing to unpack .../zfsutils-linux_0.6.5.6-0ubuntu16_amd64.deb ...
Unpacking zfsutils-linux (0.6.5.6-0ubuntu16) ...
Selecting previously unselected package zfs-zed.
Preparing to unpack .../zfs-zed_0.6.5.6-0ubuntu16_amd64.deb ...
Unpacking zfs-zed (0.6.5.6-0ubuntu16) ...
Processing triggers for libc-bin (2.23-0ubuntu7) ...
Processing triggers for initramfs-tools (0.122ubuntu8.8) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-77-generic
Processing triggers for systemd (229-4ubuntu17) ...
Processing triggers for ureadahead (0.100.0-19) ...
Processing triggers for man-db (2.7.5-1) ...
Setting up zfs-doc (0.6.5.6-0ubuntu16) ...
Setting up libuutil1linux (0.6.5.6-0ubuntu16) ...
Setting up libnvpair1linux (0.6.5.6-0ubuntu16) ...
Setting up libzpool2linux (0.6.5.6-0ubuntu16) ...
Setting up libzfs2linux (0.6.5.6-0ubuntu16) ...
Setting up zfsutils-linux (0.6.5.6-0ubuntu16) ...
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
insserv: warning: script 'plexmediaserver' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `plexmediaserver'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `plexmediaserver'
initctl: Unable to connect to Upstart: Failed to connect to socket /com/ubuntu/upstart: Connection refused
insserv: warning: script 'screen-cleanup' missing LSB tags and overrides
insserv: Default-Start undefined, assuming empty start runlevel(s) for script `screen-cleanup'
insserv: Default-Stop  undefined, assuming empty stop  runlevel(s) for script `screen-cleanup'
zfs-import-cache.service is a disabled or a static unit, not starting it.
zfs-import-scan.service is a disabled or a static unit, not starting it.
zfs-mount.service is a disabled or a static unit, not starting it.
Processing triggers for initramfs-tools (0.122ubuntu8.8) ...
update-initramfs: Generating /boot/initrd.img-4.4.0-77-generic
Setting up zfs-zed (0.6.5.6-0ubuntu16) ...
zed.service is a disabled or a static unit, not starting it.
Processing triggers for libc-bin (2.23-0ubuntu7) ...
Processing triggers for systemd (229-4ubuntu17) ...
Processing triggers for ureadahead (0.100.0-19) ...

A: Help from this post fixed my problem: Ubuntu 14.04 to 16.04 upgrade broke my ZFS
I'm not sure what actually fixed it this time, but here's a list of the things I tried before it started working.  My pool was mounted without even a reboot!
apt clean
apt update
apt purge zfs*
apt-get remove spl dkms spl-dkms
apt-get autoremove
add-apt-repository --remove ppa:zfs-native/stable

apt-get install zfsutils-linux
apt-get install spl-dkms


text:
Q: Given a degree x, find the nearest degree in an array of degrees I have an array of degrees, [10, 90, 200, 280, 355] for a circle.
I'm given a degree, let's say 1.  How do I determine that 1 is closest to 355 degrees?

A: Subtract the two numbers. If the difference is larger above 180 [or below -180], subtract [or add] 360. Now you can just compare absolute values of the difference.

A: Here is an actual formula:
degreediff = min(abs(x-y),360-abs(x-y))

A: This is more compact and efficient:
function difference(a, b) {
    var d = Math.abs(a - b);
    return d > 180 ? 360 - d : d;
};

function closest(a, bs) {
    var ds = bs.map(function(b) { return difference(a, b); });
    return bs[ds.indexOf(Math.min.apply(null, ds))];
};

> difference(1, 355)
6

> closest(1, [10, 90, 200, 280, 355])
355

A: You have one value which will contain the closes degree found found_degree and one for the actual difference degree_difference.
Next, iterate over the whole array and calculate two values: abs(degree_at_position - target_degree) and abs(degree_at_position - 360 - target_degree). If one of those values is smaller than degree_difference, you have a closer degree - store it in found_degree and update degree_difference accordingly.
That's it.
You maybe should initialise found_degree with -1 and degree_difference with 360, just to make sure you can properly interpret the result in case of an empty given array as well - or you simply handle the case of an empty input array separately.
Is this a homework, by the way?

A: The brute force approach would be something like this:
var closestElement;
var closestDivergence = 360;

var toCompare = 355;
var choices = [1, 90, 200, 280, 355];

for(i=0;i<choices.length;i++){
    var currentDivergence=choices[i] - toCompare;
    if (currentDivergence<0) {
        currentDivergence+=360;
    }
    if (currentDivergence < closestDivergence){
        closestDivergence = currentDivergence;
        closestElement = i;
    }
}

if (closestElement != NaN){
    alert('Closest value is '+choices[closestElement]);
}

A: Here's a nice little quickie
function closest(deg,ar) {
  return ar.sort(function(a,b){var c = deg; return Math.min(360 - (a-c),Math.abs(a-c)) - Math.min(360 - (b-c),Math.abs(b-c))})
}
var myArray = [355, 280, 200, 181, 90, 30];
alert(closest(180,myArray));

Sorts and returns the array according to which one is closest to the provided degree.  Index 0 is closest.  It does wrap making 355 closer to 0 than 10.

A: First check the array (check which element is closest) using the given degree (1 in your example), then add 360 and check with that degree (361). Compare which result is better:
x the given degree, y the first result, z the second result
if (abs(x-y) < 360+x-z)
    choose y;
else
    choose z;

If the array is sorted you can check it with a binary sort which gives you O(log n) time in worst case scenario. Otherwise you have to browse through the whole array two times.

A: This formula will only work with circles. It's pseudo code of course.
 degree diff = min(abs(x-y),360-abs(x-y))

A: Using the comments from this page I managed to come up with this code:
function closest(deg, degs) {

deg = (deg / 360 > 1 ? deg - (Math.floor(deg / 360)*360) : deg);

var difference = 360;
var closest = -1;

for(i=0;i<degs.length;i++) {

    var x = degs[i];

    var diff = Math.min(Math.abs(x-deg),360-Math.abs(x-deg))

    if(diff <= difference) {
        closest = i;
        difference = diff;
    }
};

return closest;

}
closest(1000, [10, 90, 200, 280, 355]);


text:
Q: Gradle Support for GCP Dataflow Templates? According to Google's Dataflow documentation, Dataflow job template creation is "currently limited to Java and Maven." However, the documentation for Java across GCP's Dataflow site is... messy, to say the least. The 1.x and 2.x versions of Dataflow are pretty far apart in terms of details, I have some specific code requirements that lock me into the 2.0.0r3 codebase, so I'm pretty much required to use Apache Beam. Apache is -- understandably -- quite dedicated to Maven, but institutionally my company's thrown the bulk of its weight behind Gradle, so much so that they migrated all their Java projects over to it last year and have pushed back against re-introducing it.
However, now we seem to be at an impasse, because we've got a specific goal to try to centralize a lot of our back-end gathering in GCP's Dataflow, and GCP Dataflow doesn't appear to have formal support for Gradle. If it does, it's not in the official documentation.
Is there a sufficient technical basis to actually build Dataflow templates with Gradle and the issue is that Google's docs simply haven't been updated to support this? Is there a technical reason why Gradle can't do what's being done with Maven? Is there a better guide for working with GCP Dataflow than the docs on Google's and Apache's websites? I haven't worked with Maven archetypes before, and all the searches I've done for "gradle archetypes" turn up results from, at best, over a year ago. Most of the information points to forum discussions from 2014 and version 1.7rc3, but we're on 3.5. This feels like it ought to be a solved problem, but for the life of me I can't find any current information on this online.

A: Commandline to Run Cloud Dataflow Job With Gradle
Generic Execution
$ gradle clean execute -DmainClass=com.foo.bar.myfolder.MyPipeline -Dexec.args="--runner=DataflowRunner --gcpTempLocation=gs://my-bucket/tmpdataflow" -Pdataflow-runner

Specific Example
$ gradle clean execute -DmainClass=com.foo.bar.myfolder.MySpannerPipeline -Dexec.args="--runner=DataflowRunner --gcpTempLocation=gs://my-bucket/tmpdataflow --spannerInstanceId=fooInstance --spannerDatabaseId=barDatabase" -Pdataflow-runner

Explanation of Commandline

*

*gradle clean execute uses the execute task which allows us to easily pass commandline flags to the Dataflow Pipeline. The clean task removes cached builds.

*-DmainClass= specifies the Java Main class since we have multiple pipelines in a single folder. Without this, Gradle doesn't know what the Main class is and where to pass the args. Note: Your gradle.build file must include task execute per below.

*-Dexec.args= specifies the execution arguments, which will be passed to the Pipeline. Note: Your gradle.build file must include task execute per below.

*--runner=DataflowRunner and -Pdataflow-runner ensure that the Google Cloud Dataflow runner is used and not the local DirectRunner

*--spannerInstanceId= and --spannerDatabaseId= are just pipeline-specific flags. Your pipeline won't have them so.
build.gradle contents (NOTE: You need to populate your specific dependencies)
apply plugin: 'java'
apply plugin: 'maven'
apply plugin: 'application'

group = 'com.foo.bar'
version = '0.3'

mainClassName = System.getProperty("mainClass")

sourceCompatibility = 1.8
targetCompatibility = 1.8

repositories {

     maven { url "https://repository.apache.org/content/repositories/snapshots/" }
     maven { url "http://repo.maven.apache.org/maven2" }
}

dependencies {
    compile group: 'org.apache.beam', name: 'beam-sdks-java-core', version:'2.5.0'
    // Insert your build deps for your Beam Dataflow project here
    runtime group: 'org.apache.beam', name: 'beam-runners-direct-java', version:'2.5.0'
    runtime group: 'org.apache.beam', name: 'beam-runners-google-cloud-dataflow-java', version:'2.5.0'
}

task execute (type:JavaExec) {
    main = System.getProperty("mainClass")
    classpath = sourceSets.main.runtimeClasspath
    systemProperties System.getProperties()
    args System.getProperty("exec.args").split()
}

Explanation of build.gradle

*

*We use the task execute (type:JavaExec) in order to easily pass runtime flags into the Java Dataflow pipeline program. For example, we can specify what the main class is (since we have more than one pipeline in the same folder) and we can pass specific Dataflow arguments (i.e., specific PipelineOptions). more here

*The line of build.gradle that reads runtime group: 'org.apache.beam', name: 'beam-runners-google-cloud-dataflow-java', version:'2.5.0' is very important. It provides the Cloud Dataflow runner that allows you to execute pipelines in Google Cloud Platform.

A: There's absolutely nothing stopping you writing your Dataflow application/pipeline in Java, and using Gradle to build it.
Gradle will simply produce an application distribution (e.g. ./gradlew clean distTar), which you then extract and run with the --runner=TemplatingDataflowPipelineRunner --dataflowJobFile=gs://... parameters.
It's just a runnable Java application.
The template and all the binaries will then be uploaded to GCS, and you can execute the pipeline through the console, CLI or even Cloud Functions.
You don't even need to use Gradle. You could just run it locally and the template/binaries will be uploaded. But, I'd imagine you are are using a build server like Jenkins.
Maybe the Dataflow docs should read "Note: Template creation is currently limited to Java", because this feature is not available in the Python SDK yet.

A: Update: 7th December 2020
We can stage dataflow templates using gradle as well.
For stage:
Here are the mandatory parameters:

*

*project

*region

*gcpTempLocation (good to have if you don't have bucket create access, if not given it will create automatically)

*stagingLocation

*templateLocation
Here is the sample command line in gradle:
gradle clean execute -D mainClass=com.something.mainclassname -D exec.args="--runner=DataflowRunner --project=<project_id> --region=<region_name> --gcpTempLocation=gs://bucket/somefolder --stagingLocation=gs://bucket/somefolder --templateLocation=gs://bucket/somefolder"

Assumptions:

*

*GOOGLE_APPLICATION_CREDENTIALS environmental variable is set with service account key.

*gradle is installed.

*JAVA_HOME environmental variable is set.

*Bare minimum dependencies are added.

*

*compile 'org.apache.beam:beam-sdks-java-core:2.22.0'

*compile 'org.apache.beam:beam-sdks-java-io-google-cloud-platform:2.22.0'

*compile 'org.apache.beam:beam-sdks-java-extensions-google-cloud-platform-core:2.22.0'

*compile 'org.apache.beam:beam-runners-google-cloud-dataflow-java:2.22.0'


text:
Q: Can dynamically add trait in object?

I want to dynamically add/set a Trait in object. How can I do it?
For example i have $object;
$object->setTrait($someTrait);

Thanks for help.
Edit
<?php

namespace GamApi\Models\Traits;

use GamApi\Scopes\OrganizationScope;

/**
 *
 * Trait BelongsToOrganizationTrait
 * @package GamApi\Models\Traits
 */
trait BootOrganization
{
    /**
     * For saving resource auto-complete organization_id attribute
     * Add global OrganizationScope
     *
     */
    public static function boot()
    {
        parent::boot();

        // global organization_id scope
        static::addGlobalScope(new OrganizationScope());

        // set organization_id for saving
        static::creating(function ($model){
            if (defined('ORGANIZATION_ID')) {
                $model->organization_id = ORGANIZATION_ID;
            }
        });
    }
}

I want to test this class, and I think that I can make $object then dynamically insert Trait to the object and then test Trait boot method.


text:
Q: React - "Attempted import error" when building the app from the command line When I try to build my React App (17.0.1) from the command line, using either "npm start" or "npm run build", I get the following error:

./node_modules/@progress/kendo-react-grid/dist/es/footer/Footer.js
Attempted import error: 'BrowserSupportService' is not exported from '@progress/kendo-react-common'.

Yet if I open up my project in VS Code and run the build via the Terminal menu -> Run build task -> npm: build / react-scripts build, it will build just fine. This isn't a pressing issue since I do have a way to build it, but does anyone know why I can't get a successful build from the command line? I can provide more info about the project/environment if needed, but I wasn't sure what would be helpful here.


text:
Q: Get rows matching the combination of ids in sql server 2008 I have a combination of ids present in a table1 as listed below :
Combi1   Combi2
---------------
1000     26341
26341    26580
1000     26580

Now, I have a table2 which has rows as listed below :
ID       CombiIDs
------------------
26131    26341
26131    26580
26131    21234
21411    26580
21411    21212
21411    21234

I want to get those rows from table2 where there is match of combination of table1. i.e
1000,26341(this combination from table1) doesn't have any row in match as a combination in table 2 whereas 26341,26580 (this combination from table1) has rows matching in table2(i.e.26131).
I want an sql query to achieve this kind of output.

A: select *
from T2 T21
inner join T2 T22
on T21.ID = T22.ID
inner join T1 T1
on T21.CombiIDs = T1.Combi1
and T22.CombiIDs = T1.Combi2


text:
Q: What is this model trying to imply about "isasmuch as" and "insofar as"? I recently found a chart listing the distinctions between the two conjunctions. But I am not really able to make much sense of this chart. I would gladly appreciate if anyone could make the distinction between these two words.
Source: aprendeinglesenleganes.com Inasmuch as vs Insofar as
Inasmuch as:
Inasmuch as conjunction (formal)
Synonyms: seeing that, since
Syntax Formula: Inasmuch as+fact
Meaning: used to explain the way in which what you are saying is true
Examples:

*

*He was a very rather unusual musician inasmuch as he was totally deaf.

*Ann is guilty, inasmuch as she knew what the others were planning.

*They're rather similar, inasmuch as they are the same size and colour.
Insofar as:
Insofar as conjunction (formal)
Synonyms: as long as/ only if
Syntax Formula: Insofar as+ quantifiable fact (sth happens to a certain extent)
Meaning: to the degree that
Examples:

*

*She cites other scholars' works only insofar as it supports her own theories.

*The news is good insofar as it suggests that a solution may be possible

*Looking back helps insofar as it helps you learn from your mistakes.

A: You may think of inasmuch as as loosely equivalent to "given that," while insofar is approximately the same as "as long as."
You won't hear these much in conversation.  And I often go a whole year or more without coming across either one even in formal writing.

A: insofar is conditional on a future or unknown variable: if A, then B
inasmuch is conditional on a past or known variable: Since A, then B

A: Inasmuch as certainly has an overlap in meaning with insofar as:

*

*inasmuch  ... Phrases

inasmuch as [also in as much as]
1 To the extent that; insofar as.
▪ The two hurricanes are definitely going to have an impact on home
prices inasmuch as they're going to impact the availability of
building materials and the availability of labor.
▪ I'm game to try and explain it, inasmuch as I can.
1.1 Considering that; since (used to specify the respect in which a statement is true or untrue)
▪ it was not really a still life inasmuch as all the objects were in
motion
▪ Breaking our addiction to foreign oil is one of the reasons
commonly advanced in support of ANWR drilling, inasmuch as Alaska is
part of the United States.

[Lexico; adjusted]

*

*inasmuch as [conjunction]   [formal]
used to introduce a phrase that explains (a) why or (b) how much something
described in another part of the sentence is true:
▪ Inasmuch as you are their commanding officer, you are responsible for the behaviour of these men.

[Cambridge Dictionary; slightly adjusted]
Here, obviously, the 'because', 'considering that', rather than the 'to the extent that' sense must be inferred. "Am I their commanding officer? Well, a bit." is Cleesian.
...........................
However, insofar as only carries the 'to the extent / degree that' of the two senses listed for 'inasmuch as':

*

*insofar as [conjunction]:

to the extent or degree that
▪ we agree only insofar as the budget is concerned
▪ She had done her best to comfort him, insofar as she was able.

[Merriam-Webster]; last example [Cambridge Dictionary]


text:
Q: How to check, if user commented before, on comment_post action? I want check, if user commented post, in comment_post action. So i make this:
function checkUserComment( $comment_ID ) {

    $comment = get_comment( $comment_ID );
    $postID = $comment->comment_post_ID;
    $authorID = $comment->user_id;

    // If user commented this post already, don't update post meta.
    if( get_comments( array( 'post_id' => $postID, 'user_id' => $authorID ) ) )
        return;

    update_post_meta($postID, 'testMeta', 'testValue');

}

add_action( 'comment_post', 'checkUserComment', 10, 2 );

It must doesn't update post_meta if user comments first time. But it updates post_meta anyway.

A: From the WordPress Codex:
comment_post is an action triggered immediately after a comment is inserted into the database.
Instead, I think what you want to try is to hook into preprocess_comment and not comment_post.


text:
Q: RMAN Restore backupset from tape to disk I am trying to restore a backupset tag from tape to disk, because I need to recover on another location (development environment).
The datacenter backups are made using Netbackup and I dont have access to it.
So, I am trying to restore through RMAN.
This is what I did so far:
rman target / catalog "user_rcat/passs@rcat" << EOF
run {
ALLOCATE CHANNEL CH00 TYPE 'SBT_TAPE';
SEND 'NB_ORA_CLIENT=oracle-db,NB_ORA_SID=ORCL,NB_ORA_SERV=bkp-server';
BACKUP BACKUPSET FROM TAG 'LVL0_05012015' FORMAT '/rman_backup/LVL0_05012015_%U' TAG 'JAN-05';
RELEASE CHANNEL CH00;
}
EOF

But, it says that it doesnt match any backups.
When I list
list backup tag 'LVL0_05012015'

The backups are there...
Anyone?

A: In case someone like me find this thread even though it is one year old, I found an answer to this question directly in the Oracle Documentation (Database Backup and Recovery Reference 11.2) of the RMAN BACKUP command.
There, it is stated in the BACKUPSET sub-section that :

You cannot back up from tape to tape or from tape to disk: only from disk to disk or disk to tape.

Also, the Oracle Support note ID 2123833.1 give some additional explanation and a possible alternative which consist in launching a RESTORE after having SET NEWNAME for datafiles aimed by the restore operation.


text:
Q: Get text from auto complete field i try to make a tool get information from etsy.com and i have some problem.
U can go to etsy.com then type something in search input, they will auto complete
I dont know how to get them use HTML agility pack, do u have any idea?
http://s17.postimg.org/5ogqo04in/searc.png
Image for every one can see.
How can i get data when submited some text from same page.
Here is code in search input text i got.
<form id="search-bar" action="http://www.etsy.com/search.php" method="GET">

 <input value="belly button jewelry" autocomplete="off" id="autocomplete-field" name="search_query" class="autocomplete text" placeholder="What are you looking for?" data-as-disable="" tabindex="0" type="text">

Thanks for your reading. :)

A: They are using ajax for autofilling the text box. they call the url
http://www.etsy.com/suggestions_ajax.php?version=&search_query=hello&search_type=all&hp_ref=primary

you can search it with changing the

search_query

it will return a json response.


text:
Q: Which layer do DDD Repositories belong to? In his DDD book Evans promotes the idea of layered architecture, and in particular that the business logic should be confined to domain layer and separated from UI/persistence/other concerns. He also introduces Repository pattern as a mean to abstract access and persistent storage to Entities and Value Objects. To me the following left unclear:

*

*Which layer Repositories belong: the Domain Layer, Persistence Layer or something in the middle? (It seems that if it were below Domain Layer it would violate Layered Architecture principle, because it depends on a domain object which it stores)

*Can Entities, Value Objects or Domain Services call Repositories?

*Should Repositories be abstracted from storage technology (which would be implied if they belong to domain layer) or can they leverage those storage technologies?

*Can Repositories contain business logic?

*Have you applied these constraints in practice and what was the effect on the quality of your project?

(I am mostly interested in DDD perspective)

A: *

*The repository interface belongs in the domain layer. The repository implementation should be elsewhere, but the literature is not clear.  Options include: infrastructure layer (probably the most consonant with DDD precepts); application layer; persistence layer; repository layer or sub-layer.

*No. That would be a violation of the DDD-driven layered architecture, and would likely create a cyclic dependency.

*The recommended practice today is to define a repository interface that is abstracted from the persistence technology. The repo impl OTOH is not. Evidently, application services should use the repo interface.

*Repositories should not contain business logic. However, they may contain query logic. Some may see query logic as business logic, especially if it's a complex query. If you have complex repo queries, maybe your aggregate is larger than it should or maybe you're overusing the query language power. Using repositories for reporting needs is an antipattern.

*In our organization we place repository interfaces alongside entities in the domain layer. App services directly use entities, VOs and repositories (via the interface). We use the JpaRepository interface. With respect to answer (1), this alternative has the benefit that you don't need to provide the repository implementation--it's automagically given to you by the Spring framework.
My answers are primarily influenced by Patterns, Principles, and Practices of DDD by Millet and Tune.

A: Repositories and their placement in the code structure is a matter of intense debate in DDD circles. It is also a matter of preference, and often a decision taken based on the specific abilities of your framework and ORM.
The issue is also muddied when you consider other design philosophies like Clean Architecture, which advocate using an abstract repository in the domain layer while providing concrete implementations in the infrastructure layer.
But here's what I have discovered, and what has worked for me, after trying out different permutation/combinations.

*

*From a DDD perspective, Repositories sit between Application Services and Domain Objects.

*Domain Objects encapsulate behavior and contain the bulk of business logic, enforcing invariants at the aggregate level.

*Application services receive calls from UI/API/Controllers/Channels (external facing), initial repositories to load aggregates (if needed), invoke domain model for the necessary changes, then use the repositories again to persist aggregates

To your questions:

Which layer Repositories belong: the Domain Layer, Persistence Layer or something in the middle?

*

*I would say there are three distinct layers in DDD applications - the inner domain layer, the outer application layer, and the external world (includes the API/UI).
The domain layer contains aggregates, entities, value objects, domain services, and domain events. These elements are only dependent on each other and actively avoid dependencies any outer layers.
The application layer contains Application Services, Repositories, Message Brokers, and whatever else you need to make your application practically possible. This layer is where most of the persistence, authorization, pub-sub processing, etc. happens. Application Layer depends and knows about the domain layer elements, but follows DDD guidelines when accessing the domain model. For example, it will only invoke methods on Aggregates and Domain Services.
The outermost layer includes API Controllers, serializers, authentication, logging, etc., whatever is not related to business logic or your domain, but very much part of your application.

Can Entities, Value Objects or Domain Services call Repositories?

*No. The domain layer should preferably remain agnostic to repositories. Application services should take on the responsibility of transactions and repository interactions.

Should Repositories be abstracted from storage technology (which would be implied if they belong to domain layer) or can they leverage those storage technologies?

*Repositories lean towards the domain side, meaning they contain methods that are meaningful from a domain point of view (like GetAdults() or GetMinors()). But the concrete implementation can be done in a couple of ways:

*

*You could use an abstract repository to declare the necessary methods, and then create concrete implementations for different databases. The database implementation can be chosen at the beginning of application startup, based on your configurations. Note that even in this case, Domain layer has nothing to do with repositories

*Repositories could act like wrappers and make use of underlying DAO objects (one per table/document) that implement the actual logic for interacting with the database. The DAO objects are initialized usually with dependency injection if your framework/language supports it, or they could be initialized manually based on active configuration.

Can Repositories contain business logic?

*Repositories represent domain concepts, with meaningful method names, but seldom contain any business logic. They encapsulate the database query and give it a conceptual name that usually is derived directly from the ubiquitous language. It is so much better to have a method called GetAdults() instead of .filter(age > 21).

Have you applied these constraints in practice and what was the effect on the quality of your project?

*If you restrict yourself to using repositories only in application services, and control transactions at one place (usually with Unit of Work pattern), Repositories are pretty easy to work with. In my past projects, I have found it extremely useful to restrict all database interaction to repositories instead of sprinkling lifecycle methods in the domain layer.
When I called lifecycle methods (like save, update, etc.) from the aggregate layer, I found it to be extremely complex and difficult to reliably control ACID transactions.

A:
Which layer Repositories belong: the Domain Layer, Persistence Layer or something in the middle?

If you believe in dependency inversion*, then repositories are contracts defined by the application layer and implemented by the persistence layer.  The contract itself has an implicit dependency on the domain model (via the appearance of the domain entities in the signature), and the implementation of a repository will often include a direct dependency on the factory responsible for creating instances.

Can Entities, Value Objects or Domain Services call Repositories?

Ideally, they should not need to.  The domain model sits at the core of the onion; it's a pure in memory representation of (a part of the) domain.
You may sometimes see a domain service that acts as a facade provides a read-only view of cached data.  But writing to a repository from the domain model is normally out of bounds (the dependency arrows don't point that direction).

Should Repositories be abstracted from storage technology

Ideally, the repository contract explicitly describes the capabilities required by the application, without necessarily coupling you to a specific technology.

Can Repositories contain business logic?

In its ideal form, a repository is a facade for a domain agnostic collection.  So no.  This is somewhat connected to the previous question; if the implementation of the repository includes important business logic, it becomes that much harder to find the logic, and to recognize the implications that logic has on your choice of storage.
A real portion of the motivation for these patterns is an attempt to make them easier to maintain -- which includes making it easier to guess where in the code base some important concept is going to be realized.

Have you applied these constraints in practice and what was the effect on the quality of your project?

This is pretty subjective, but I haven't found much joy in the repository pattern as described by Evans.  Part of the problem is that the patterns are very much based in the Kingdom of Nouns; another is that they appear to be coupled to the idioms of Java circa 2003.
The idea is right -- the application shouldn't need to know the details of where mutable state is managed.  We can correctly place a boundary between those concepts.  Similarly, the domain model should be independent from its application host, so that the host can be changed.
Where things tend to break down is save.  How do you get the data you need out of the object and into your storage?  The domain model has it, the repository needs it, so you end up with some persistence pollution entering your "pure" domain model.  The pollution can take a number of forms -- ORM hooks, public members, serialization APIs....

Let's assume that Entities have to be immutable. By definition repository is an emulation of in-memory collection of entities, sort of Map

Very close.  It's probably a better fit, semantically, if you think in terms of messages, rather than entities.  Both the domain model and persistence need to know how to extract information from the messages to get their job done.  See Boundaries, by Gary Bernhardt
Alternatively, you can keep the idea of the repository that stores mutable entities (somewhere), by separating those entities from the business logic.  In that approach, the entity API is consumed by the domain model, but implemented by the persistence component.  This keeps the mutable state out at the boundary of your solution, where it belongs.

* The term "Dependency Inversion" is as ill-defined as all of the other SOLID principles, and articles on the internet all parrot the same tired phrases to define it.  For purposes of this answer, dependency inversion can be defined as "handing a class its concrete dependencies through constructor parameters that are defined by interfaces."  See here for an example.

A: So, if you disregard all the "aggregate design rules" talk you can find on the net, and focus on how aggregates are described in the book, they are meant to be these bundles of objects that form some sort of a graph, with an explicit design boundary, and one object selected as the root. The root acts as an interface (facade) to the aggregate, it encapsulates it, and is responsible for maintaining consistency within that boundary. Your domain model is then, more or less, composed of a number such aggregates that can be reached by traversal. Another important role the aggregates have is to simplify the web of dependencies between objects, so aggregate relationships should be strategically designed.
The question is, how do you obtain the initial aggregates - the ones you start the traversal from?
If you take a closer look at how Evans defined repositories, the emphasis is not on persistence (although generally speaking they do eventually end up going to the database) - instead they are a means to obtain the initial "surface level" aggregate roots, letting you start there and reach the others via traversal.
To quote the Blue Book:

"Whether to provide a traversal or depend on a [database] search
  becomes a design decision, trading off the decoupling of the search
  against the cohesiveness of the association. [...] The right
  combination of search and association makes the design
  comprehensible."

That means that the dependency structure is such that (1) when an execution path is entered, a Use Case1 that needs an aggregate must ask a repository to obtain one, and (2) the the repository knows about certain "surface level" aggregates, but the core domain doesn't know about repositories.
There is some room for variation when it comes to how you organize that into layers, but you can see that the above structure imposes some constraints on the dependency directions across and within layers. So to answer you question.

*

*Which layer Repositories belong: the Domain Layer, Persistence Layer or something in the middle?

A repository as conceptualized by DDD is an abstraction - it is not itself in the persistence layer, it encapsulates database access - meaning that it forwards reconstitution request to some data access gateway that is in the persistence layer (either via composition, or via dynamic dispatch).

"For each type of object that needs global access [...] set up access through a well-known global interface. [Repositories encapsulate] the actual storage and query technology. Provide REPOSITORIES only for AGGREGATE roots that actually need direct access."

They are meant to be accessible throughout the application layer, so that seems to be a natural place for them to reside, but the actual implementation will go across layers. The reason for the encapsulation is to keep application service layer code simple and decoupled from persistence-related boilerplate.

(It seems that if it were below Domain Layer it would violate Layered Architecture principle, because it depends on a domain object which it stores)

The repository abstraction is not below the Domain Layer, but it does depend on the domain objects - that's the whole point. You ask it for an aggregate root using the language of the domain model (e.g., you pass it an ID), it then figures out how to turn that into a database query; the database returns its representation, and the repository then uses it to reconstitute the requested aggregate, and returns that. Beyond that, it doesn't contain any significant business logic, and it certainly doesn't contain any problem-specific (core) domain logic.
In practice, though, you want to try and arrange things in a way that avoids elaborate and costly translations between representations.
Another thing that is discussed in the book is that it is desirable to find a way to express aggregate boundaries in the code itself, but that it can be a bit tricky to do so. The most common thing you'll find on the web is the idea popularized by Vaughn Vernon, that states that aggregates should reference other aggregates exclusively via their identity. This can work well in many cases, and has the advantage of clearly delineating aggregate boundaries in code, but IMO it's too restrictive and somewhat database-centric in thinking for it to be elevated to the status of a rule that you enforce or even default to when it comes to aggregate design. So don't think of it as the only option - you could design a different scheme.
If you do go down that path, then you have to figure out how to traverse across aggregates given that specific restriction. Vaughn Vernon recommends to "use a repository or domain service to look up dependent objects ahead of invoking the aggregate behavior" (and not use a repository from within the aggregate, to prevent the aggregates from having a dependency on one or more repositories).
There's a bit of a tradeoff here (as with every design decision): A certain amount of knowledge about the inner workings of the aggregate is being pushed elsewhere, and the signatures of the aggregates' methods become more verbose (and some of the dependencies less obvious as they aren't visible in the constructor).
This is a viable approach, but it should be noted that it's a little different than what's described in Evans' book - where the idea was to be very deliberate about which aggregate roots should be obtained through repositories, and which via traversal, and under what circumstances - based on your understanding of the domain, business processes, access patterns, etc.

1 The two layers of interest here, in DDD terminology, are the Application Layer and the Domain Layer. The Application Layer ("defines the jobs the software is supposed to do and directs the expressive domain objects to work out problems") roughly corresponds to the Application Business Rules (Use Cases) layer in Clean Architecture ("use cases [...] direct [the] entities to use their enterprise wide business rules to achieve the goals of the use case").

A: According to dddsample you can have a Repository as interface(CargoRepository) in domain layer and actual implementation(CargoRepositoryHibernate) in Infrastructure layer.
Layered Architecture picture (also from DDD blue book):


text:
Q: Fill NA column values within a keyed row with non-NA values from another same keyed row I was given data formatted in a weird fashion
df = pd.DataFrame([[1, 2, None, None], [1, None, 4, None], [1, None, None, 9, None], [1, None, None, None, 4]])
df.columns = ['name', 'c1', 'c2', 'c3', 'c4']

  name  c1  c2  c3  c4
    1   2.0 NaN NaN NaN
    1   NaN 4.0 NaN NaN
    1   NaN NaN 9.0 NaN
    1   NaN NaN NaN 4.0
    2   1.0 NaN NaN NaN
    2   NaN 4.0 NaN NaN

Given the key "name", I want to basically fill the NaN values in the first row of a key with the first other non-NaN value and condense it to one row, like this.
  name  c1  c2  c3  c4
    1   2.0 4.0 9.0 4.0
    2   1.0 4.0 NaN NaN

What's the best function to accomplish this? A groupby with first() to grab the first non-NA value?

A: How about this?
df = pd.DataFrame([[1, 2, None, None], [1, None, 4, None], [1, None, None, 9, None], [1, None, None, None, 4],[2, 1, None, None, None],[2, None, 4, None, None]])
df.columns = ['name', 'c1', 'c2', 'c3', 'c4']
df.bfill(inplace=True)
newdf = df.groupby('name').head(1)
newdf

name    c1      c2      c3      c4
1       2.0     4.0     9.0     4.0
2       1.0     4.0     NaN     NaN


text:
Q: Find all substrings that don't contain the entire set of characters This was asked to me in an interview.
I'm given a string whose characters come from the set {a,b,c} only. Find all substrings that dont contain all the characters from the set.For e.g, substrings that contain only a's, only b's, only c's or only a,b's or only b,c's or only c,a's. I gave him the naive O(n^2) solution by generating all substrings and testing them.
The interviewer wanted an O(n) solution.
Edit: My attempt was to have the last indexes of a,b,c and run a pointer from left to right, and anytime all 3 were counted, change the start of the substring to exclude the earliest one and start counting again. It doesn't seem exhaustive
So for e.g, if the string is abbcabccaa,
let i be the pointer that traverses the string. Let start be start of the substring.
1) i = 0, start = 0
2) i = 1, start = 0, last_index(a) = 0 --> 1 substring - a
3) i = 2, start = 0, last_index(a) = 0, last_index(b) = 1 -- > 1 substring ab
4) i = 3, start = 0, last_index(a) = 0, last_index(b) = 2 --> 1 substring abb
5) i = 4, start = 1, last_index(b) = 2, last_index(c) = 3 --> 1 substring bbc(removed a from the substring)
6) i = 5, start = 3, last_index(c) = 3, last_index(a) = 4 --> 1 substring ca(removed b from the substring)
but this isn't exhaustive

A: Given that the problem in its original definition can't be solved in less than O(N^2) time, as some comments point out, I suggest a linear algorithm for counting the number of substrings (not necessarily unique in their values, but unique in their positions within the original string).
The algorithm

*

*count = 0

*For every char C in {'a','b','c'} scan the input S and break it into longest sequences not including C. For each such section A, add |A|*(|A|+1)/2 to count. This addition stands for the number of legal sub-strings inside A.

*Now we have the total number of legal strings including only {'a','b'}, only {'a','c'} and only {'b','c'}. The problem is that we counted substrings with a single repeated character twice. To fix this we iterate over S again, this time subtracting |A|*(|A|+1)/2 for every largest sequence A of a single character that we encounter.

*Return count

Example
S='aacb'
breaking it using 'a' gives us only 'cb', so count = 3. For C='b' we have 'aac', which makes count = 3 + 6 = 9. With C='c' we get 'aa' and 'b', so count = 9 + 3 + 1 = 13. Now we have to do the subtraction: 'aa': -3, 'c': -1, 'b': -1. So we have count=8.
The 8 substrings are:
'a'
'a' (the second char this time)
'aa'
'ac'
'aac'
'cb'
'c'
'b'

A: To get something better than O(n) we may need additional assumptions (maybe longest substrings with this property).
Consider a string of the form aaaaaaaaaabbbbbbbbbb of length n. There is at least O(n^2) possible substrings so if we want to list them all we need O(n^2) time.
I came up with a linear solution for the longest substrings.
Take a set S of all substrings separated by a, all substrings separated by b and finally all substrings separated by c. Each of those steps can be done in O(n), so we have O(3n), thus O(n).
Example:
Take aaabcaaccbaa.
In this case set S contains:

*

*substrings separated by a: bc, ccb

*substrings separated by b: aaa, caacc

*substrings separated by c: aaab, aa, baa.

By the set I mean a data structure with adding and finding element with a given key in O(1).


text:
Q: I am looking for a way to create asynchronous & stateless ssh connection using JSch? Hi I am trying to create a putty like interface in my web application.
1.  It will have a text box to enter a command (Temporarily hard coding the server user credentials) and If the user hits return key, it will send ajax request to the server.
2.  Server will creates jsch & session and channle object and execute that user command in the remote shell.
3.  And I will populate the response in user browser screen.
I don't want the point number two as above for further request. I want it as "Server will check for existing channel and using that channel it will execute".
To achieve this I tried storing the channel object in session. But I need to execute the .connect() method of the channel object on every request (Which return Last Login time…., It seem it is doing login process using the older credentials) ie, Only the state is store in terms of user name & password and not the connect and server session.
    Could someone suggest me a way to get a solution for my problem with JSch.
Or suggest me any other way to achieve my requirement. (Putty like interface in Browser window)
ie, I am looking for a way to create asynchronous & stateless ssh connection using  JSch ?
This is my code
protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    String createSession = request.getParameter("createSession");
    String logOff = request.getParameter("logOff");
    userVoice = request.getParameter("string");
    userVoice = userVoice == null ? "" : userVoice;
    userVoice = userVoice + "\n";
    writer = response.getWriter();
    try {
        HttpSession httpSession = request.getSession();
        //channel = (Channel) httpSession.getAttribute("channel");
        if(channel!= null && channel.isConnected())
        {
            /*
             * channelOutput = (InputStream) httpSession
             * .getAttribute("channelOutput"); channelInput = (OutputStream)
             * httpSession .getAttribute("channelInput");
             */
            channelOutput = channel.getInputStream();
            channelInput = channel.getOutputStream();

        }

        if (createSession != null && logOff == null) {
            String username = request.getParameter("username"); // "bninet";
            String password = request.getParameter("password"); // "password";
            String host = request.getParameter("host"); // "10.77.246.120";
                                                        // // sample ip
                                                        // address
            int port = Integer.parseInt(request.getParameter("port"));
            JSch jsch = new JSch();
            Session session = jsch.getSession(username, host, port);
            session.setPassword(password);
            Properties properties = new Properties();
            properties.put("StrictHostKeyChecking", "no");
            session.setConfig(properties);
            session.setPassword(password);
            session.connect(30000);
            channel = session.openChannel("shell");
            setIOforChannel(channel, httpSession);
        //  httpSession.setAttribute("channel", channel);
        } else if (channelOutput != null && channelInput != null) {
            if (logOff != null) {
                userVoice = "exit";
            }
            channelInput.write((userVoice + "\n").getBytes());
            //channel.connect();

            if (logOff != null) {
                channel.disconnect();
            //  httpSession.removeAttribute("channelOutput");
            //  httpSession.removeAttribute("channelInput");
            }
        } else {
            writer.write("No session Available.\n Please create a session using createSession tool ");
            return;
        }
        Thread.sleep(1000);
        String returnData = streamToString(channelOutput);
        int i = 0;
        while (!returnData.isEmpty() && i < 5) {
            writer.write(returnData);
            Thread.sleep(1000);
            returnData = streamToString(channelOutput);
            i++;
        }

    } catch (Exception e) {
        writer.write("Error Occured --  " + e.getMessage());
    } finally {
        writer.flush();
        writer.close();

    }

}

A: If you reuse a Channel, it reuses the session, which holds your credentials.
In order to use different credentials, you would need to disconnect the session, change its settings and reconnect it.
How to disconnect the session.
If you are wanting to reuse the session, you dont need to reconect the channel each time.  Connect it once as a shell, plugging an input and output stream into it.  Use the streams to pass commands and capture output.
See the JSCH example on the JCraft website.


text:
Q: How best to calculate a year over year difference in R Below is the sample code. The task at hand is to create a year over year difference (2021 q4 value - 2020 q4 value) for only the fourth quarter and percentage difference. Desired result is below. Usually I would do a pivot_wider and such. However, how does one do this and not take all quarters into account?
  year <- c(2020,2020,2020,2020,2021,2021,2021,2021,2020,2020,2020,2020,2021,2021,2021,2021)
  qtr <- c(1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4)
  area <- c(1012,1012,1012,1012,1012,1012,1012,1012,1402,1402,1402,1402,1402,1402,1402,1402)
  employment <- c(100,102,104,106,108,110,114,111,52,54,56,59,61,66,65,49)

  test1 <- data.frame (year,qtr,area,employment)

  area       difference     percentage
  1012           5              4.7%
  1402           -10            -16.9

A: You would use filter on quarter:
test1 |>
  filter(qtr == 4) |>
  group_by(area) |>
    mutate(employment_lag = lag(employment),
           diff = employment - employment_lag) |>
    na.omit() |>
  ungroup() |>
  mutate(percentage = diff/employment_lag)

Output:
# A tibble: 2 × 7
   year   qtr  area employment  diff employment_start percentage
  <dbl> <dbl> <dbl>      <dbl> <dbl>            <dbl>      <dbl>
1  2021     4  1012        111     5              106     0.0472
2  2021     4  1402         49   -10               59    -0.169

Update: Adding correct percentage.


text:
Q: Why are $2$-covectors on $\mathbb{R}^3$ decomposable? How do you show that every $2$-covector $\omega\in\Lambda^2((\mathbb{R}^3)^\ast)$ is decomposable i.e. that
$$\omega=u\wedge v$$
for some $u,v\in(\mathbb{R}^3)^\ast$?
In general we have
$$\omega=\omega_{12}e^1\wedge e^2+\omega_{13}e^1\wedge e^3+\omega_{23}e^2\wedge e^3,$$
so we can set
$$\omega_{12}e^1\wedge e^2+\omega_{13}e^1\wedge e^3+\omega_{23}e^2\wedge e^3=(a_1e^1+a_2e^2+a_3e^3)\wedge(b_1e^1+b_2e^2+b_3e^3),$$
and try to solve for $a_i,b_i$. But there doesn't seem to have a well-defined solution to these equations unless we separate it in several different cases ($\omega_{12} \neq 0$, etc). What's a better way of proving it?

A: Here is one way to do this without the case splitting you mention, but it uses the important Hodge star operator, which, given the question, you may or may not have available:
Pick an inner product $\langle \, , \, \rangle$ and orientation on $\mathbb{R}^3$ (the usual ones will do), which defines a volume form $\Omega \in \Lambda^3 (\mathbb{R}^3)^*$; this defines a Hodge star operator $$\ast: \Lambda^2 (\mathbb{R}^3)^* \to (\mathbb{R}^3)^*$$ characterized by
$$\alpha \wedge \ast \beta = \langle \alpha, \beta \rangle \Omega,$$
where $\langle \, , \, \rangle$ here denotes the induced inner product on $\Lambda^2 (\mathbb{R}^3)^*$.
Henceforth assume that $\omega \neq 0$ (if $\omega = 0$ it is clearly decomposable, as in that case $\omega = 0 \wedge 0$). Now, $\ast \omega$ is a $1$-form, and we can extend it to some orthogonal basis $(\ast \omega, \zeta, \eta)$ of $(\mathbb{R}^3)^*$. Then, $(\omega, \ast \zeta, \ast \eta)$ is an orthogonal basis of $\Lambda^2 (\mathbb{R}^3)^*$. Computing gives that
\begin{align}
    \langle \zeta \wedge \eta, \ast \zeta \rangle \Omega &= \zeta \wedge \eta \wedge \zeta = 0 \\
    \langle \zeta \wedge \eta, \ast \eta \rangle \Omega &= \zeta \wedge \eta \wedge \eta = 0 ,\\
\end{align}
so by orthogonality $\omega$ is a multiple of $\zeta \wedge \eta$, and in particular $\omega$ is decomposable.

A: Alternatively, the components of the wedge product with respect to a basis $(e_1, e_2, e_3)$ and the induced basis $(e_2 \wedge e_3, e_3 \wedge e_1, e_1 \wedge e_2)$ are given by the familiar cross product. More precisely,
$$\omega_{23}e^2\wedge e^3 + \omega_{31}e^3\wedge e^1 + \omega_{12}e^1\wedge e^2= (a_1e^1+a_2e^2+a_3e^3)\wedge(b_1e^1+b_2e^2+b_3e^3)$$
is equivalent to $$(\omega_{23}, \omega_{31}, \omega_{12}) = (a_1, a_2, a_3) \times (b_1, b_2, b_3).$$ So, the statement that every $2$-covector $\omega \in \Lambda^2 (\mathbb{R}^3)^*$ is decomposable is equivalent to the statement that every vector in $\mathbb{R}^3$ can be written as the cross product of two other vectors.
But this latter claim is easy to prove: Pick any two linearly independent vectors $X, Y$ orthogonal to $\ast \omega := (\omega_{23}, \omega_{31}, \omega_{12})$. Then, by construction $X \times Y$ is some multiple of $\ast \omega$, and by rescaling, say, $X$, we can ensure that $\ast \omega = X \times Y$. (In fact, the relationship between $\wedge$ and $\times$ can be written in terms of the Hodge star operator and the isomorphism $\mathbb{R}^3 \cong (\mathbb{R}^3)^*$ determined by the standard inner product.)

A: This can be done using clifford algebra.  Call a product of $k$ vectors under the clifford product a $k$-versor.  Versors are closed under multiplication: the product of two versors is another versor.  Note that a $k$-vector that is also a versor is necessarily simple.
Now, consider a bivector $B$ that might not be simple.  Multiply it by $\epsilon = e_1 e_2 e_3$, the unit pseudoscalar, which is also a versor (this is the operation of Hodge duality Travis mentions).  The result is necessarily some vector.  All vectors are simple, and all vectors are versors.  $B\epsilon$ is some vector.
Now, consider $(B \epsilon) \epsilon^{-1}$. The result is necessarily a bivector, but it also must be a versor since $B\epsilon$ is a vector.  But $B \epsilon \epsilon^{-1} = B$, and since the product operation is associative, this implies $B$ is a versor, and therefore a simple $2$-vector.