text:
Q: How to add closing parentheses when there are additional parentheses inside I am doing a "parser" which has to replace a keyword with another keyword
trim(<something>)  --> ltrim(rtrim(<something>))

I am using python regular expressions.
The main issue is since in the <something> part there can be additional parentheses which makes forming a regex very difficult to me. Simply adding a ? to make it non-greedy doesn't really work, and putting greedy the regex will match with the parentheses at the end of the file 200 lines down.
From the start I assume someone else had this issue, and I found these two questions.
How to correctly parse closing parentheses
How to add a missing closing parenthesis to a string in Python?
But neither help in my case,
my code so far:
def run(path):
for root, dirs, files in os.walk(path):
    for fname in files:
        fpath = os.path.join(root, fname)
        with open(fpath, 'r') as f:
            s = f.read()
        s = s.replace("trim","ltrim(rtrim" )
        text = s
        text = re.sub(r'(\(.+(?!\))\b)', r"\1)", text)
        return text

The code just adds closing ) without including the text in between even though I places a + in my regex which should mean at least one appearance of any char.
Like this
trim(p_name) becomes ltrim(rtrim()p_name)
I need it to be ltrim(rtrim(p_name))

A: You cannot match recursive patterns with built-in Python re, so you will have to pip install regex to install the PyPi regex module and use
return regex.sub(r'\btrim(\((?:[^()]++|(?1))*\))', r'ltrim(r\g<0>)', text) )

See the regex demo.
Details:

*

*\btrim - matches a whole word trim

*(\((?:[^()]++|(?1))*\)) - Group 1:

*

*\( - a ( char

*(?:[^()]++|(?1))* - zero or more chars other than ( and ) or the whole Group 1 pattern (recursed)

*\) - a ) char.

The replacement is ltrim(r\g<0>): ltrim(r + the whole match + ).
See the Python demo:
import regex
text = "trim(str(p_name))"
print( regex.sub(r'\btrim(\((?:[^()]++|(?1))*\))', r'ltrim(r\g<0>)', text) )
## => ltrim(rtrim(str(p_name)))


text:
Q: opening excel ooxml 2007 xlsx document returns nullPointer exception How do I open a 2007 xlsx ooxml file with Apache POI? I've added everything to my class path but keep getting this java.lang.NullPointerException error:
"C:\Program Files\Java\jdk1.7.0_13\bin\java" -agentlib:jdwp=transport=dt_socket,address=127.0.0.1:1804,suspend=y,server=n -Dfile.encoding=UTF-8 -classpath "C:\Program Files\Java\jdk1.7.0_13\jre\lib\charsets.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\deploy.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\javaws.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\jce.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\jfr.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\jfxrt.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\jsse.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\management-agent.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\plugin.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\resources.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\rt.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\access-bridge-64.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\dnsns.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\jaccess.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\localedata.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\sunec.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\sunjce_provider.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\sunmscapi.jar;C:\Program Files\Java\jdk1.7.0_13\jre\lib\ext\zipfs.jar;C:\Users\Patrick\Desktop\xmlChanger\out\production\xmlChanger;C:\poi-3.9\poi-3.9-20121203.jar;C:\poi-3.9\poi-examples-3.9-20121203.jar;C:\poi-3.9\poi-excelant-3.9-20121203.jar;C:\poi-3.9\poi-ooxml-3.9-20121203.jar;C:\poi-3.9\poi-ooxml-schemas-3.9-20121203.jar;C:\poi-3.9\poi-scratchpad-3.9-20121203.jar;C:\poi-3.9\lib\commons-codec-1.5.jar;C:\poi-3.9\lib\commons-logging-1.1.jar;C:\poi-3.9\lib\junit-3.8.1.jar;C:\poi-3.9\lib\log4j-1.2.13.jar;C:\poi-3.9\ooxml-lib\dom4j-1.6.1.jar;C:\poi-3.9\ooxml-lib\stax-api-1.0.1.jar;C:\poi-3.9\ooxml-lib\xmlbeans-2.3.0.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA 12.0.1\lib\idea_rt.jar" Main
Connected to the target VM, address: '127.0.0.1:1804', transport: 'socket'
java.lang.NullPointerException
    at org.apache.poi.openxml4j.opc.OPCPackage.getPart(OPCPackage.java:625)
    at org.apache.poi.POIXMLDocumentPart.<init>(POIXMLDocumentPart.java:91)
    at org.apache.poi.POIXMLDocument.<init>(POIXMLDocument.java:56)
    at org.apache.poi.xssf.usermodel.XSSFWorkbook.<init>(XSSFWorkbook.java:183)
    at org.apache.poi.ss.usermodel.WorkbookFactory.create(WorkbookFactory.java:73)
    at Main.main(Main.java:178)
Disconnected from the target VM, address: '127.0.0.1:1804', transport: 'socket'

Process finished with exit code 0

My code is as follows:
import org.apache.poi.ss.usermodel.Row;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.w3c.dom.Document;
import org.w3c.dom.NodeList;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import java.io.File;
import java.util.Iterator;

public class Main {
    public static void main(String[] args) {
        try {

            File file = new File(root_dir + "2013-03-13 iom diff.xlsx");
            Workbook workbook = WorkbookFactory.create(file); //fails here

            //...

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

Again I have searched already for this but haven't found any answers that worked (e.g. making sure the directory path is correct, going out of bounds etc.)
I asked a similar question before but the error was different because I believe I was using just the normal xlsx format and not the OOXML xlsx format when saving in Microsoft Excel.
Any ideas where this null pointer exception is coming from or a way of making the exception thrown more meaningful?
EDIT
When I use the following code to create a workbook, it opens with the code posted above:
        Workbook wb = new XSSFWorkbook();
        CreationHelper createHelper = wb.getCreationHelper();
        Sheet sheet = wb.createSheet("new sheet");

        Row r = sheet.createRow((short) 0);

        Cell cell = r.createCell(0);
        cell.setCellValue(1);

        r.createCell(1).setCellValue(1.2);
        r.createCell(2).setCellValue(createHelper.createRichTextString("This is a string"));
        r.createCell(3).setCellValue(true);

        // Write the output to a file
        FileOutputStream fileOut = new FileOutputStream("workbook.xlsx");
        wb.write(fileOut);
        fileOut.close();

This implies an invalid format but I'm not sure what the deal is because I saved as OOXML in Excel

redpajama_set_name: RedPajamaStackExchange


text:
Q: Oracle SQL Procedure. What is the error here? I wrote an PL/SQL procedure in Oracle APEX, and when I compile it, I get an error.
I do not understand what is the cause of the error. It looks to me that the sintaxis is correct.
Here is a screen capture:
https://i.imgur.com/UhfIMvh.png
This is the code:
create or replace PROCEDURE imageBLOBtoHTML(  v_MimeType IN VARCHAR2 (255) := null,
                                              v_Size IN NUMBER := null,
                                              v_file_name IN VARCHAR2 (2000) := null,
                                              imageBLOB IN NOCOPY BLOB  := null )
AS
BEGIN

       --Generates HTML
       OWA_UTIL.mime_header (NVL (v_MimeType , 'application/octet'), FALSE);
       htp.p('Content-length: ' || v_Size );
       htp.p('Content-Disposition:  filename="' || SUBSTR(v_file_name , INSTR(v_file_name , '/') + 1) || '"');
       owa_util.http_header_close;

       --Stops generation of HTML
       wpg_docload.download_file(imageBLOB);
END imageBLOBtoHTML;

This is the error:
Compilation failed,line 1 (13:39:25)
PLS-00103: Encountered the symbol "(" when expecting one of the following: := . ) , @ % default character

A: Error is at line:
  imageBLOB IN NOCOPY BLOB  :=  null

you need to change it :
imageBLOB     IN OUT NOCOPY BLOB := ''

I would say as :
CREATE OR REPLACE PROCEDURE imageBLOBtoHTML (
   v_MimeType    IN            VARCHAR2  := '',
   v_Size        IN            NUMBER := '',
   v_file_name   IN            VARCHAR2  := '',
   imageBLOB     IN OUT NOCOPY BLOB := '')

A: Joining my answer with the answer from XING it should be this one:
create or replace PROCEDURE imageBLOBtoHTML( v_MimeType IN VARCHAR2 := null,
                                             v_Size IN NUMBER,
                                             v_file_name IN VARCHAR2,
                                             imageBLOB IN OUT NOCOPY BLOB)

Permitting NULL for the other parameters (i.e. set NULL as default) does not make sense.


text:
Q: How many recievers per cycle in mail queue? Before pushing the send button, I would like to know, how many mailrecievers the queue handles per cycle? Does it send to everybody on the list at one time, or does it go more gently with, lets say, 50 per batch? And, is so, are there any ways to configure the number.
I'm a bit worried if the server has to handle thousands of mails in one go ...

A: It depends on Server else if you press a Send button then if you have 10k receivers then it will send all of them.
So if you have many receivers in queue then you have to be careful else server's email limitations will be over in just one press.


text:
Q: Troublshooting noisy smps I had a working design of a buck switching regulator based on a TPS62125. It worked fine, with minimal (<100mVpp) noise. I made some changes to my design, seemingly unrelated to the switcher. The result is audible noise from the switcher (a high pitch whine, that gets louder as draw increases), as well as this lovely waveform:

Here's my current layout:

The only changes I made to the switcher directly is adding room for a 250uF electrolytic cap (problem persists with and without it), adding a .2mF supercap elsewhere in the design, but off this power rail (problem also persists with and without), and adding a footprint for C33, but not populating. The amplitude of the noise does not seem to be affected by load.
Where do I go from here? How do I troubleshoot this? I thought I spotted a short between the two pins of the IC that lead to the two pads for the inductor. It doesn't look like there's an actual bridge while looking with a loupe, but could this be the source of the problem (pins are too close because of excess solder, creating some sort of stray capacitance)?
The only other thing I can think of is that it's possible that I installed a wrong capacitor for the input or output caps (did this by hand). Would that produce these results? Could it be a bad inductor?

A: Just maybes:
If any of these prove useful I'll come back and tidy up the answer. Otherwise no great value.
You've got a lovely pickup loop across R16 - why are FB R's across other side from both Vout and FB pin? |
C22 is in middle of that loop - noise filtered by C22 MAY be inductively coupled into loop.
Install C33 (small).
Temporarily move C22 physically and tack on in next best locn away from FB loop.
IP and OP caps could cause problems if well off values shown.
Data sheet does NOT say so but possible it is unstable if output cap ESR does not fall in a certain range. Varies with load. Check.
What sort on in & out caps? Ceramic?
C33 = transient response speedup. Diagm says DNP. Is it populated? Try it.
What happens with small C33?
What is load.
How does op waveform and amplitude change with load?


text:
Q: Calculating $\oint_{L} \frac{xdy - ydx}{x^2 + y^2}$ The problem is "Calculating $\oint_{L} \frac{xdy - ydx}{x^2 + y^2}$, where L is a smooth, simple closed, and postively oriented curve that does not pass through the orgin".
Here is my solution:
Let $$P(x,y) = \frac{-y}{x^2 + y^2}, Q(x,y) = \frac{x}{x^2 + y^2}$$
Get $$\frac{\partial{P}}{\partial{y}} = \frac{y^2 - x^2}{(x^2 + y^2)^2} = \frac{\partial{Q}}{\partial{x}}$$
Acorrding to the Green formula:
$$\oint_{L} \frac{xdy - ydx}{x^2 + y^2} = \iint (\frac{\partial{Q}}{\partial{x}} - \frac{\partial{P}}{\partial{y}})dxdy = 0$$
What's wrong with my solution?

A: That is valid as long as $L$ is a simple closed curve and the origin is not "inside" $L$, i.e., in the bounded region determined by $L$.  For example, this would work if $L$ is a unit circle centered at $(2,0)$, but not if it is the unit circle centered at the origin, and not if it is not a simple closed curve.
(As Timothy Wagner already pointed out before I finished writing, you need to check the hypotheses on the theorem you invoked to see when it works.)
If $L$ is closed, your integral should be $2\pi$ times the number of times $L$ winds around the origin.

A: Hint: What does the hypothesis of Green's theorem say about the requirements on functions $P$ and $Q$?

A: Just to add that I think that the value of the integral (i.e., 2Pi times the
  winding number) depends only on the homotopy-type of the curve, i.e., if a curve
  C is homotopic to the circle L that winds around the origin, then the integral over
  C will have the same value as the integral over L.

A: The answer should be $2\pi$ if the origin lies "inside" $L$, otherwise it should be 0.

A: One way of understanding why Green's theorem doesn't necessarily work in this context is to view Green's theorem as two separate equations added together: $\oint_{L} P dx = \int\int-{\partial P \over \partial y} dy dx$ and $\oint_{L} Q dy = \int\int{\partial Q \over \partial x} dx dy$.
Basically, Green's theorem holds because you can prove each of these equations by integrating by parts. In the first equation you integrate by parts in $y$ for a fixed $x$ and then integrate the result in $x$. In the second, you integrate by parts in $x$ for a fixed $y$ and then integrate the result in $y$. Since in your case both $-{\partial P \over \partial y}$ and  ${\partial Q \over \partial x}$ blow up at the origin, if the origin is contained in the interior of your curve these integrations by parts won't work... and you'll get the wrong answer.
(The curve is assumed to be simple and closed in the above.)

A: Notice that $\frac {xdt-ydx}{ x^2+y^2}$ is the total derivative of $arctan(x/y)$, so when you integrate about a closed curve, by the fundamental theorem of contour integrals, you get (after parametrizing) $$\int_{C} \frac {xdy-ydx}{x^2+y^2} = arctan(x/y) /_{(c,d)}^{(a,b)}$$ with $(a,b), (c,d)$ points on your curve. If $C$ is a circle, then these points will be of the form $(r, \sqrt {1-r^2)}$ or $(rcos\theta,rsin\theta)$ , so that, with the latter you get $$ tan^{-1}(sin \theta/ cos \theta)=tan^{-1}(tan\theta) =  \theta$$ so that the integral equals $$ \theta_1 - \theta_2 $$ though you have to take the periodicity of $tan \theta$ into account.


text:
Q: Is it reliable to set CSS variables in media queries? I'm building a responsive layout, referencing my variable in media queries, like this:
.item {
    --width: calc(50% - 10px);
    width: var(--width);
    padding-top: calc(var(--width) * 0.75);
}

@media(min-width: 920px) {
    .item {
        --width: calc(33.3333% - 10px);
    }
}

@media(min-width: 1280px) {
    .item {
        --width: calc(25% - 10px);
    }
}

It works in Google Chrome. Is there better way to do this assuming I want to stick to vanilla CSS? Are there any potential pitfalls with this solution?


text:
Q: FontAwesome 5 Icons won't Show on Generated PDF using mpdf package in laravel blade? I used composer to install mpdf
composer require carlos-meneses/laravel-mpdf
did all the settings in config/app.php file.
The webfonts TTF files copied to  resources/fonts/ folder.
Added this to your configuration file (/config/pdf.php):
<?php
return [
    'custom_font_dir' => base_path('resources/fonts/'), // don't forget the trailing slash!
    'custom_font_data' => [
        'examplefont' => [
            'R'  => 'fa-regular-400.ttf',    // regular font
            'B'  => 'fa-solid-900.ttf',       // optional: bold font
        ]
    ]
];
?>

used the font in view:
.fas {
    font-family: 'examplefont';
}

Versions:

*

*PHP: 7.4

*Laravel: 7

but icons not showing in generated pdf. how can I fix this issue?
Update
Resolved by How to use Font Awesome with MPDF?


text:
Q: Using thread for parallel processing in java I need few of the functions in my program to run simultaneously. These processes returns records. But, the output of one is the input to the other. In such a case, if at a point of time function A takes some time to output some record to the function B, I need to the function B to wait till function A provides some records as input for this process. Can I achieve this simply by using the thread functionalities such as wait, join, etc.. Or Is there any other ways to achieve the same functionality.
Edited:
As per the below mentioned suggestions, If I use the producer-consumer algorithm with BlockingQueue,ExecutorService, Future and CountDownLatch, Can I achieve every functionalities I requested?

A: In most cases you do not need to use wait etc. All you need to do is choose a good safe structure to use to communicate between your threads,
In this specific case I would suggest one of the concurrent queuue implementations, perhaps a BlockingQueue such as ArrayBlockingQueue.

A: As mentioned above you can use blocking queue with producer consumer
OR
You can use countdown latch of the java concurrency to solve your problem.
How CountDownLatch works?
CountDownLatch.java class defines one constructor inside:
//Constructs a CountDownLatch initialized with the given count.
public void CountDownLatch(int count) {...}

This count is essentially the number of threads, for which latch should wait. This value can be set only once, and CountDownLatch provides no other mechanism to reset this count.
The first interaction with CountDownLatch is with main thread which is goind to wait for other threads. This main thread must call, CountDownLatch.await() method immediately after starting other threads. The execution will stop on await() method till the time, other threads complete their execution.
Other N threads must have reference of latch object, because they will need to notify the CountDownLatch object that they have completed their task. This notification is done by method : CountDownLatch.countDown(); Each invocation of method decreases the initial count set in constructor, by 1. So, when all N threads have call this method, count reaches to zero, and main thread is allowed to resume its execution past await() method.
Below is a simple example. After the Decrementer has called countDown() 3 times on the
CountDownLatch, the waiting Waiter is released from the await() call.
CountDownLatch latch = new CountDownLatch(3);

Waiter      waiter      = new Waiter(latch);
Decrementer decrementer = new Decrementer(latch);

new Thread(waiter)     .start();
new Thread(decrementer).start();

Thread.sleep(4000);

public class Waiter implements Runnable{

    CountDownLatch latch = null;

    public Waiter(CountDownLatch latch) {
        this.latch = latch;
    }

    public void run() {
        try {
            latch.await();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

        System.out.println("Waiter Released");
    }
}

public class Decrementer implements Runnable {

    CountDownLatch latch = null;

    public Decrementer(CountDownLatch latch) {
        this.latch = latch;
    }

    public void run() {

        try {
            Thread.sleep(1000);
            this.latch.countDown();

            Thread.sleep(1000);
            this.latch.countDown();

            Thread.sleep(1000);
            this.latch.countDown();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

In your case you can use callable to create thread instead of runnable as you need to get the retrun value from one thread and have to pass that value to second thread.

A: Java's Fork and Join looks suitable for the usecase specified in your Question.
See http://docs.oracle.com/javase/tutorial/essential/concurrency/forkjoin.html

A: Have a look at BlockingQueue classes and producer/consumer patterns.
The first thread is getting the work unit from an input blocking queue and putting its output to an output blocking queue (with size restrictions).
The second thread is doing the using this output queue as an input.
With this method you can also easialy adjust the number of threads.
Ensure the the work load per work unit is not to small.

A: This is similar to producer-consumer problem. You can use Java's BlockingQueue.
The process A will enqueue its results and the process B will wait until A's output is ready in the queue. When output of A is available, then B can read and consume it.

A: This looks like the consumer-producer-problem. As suggested by others you can use a BlockingQueue. Here is an example for how to use it:
public static void main(final String[] args) {
    final ExecutorService producer = Executors.newSingleThreadExecutor();
    final ExecutorService consumer = Executors.newSingleThreadExecutor();
    final BlockingQueue<Integer> workpieces = new LinkedBlockingQueue<>();

    producer.submit(new Runnable() {

        @Override
        public void run() {
            final Random rand = new Random();

            for (;;) {
                try {
                    workpieces.put(rand.nextInt());
                    Thread.sleep(1000);
                } catch (final InterruptedException e) {
                    Thread.currentThread().interrupt();
                    return;
                }
            }
        }

    });

    consumer.submit(new Runnable() {

        @Override
        public void run() {
            for (;;) {
                try {
                    System.out.println("Got " + workpieces.take());
                } catch (final InterruptedException e) {
                    Thread.currentThread().interrupt();
                    return;
                }
            }
        }

    });
}

It generates a random number every second in the producer-thread which is printed by the consumer-thread.

A: You can use BlockingQueue between producer and consumer threads. The producer will keep on adding results to queue if it is not full, concurrently the consumer thread can process pending messages from queue.


text:
Q: Open windows to preset size and position I was wondering if there is a way to create a script or automator task that will open windows with a preset size and position.  I'd like to do this with apps, as well as with finder windows.
For example, I want to open Sublime and have it take up the top half of my screen, and open Chrome taking up the bottom half of my screen.
Another example is I'd like to open up four finder windows, each taking up a quarter of the screen.

A: I would recommend using Script Editor to write some AppleScripts that will cater to your different layout requirements for different applications.
I'll demonstrate how this can be done using your first example featuring Sublime and Google Chrome, which are to occupy the top half and the bottom half of the screen, respectively.
This script assumes the applications are already running with a visible window available in each application to manipulate.  It's actually a very short script, but looks long because of the comment lines (they start with --) that I inserted at each stage to guide you through what each part of the script does:
    tell application "System Events"
        set Chrome to the front window of application process "Google Chrome"
        set Sublime to the front window of application process "Sublime Text"

        -- Get the size of the screen's display in pixels
        get the size of scroll area 1 of application process "Finder"
        set Display to {width:item 1, height:item 2} of the result

        -- First attempt to make Sublime take up the full width and
        -- height of the display.
        set position of Sublime to [0, 0]
        set size of Sublime to [the Display's width, the Display's height]

        -- However, the presence of a visible menu bar and dock
        -- will create natural barriers that the window won't cross.

        -- Retrieve the actual size and position that Sublime's
        -- window ended up adopting.
        set [_w, _h] to the size of Sublime
        set [_x, _y] to the position of Sublime

        -- Half Sublime's window's height.  It should now be
        -- correctly positioned and sized.
        set the size of Sublime to [_w, _h / 2 - 1]

        -- Position Chrome first so that its horizontally aligned
        -- with Sublime, and the top edge of Chrome's window's meets
        -- the bottom edge of Sublime's.
        set position of Chrome to [_x, _y + _h / 2]
        -- Then size Chrome's window identically to that of Sublime.
        set size of Chrome to [_w, _h / 2 - 1]
    end tell

    -- Lastly, bring both applications to the foreground
    activate application "Sublime Text"
    activate application "Google Chrome"

Bear in mind this is just a quick example of how you might approach this task given an optimal starting point (both apps open with one active window each).  However, you'll likely want to incorporate ways of dealing with less optimal situations, such as how you'd want your script to behave if you accidentally triggered it before opening Chrome; or if you wished to arrange four Finder windows into separate corners of the screen, but there were five open at the time.

Alternatively, you could spend about $1 and get an app from the App Store that will size and position windows in just about any arrangement you could wish for.  Here's one:

*

*Magnet

A: At least on Sublime I addressed this issue by following these three simple steps

*

*Put this on the Preferences.sublime-preferences
"remember_full_screen": true

*Open the sublime

*Resize MANUALLY the sublime window to the size you want (maximum height and width)
☝
After I followed this steps, now everytime I open the sublime (even with subl), the sublime opens on the last window that I MANUALLY resized it.


text:
Q: Motivating Zariski topology I always find it difficult to motivate Zariski topology on $\text{Spec}(k[X_1,...,X_n])$, both the underlying set and the topology. As far as I understand, Zariski topology isn't really that essential for proving many classical theorems like Bezout's (for example Fischer doesn't mention Zariski topology once in his Plane Algebraic Curves); applications of Zariski topology where it does play an essential role are probably too advanced for me (although counterexamples are much appreciated).
Then I wonder if I can at least motivate Zariski topology intrinsically. I can somehow agree with the naturalness of Zariski topology on $k^n$: points should be closed and polynomials should be continuous; this is a bit like weak topology in functional analysis. But why do we want to consider prime ideals, i.e., to put points and irreducible varieties on the same footing? A usual answer is that preimage of maximal ideal is in general not maximal, but it is maximal in the case of finitely generated $k$-algebras, which seems good enough (and why is it so important to take preimage?). Also, why should we think of the zero ideal as the "generic point"? For me it's hard to relate that to those classical generic point arguments.
But now I think I finally found a way to motivate Zariski topology. Please help me check if the math is correct.

*

*Let $K\supseteq k$ be a larger algrabraically closed field of infinite transcendence degree, e.g., if $k=Q^{\text{alg}}$ then we may take $K=\mathbb{C}$. For each $a=(a_1,...,a_n)\in K^n$, define $\pi(a)=\{f\in k[X_1,...,X_n]: f(a)=0\}$. This is a prime ideal.

*We claim that $\pi:K^n\rightarrow\text{Spec}(k[X_1,...,X_n])$ is surjective. For any prime ideal $\mathfrak{p}$, the image of $X_1,...,X_n$ in $k[X_1,...,X_n]/\mathfrak{p}$ is a tuple that satisfies exactly those polynomials in $\mathfrak{p}$. The algebraic closure of $k[X_1,...,X_n]/\mathfrak{p}$ has transcendence degree at most $n$ over $k$, and hence embeds into $K$.

*We claim that with both $K^n$ and $\text{Spec}(k[X_1,...,X_n])$ endowed with Zariski topology, $\pi$ is a closed map, hence a quotient map. If $f(a)=0$ then $\pi(a)\ni f$; conversely if $\mathfrak{p}\ni f$, choose any $a$ that maps to $\mathfrak{p}$, and we must have $f(a)=0$. This shows the image of a basic closed set in $K^n$ is a basic closed set in $\text{Spec}(k[X_1,...,X_n])$; the general case is similar.
So the Zariski topology on $\text{Spec}(k[X_1,...,X_n])$ is just the quotient of the (in my opinion) more intuitive topology on $K^n$. As for generic point, if $\pi(a)=\mathfrak{p}$ then the tuple $a$ satisfies those polynomials in $\mathfrak{p}$ and nothing else, as with "most" $K$-points on the variety determined by $\mathfrak{p}$; in particular $\pi(a)=(0)$ iff $a=(a_1,...,a_n)$ are algebraically independent. This makes more sense to me than "$(0)$ is a point that lies everywhere". As for the reason of going to a larger field $K$: truly generic point doesn't exist if we only look at $k$. All algebraically closed fields (of a fixed characteristic) are more or less the same, so the structure of varieties don't really change when we move to a larger field.
Is this a useful way to picture Zariski topology? Perhaps it's too early for me, but is this related to the the functor of points?


text:
Q: Splitting strings with multiple lines in android I have the following string:
"ISL-1027
20:13:02:22:00:76"
i.e. bluetooth name and MAC address
I need MAC address on a separate string.
What is the best way to use split() in this case?
Thanks

A: split("\n") you can use this."\n" will be the separator here.
   String str = "ISL-1027" +
            "\n" +
            "20:13:02:22:00:76";
    String[] arr= str.split("\n");
    System.out.println("Bluetooth  Name: "+arr[0]);
    System.out.println("MAC address: "+arr[1]);

Out put:
Bluetooth  Name: ISL-1027
MAC address: 20:13:02:22:00:76

If your input String like this ISL-1027 20:13:02:22:00:76(separate by a space) use follows
    String str = "ISL-1027 20:13:02:22:00:76";

    String[] arr= str.split(" ");
    System.out.println("Bluetooth  Name: "+arr[0]);
    System.out.println("MAC address: "+arr[1]);

A: Split matching on any white space and include the DOTALL mode switch:
split("(?s)\\s+");
The DOTALL will make the regex work despite the presence of newlines.

A: Depending on that how your string is formated is not sure, but the format of a mac-address is defined. I would not try to split the string and hope that index n is the correct value.
Instead I would use regulare expression to find the correct position of a string that matches the mac-address format.
Here is a litle example (not tested):
String input = "ISL-1027

20:13:02:22:00:76"

Pattern macAddrPattern = Pattern.compile("[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\:[0-9a-fA-F]{2}\");

String macAdr = parseMacAddr(input);

public String parseMacAddr(String value) {
  Matcher m = macAddrPattern.matcher(value);

  if (m.matches()) {
    return value.substring(m.start(),m.end());
  }

  return null;
}

This should always work.


text:
Q: SpriteKit - How to fix distortion in Node's animation? I have created an animation of various PNGs, but there are various frames that stretch to the border so the node is 'filled'. The animation should look like the GIF that I have created using the same pictures. Does anybody know how to make the animation look like the GIF?
GIF:
    Gif: Animation should look like this
Actual: Extra slow
    Actual result of the code
Border:
Here you can see the border of the physics body that has the same size of the "node's border"
I have tried to fix the problem by switching the scene.scalemode. Further, I have tried to make the size of the Node dependent on the size of the textures. Neither looked like the GIF.
class GameScene: SKScene {

var player = SKSpriteNode()
var frames : Array = [SKTexture]()

override func didMove(to view: SKView) {

    //Color: Placeholder; Size should be size of original frames
    player = SKSpriteNode(color: .red, size: CGSize(width: 500,     height: 1000))

    //Physics
    player.physicsBody = SKPhysicsBody(rectangleOf: player.size)
    player.physicsBody?.affectedByGravity = false

    //Init the frames to the array
    for i in 1...6 {
        frames.append(SKTexture(imageNamed: "playerRunLeft-\(i)"))
    }
//        Tried to make the player size dependent on the image size - didn't work out
//        for i in frames {
//            player.size = i.size()
//        }

    //Attach the action
    let runAction = SKAction.animate(with: frames, timePerFrame: 0.3)
    player.run(SKAction.repeatForever(runAction))

    //Add to scene
    addChild(player)
    }
}


text:
Q: Right quotient of $L_1=L(a^*baa^*)$, and $L_2=L(ab^*)$. Given $L_1=L(a^*baa^*)$, $L_2=L(ab^*)$. The regular expression corresponding to language $L_3=L_1/L_2$ (right quotient) is given by

*

*$a^*b$

*$a^*baa^*$

*$a^*ba^*$

*None of the above

My attempt:
The right quotient (or simply quotient) of a formal language ${\displaystyle L_{1}} $ with a formal language ${\displaystyle L_{2}}$ is the language consisting of strings $w$ such that $wx$ is in ${\displaystyle L_{1}}$ for some string $x$ in ${\displaystyle L_{2}} $.
Given,
$L_1=(a^*baa^*)=\{ba, baa, aba, abaa,\dots\}$
$L_2=(ab^*)=\{a, ab, abb, abbb,\dots\}$
Therefore,
$L_3=L_1/L_2=\{b, ba, ab, aba,\dots\}=(a^*ba^*)$
I have used only string $'a'$ of language $L_2$
Option $(3)$ is true.

But, some where it explained as
$L_1 =\{ba,aba,abaa,baa,\dots\}$
$L_2=\{ab^*\}$
$L_1 / L_2$ operation not successful here
So, Ans $(4)$.

Can you explain it, please?

A: Suppose that $w\in\{a,b\}^*$, and there is some $x\in L_2$ such that $wx\in L_1$. This $x$ must be $ab^n$ for some $n\ge 0$, so $wab^n\in L_1$. No word in $L_1$ ends in $b$, so $n=0$, and $wa\in L_1$. This is the case if and only if $w$ has the form $a^*ba^*$, so you are correct.
It makes no sense to say that the operation of taking the right quotient is not successful: the right quotient always exists, though it may be empty. Perhaps the person who wrote that answer was under the mistaken impression that $w\in L_1/L_2$ if and only if $wx\in L_1$ for every $x\in L_2$, instead of for at least one $x\in L_2$.


text:
Q: Which type i should provide to pass props to component I have component where i map each item from store array
{this.state.figures
   .sort(( a, b ) => a > b ? 1 : -1 )
   .reverse()
   .map((item: ***ItemProps***) => {
       return (
          <Item key={Math.random()} data={item}/>
       );
})}

And my component
type ItemProps = {
    data: {
        name: string;
        sprites: {
            front_default: string;
        }
    }
}

const Item = (props: ItemProps): JSX.Element => {
    const { isOpen, onOpen, onClose } = useDisclosure()

    return (
        {/* ... */}
    )
}

export default Item

The problem in type item in MAP, which type should i use?


text:
Q: getting null data on first load in react redux toolkit Hello all I need help I am getting null data in redux toolkit on first load in console below is my full code
---profileSlice---

export const profileSlice = createSlice({
    name: "profile",
    initialState : { value: null },
    reducers: {
        profileAction : (state, action) => {
           state.value = action.payload
        }
    },
});

export const { profileAction} = profileSlice.actions;

export default profileSlice.reducer;

---Action---
export const fetchProfile = (token,path) => async (dispatch) => {

         await axios.get(Constants.url + path,
            {
                headers : {
                    'Content-type': 'application/json',
                    'Accept': "application/json",
                    'Authorization' : `Bearer ${token}`
                }
            }
        )
        .then(res => {
            dispatch({
              type:'profile/profileAction',
              payload:res.data
            });
        })
        .catch((err) => {
            toast.error(err.response.data.message);
        })
}

---profile component---
import {fetchProfile} from '../Redux/actions';

const [basicInformation, setbasicInformation] = useState({
    name: '',
    email: ''
})
const response = useSelector((state) => state.profile.value);
const dispatch = useDispatch();
useEffect(() => {
    dispatch(fetchProfile('token','path'))
    setbasicInformation({
        name:response.name,
        email:response.email,
    })
    console.log(response);
  }, [])
console.log(basicInformation);

I am getting null value on both response and basicInformation State on (first load or after login)  after I refresh the page I got that data can anyone help me out.

A: That is normal - your useEffect only runs after the component has rendered and already encountered the null. You will have to check if the value from state is null and render some kind of loading indicator.


text:
Q: Jump to current cursor position in Xcode How do I jump to the current cursor position in Xcode?
For example, I am coding at line 748. I scroll up to line 35 to look at a part of my code. The cursor is still at line 748. Is there a keyboard shortcut to jump back down to where the cursor is?

A: Hit the spacebar.
Delete the space if you want.


text:
Q: Ambiguous method overloading for method com.android.build.gradle.internal.core.MergedFlavor#setSigningConfig after updating to gradle 7 I've just updated gradle from 6 to 7 and AGP from 4 to 7. There is part of my gradle setup that stopped compiling.
applicationVariants.all { variant ->
        if (variant.getName().contains("prodSe")) {
            variant.mergedFlavor.signingConfig = signingConfigs.prodSeSigningConfig
        }
}

This now causes:

Cannot resolve which method to invoke for [class
com.android.build.gradle.internal.dsl.SigningConfig_Decorated] due to
overlapping prototypes between:   [interface
com.android.builder.model.SigningConfig]  [interface
com.android.build.api.dsl.ApkSigningConfig]

Feels like variant.mergedFlavor now returns a type inheriting from both SigningConfig & ApkSigningConfig that have same methods. Not sure how to fix this.

A: I had the same problem and I ended up setting signingConfigs inside a variantFilter block https://developer.android.com/studio/build/build-variants#filter-variants
So in your case, it will be something like this:
variantFilter { variant ->
    if (variant.getName().contains("prodSe")) {
        android.defaultConfig.signingConfig signingConfigs.prodSeSigningConfig
    }
}

A: @ppodgorski answer is correct but today we can use a better solution using the androidComponents block. I'm using Gradle 7.4 and AGP 7.3.1 and the following is the code that lets you choose the right signingConfig based on your variant. Keep in mind that my android app is multi-flavour with 2 dimensions.
signingConfigs {
    play_store {
        storeFile file(properties.getProperty('play_store_storeFile'))
        keyAlias properties.getProperty('play_store_keyAlias')
        storePassword properties.getProperty('play_store_storePassword')
        keyPassword properties.getProperty('play_store_keyPassword')
        v1SigningEnabled true
        v2SigningEnabled true
    }
    smart {
        storeFile file(properties.getProperty('smart_storeFile'))
        keyAlias properties.getProperty('smart_keyAlias')
        storePassword properties.getProperty('smart_storePassword')
        keyPassword properties.getProperty('smart_keyPassword')
        v1SigningEnabled true
        v2SigningEnabled true
    }
    huawei_store {
        storeFile file(properties.getProperty('huawei_store_storeFile'))
        keyAlias properties.getProperty('huawei_store_keyAlias')
        storePassword properties.getProperty('huawei_store_storePassword')
        keyPassword properties.getProperty('huawei_store_keyPassword')
        v1SigningEnabled true
        v2SigningEnabled true
    }
}

flavorDimensions "brand", "services"

productFlavors {
// different flavours definition
}

androidComponents {
    onVariants(selector().all(), { variant ->
        if (variant.name == "xxyyzzGmsRelease") {
            variant.signingConfig?.setConfig(signingConfigs.play_store)
        } else if (variant.name == "xxyyzzHmsRelease") {
            variant.signingConfig?.setConfig(signingConfigs. huawei_store)
        } else if (variant.name.contains("aabbccGmsRelease")) {
            variant.signingConfig?.setConfig(signingConfigs.smart)
        }
    })
}


text:
Q: NetSuite Suitelet Custom HTML | Pressing submit on the form causes the value to be null I am creating a suitelet using custom HTML. The page displays fine, but on submit, I am not able to get the parameter values.
    html = html + "
";
    html = html + "<select onchange='onItemSelect(event)' class='item_select'   name='item_1'>";
    html = html + "</select>";
    html = html + "<input name='quantity' placeholder='Quantity' type='number' />";
    html = html + "<input  name='svuuom' disabled placeholder='SVU UOM' type='text' />";
    html = html + "<input  name='qtysvuuom' disabled placeholder='Qty in SVU UOM' type='text' />";
    html = html + "<input  name='lot_num' placeholder='Lot Number' type='text' />";
    html = html + "<input  name='exp_date' placeholder='Expiration Date' type='date' />";
    html = html + "<input  onChange='calcQtyRemain(event)' name='ac_weight' placeholder='Actual Weight' type='text' />";
    html = html + "<input  name='averageweight' disabled placeholder='Average Weight' type='number' />";
    html = html + "<input  name='totalqty' disabled placeholder='Total Quantity' type='text' />";
    html = html + "<input  name='qtyremaining' disabled placeholder='Quantity Remaining' type='text' />";
    html = html + "<button  class='row_1 remove nav_button' onClick='removeRow(this)'>Remove</button>";
    html = html + "<input type='hidden' name='submit_data' id='submit_data'  ></input>";
    html = html + "
";
    html = html + "<button  class='nav_button' type='submit' >Submit</button>";
    html = html + "<button id='finalize' class='nav_button' onClick='finalizeForm(event)'> Finalize</button>";
    html = html + "<button class='nav_button' onClick='addRow()' class='add_row'>Add Row</button>";
    html = html + "";
    html = html + "</form>";

The value is being set to the hidden field 'submit_data' when the user clicks finalize. I want to grab this as a parameter on post. If I set the value='Test' on the submit_data field, I get the parameter just fine on post. The above code is on the get request.
I am also linking JS files and doing some client side functions within that. These functions set the value on submit_data field.

A: The issue was within the JS resource. Something was conflicting with the post action and caused the field to be null. I have resolved the issue and I am now grabbing the value perfectly.


text:
Q: Is there any way to set up a different Pytest configuration for different folders / subfolders in the Pycharm project in my PyCharm project I have some pytest files, that I have to run with "environment variables", and other files can't run with this option.
At this point, every time I want to run a test file, I have to edit environment variables for it, which is a pain.
Is it possible to set a certain configuration for the files in some location (also in folders that contain them), and another for other folders?


text:
Q: Map plotting with Basemap Ubuntu 18.04 I am trying to plot on a globe with basemap.  However, I get the following error listed below.  How can I get basemap to work?
Traceback (most recent call last):
  File "plotgm.py", line 3, in <module>
    from mpltoolkits.basemap import Basemap
ModuleNotFoundError: No module named 'mpltoolkits'

sudo apt install python3-mpltoolkits.basemap
Reading package lists... Done
Building dependency tree
Reading state information... Done
python3-mpltoolkits.basemap is already the newest version (1.1.0+dfsg-1).
0 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.

A: You have mpltoolkits.basemap installed for Python 3.
Are you using Python 2 to run your program?
Make sure you type
python3 <filename>


text:
Q: leaflet.heat not working for Angular 12-14 I am having issues getting leaflet.heat to work in Angular 12-14. Leaflet basic map displays, however, the heatmap will not display over the map.
I am following the thread from:
Link
which provides a working version, however, it is using Angular 7 in the demo:
Link
I have attempted to recreate the demo on my own machine, Angular 14, and using Angular 12 in Code Sandbox
My heatmap failing to display Code Sandbox demo: Link
There were some errors being triggered in the Angular 7 Code Sandbox working demo version related to const heat. I was able to fix them with (L as any) and also adding the parameter { radius: 25 } to heatLayer, but I am at a loss of what else to do to get the heatmap to work at this point.
Is leaflet.heat just incompatible with newer versions of Angular? if so, is there a Leaflet heatmap libary that anyone could recommend?
Thank you

A: Just import import 'leaflet/dist/leaflet.css' and the codesandbox works as expected

I am sure that it will work if you upgrade also in angular 14.x


text:
Q: Best practices with historical data in MySQL database Recently I think about the best practices with storing historical data in MySQL database. For now, each versionable table has two columns - valid_from and valid_to, both DATETIME type. Records with current data has valid_from filled with its creation day. When I update this row, I fill valid_to with update date and add new record with valid_from the same as valid_to in previous row - easy stuff. But I know that table will be enormous very quick so fetching data can be very slow.
I'd like to know if you have any practices with storing historical data?

A: It's a common mistake to worry about "large" tables and performance. If you can use indexes to access your data, it doesn't really matter if you have 1000 of 1000000 records - at least not so as you'd be able to measure. The design you mention is commonly used; it's a great design where time is a key part of the business logic.
For instance, if you want to know what the price of an item was at the point when the client placed the order, being able to search product records where valid_from < order_date and valid_until is either null or > order_date is by far the easiest solution.
This isn't always the case - if you're keeping the data around just for archive purposes, it may make more sense to create archive tables. However, you have to be sure that time is really not part of the business logic, otherwise the pain of searching multiple tables will be significant - imagine having to search either the product table OR the product_archive table every time you want to find out about the price of a product at the point the order was placed.

A: This is not complete answer, just few suggestions.
You can add indexed boolean field like is_valid. This should improve performance with big table with historical and current records.
In general - storing historical data in seprate table may complicate your application (just imagine complexity of query that is supposed to get data with mixed current and historical records...).
Today computers are really fast. I think you should compare/test performance with single table and separate table for historical records.
In addition - try to test your hardware to see how fast is MySQL with big tables to determine how to design database. If its too slow for you - you can tune MySQL configuration (start with increasing cache/RAM).

A: I'm nearing completion of an application which does exactly this. Most of my indexes index by key fields first and then the valid_to field which is set to NULL for current records thereby allowing current records to be found easily and instantly. Since most of my application deals with real time operations, the indexes provide fast performance. Once in a while someone needs to see historical records, and in that instance there's a performance hit, but from testing it's not too bad since most records don't have very many changes over their lifetime.
In cases where you may have a lot more expired records of various keys than current records it may pay to index over valid_to before any key fields.


text:
Q: PassportJS and local strategy I get an issue using PassportJS and my local strategy. I'm using ExpressJS 4.
My app.js (reduced, without express init) :
var express                        = require('express'),
    ejs                            = require('ejs'),
    path                           = require('path'),
    expressLayouts                 = require('express-ejs-layouts'),
    session                        = require('express-session'),
    compression                    = require('compression'),

    _                              = require('lodash'),
    fs                             = require('fs-extra'),
    colors                         = require('colors'),
    passport                       = require('passport'),
    flash                          = require('connect-flash'),

    localStrategyMiddleware        = require('./middlewares/localStrategy'),
    logMiddleware                  = require('./middlewares/log'),
    localsMiddleware               = require('./middlewares/locals'),
    securityMiddleware             = require('./middlewares/security');

this.app.use(session({
  secret : 'd4qs45sdq6',
  // name : 'sessionId',
  // proxy: true,
  resave: true,
  saveUninitialized: true
}));

this.app.use(flash());
this.app.use(function(request, response, next) {
  response.locals.flash = {
    info: request.flash('info'),
    success: request.flash('success'),
    warning: request.flash('warning'),
    danger: request.flash('danger')
  };
  next();
});

this.app.use(passport.initialize());
this.app.use(passport.session());

this.app.post('/test', passport.authenticate('local', {
      successRedirect: '/user/success',
      failureRedirect: '/user/failure',
      failureFlash: true,
      successFlash: true
    }), function(request, response) {
  console.log('test');
});

My strategy (./middlewares/localStrategy) :
var passport        = require('passport'),
    LocalStrategy   = require('passport-local').Strategy,
    sequelize       = require('../databases/Database').connexion,
    UserModel       = require('../app/models/UserModel')(sequelize);

passport.use(new LocalStrategy(
  function(username, password, done) {

    console.log('test');

    UserModel.findOne({ username: username }, function (err, user) {
      if (err) { return done(err); }

      if (!user) {
        return done(null, false, { message: 'Incorrect username.' });
      }

      if (!user.validPassword(password)) {
        return done(null, false, { message: 'Incorrect password.' });
      }

      return done(null, user);
    });
  }
));

passport.serializeUser(function(user, done) {
  console.log(user);
  done(null, user.id);
});

passport.deserializeUser(function(id, done) {
  console.log(id);
  UserModel.findById(id, function(err, user) {
    done(err, user);
  });
});

module.exports = passport;

Issue : I get no logs and I'm every time redirected to user/failure.
Edit 1 :
<form action="/test" method="post">
  <input type="hidden" name="_csrf" value="<%=csrfToken%>">
  <input type="text" name="user[username]" placeholder="username">
  <input type="text" name="user[password]" placeholder="password">
  <input type="submit">
  <input type="reset">
</form>

A: If you are getting no logs then that tells you that your app.js file doesn't have access to the code in  ./middlewares/localStrategy
Try changing
localStrategyMiddleware = require('./middlewares/localStrategy')
to simply
require('./middlewares/localStrategy')

Also you need to change your name attributes on your form to match with those that passport uses, I think the default are username and password, so unless you want to specify alternatives in your localStrategy you should use the following.
  <input type="text" name="username" placeholder="username">
  <input type="text" name="password" placeholder="password">


text:
Q: Drop by multiple columns groups if specific values not exit in another column in Pandas How can I drop the whole group by city and district if date's value of 2018/11/1 not exits in the following dataframe:
  city district       date  value
0    a        c   2018/9/1     12
1    a        c  2018/10/1      4
2    a        c  2018/11/1      5
3    b        d   2018/9/1      3
4    b        d  2018/10/1      7

The expected result will like this:
  city district       date  value
0    a        c   2018/9/1     12
1    a        c  2018/10/1      4
2    a        c  2018/11/1      5

Thank you!

A: Create helper column by DataFrame.assign, compare by datetime and test if at least one true per groups with GroupBy.any and GroupBy.transform for possible filter by boolean indexing:
mask = (df.assign(new=df['date'].eq('2018/11/1'))
          .groupby(['city','district'])['new'].transform('any'))
df = df[mask]
print (df)
  city district       date  value
0    a        c   2018/9/1     12
1    a        c  2018/10/1      4
2    a        c  2018/11/1      5

If error with misisng values in mask one possivle idea is replace misisng values in columns used for groups:
mask = (df.assign(new=df['date'].eq('2018/11/1'),
                  city= df['city'].fillna(-1),
                  district= df['district'].fillna(-1))
          .groupby(['city','district'])['new'].transform('any'))
df = df[mask]
print (df)
  city district       date  value
0    a        c   2018/9/1     12
1    a        c  2018/10/1      4
2    a        c  2018/11/1      5

Another idea is add possible misisng index values by reindex and also replace missing values to False:
mask = (df.assign(new=df['date'].eq('2018/11/1'))
          .groupby(['city','district'])['new'].transform('any'))
df = df[mask.reindex(df.index, fill_value=False).fillna(False)]
print (df)
  city district       date  value
0    a        c   2018/9/1     12
1    a        c  2018/10/1      4
2    a        c  2018/11/1      5

A: There's a special GroupBy.filter() method for this. Assuming date is already datetime:
filter_date = pd.Timestamp('2018-11-01').date()
df = df.groupby(['city', 'district']).filter(lambda x: (x['date'].dt.date == filter_date).any())


text:
Q: Database connection timeout I have read so many articles on the Internet about this problem but none seem to have a clear solution. Please could someone give me a definite answer as to why I am getting database timeouts. The app is a GWT app that is being hosted on a Tomcat 5.5 server. I use spring and the session factory is created in the applicationContext.xml as follows
<bean id="sessionFactory"
      class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
    <property name="hibernateProperties">
        <props>
            <prop key="hibernate.dialect">${connection.dialect}</prop>
            <prop key="hibernate.connection.username">${connection.username}</prop>
            <prop key="hibernate.connection.password">${connection.password}</prop>
            <prop key="hibernate.connection.url">${connection.url}</prop>
            <prop key="hibernate.connection.driver_class">${connection.driver.class}</prop>
            <prop key="hibernate.show_sql">${show.sql}</prop>
            <prop key="hibernate.hbm2ddl.auto">update</prop>
            <prop key="hibernate.c3p0.min_size">5</prop>
            <prop key="hibernate.c3p0.max_size">20</prop>
            <prop key="hibernate.c3p0.timeout">1800</prop>
            <prop key="hibernate.c3p0.max_statements">50</prop>
            <prop key="hibernate.c3p0.idle_test_period">300</prop>
        </props>
    </property>
    <property name="annotatedClasses">
        <list>
            <value>za.co.xxxx.traintrack.server.model.Answer</value>
            <value>za.co.xxxx.traintrack.server.model.Company</value>
            <value>za.co.xxxx.traintrack.server.model.CompanyRegion</value>
            <value>za.co.xxxx.traintrack.server.model.Merchant</value>
            <value>za.co.xxxx.traintrack.server.model.Module</value>
            <value>za.co.xxxx.traintrack.server.model.Question</value>
            <value>za.co.xxxx.traintrack.server.model.User</value>
            <value>za.co.xxxx.traintrack.server.model.CompletedModule</value>
        </list>
    </property>
</bean>

<bean id="dao" class="za.co.xxxx.traintrack.server.DAO">
    <property name="sessionFactory" ref="sessionFactory"/>
    <property name="adminUsername" value="${admin.user.name}"/>
    <property name="adminPassword" value="${admin.user.password}"/>
    <property name="godUsername" value="${god.user.name}"/>
    <property name="godPassword" value="${god.user.password}"/>
</bean>

All works fine untile the next day:
INFO   | jvm 1    | 2010/06/15 14:42:27 | 2010-06-15 18:42:27,804 WARN
[JDBCExceptionReporter] : SQL Error: 0, SQLState: 08S01
INFO   | jvm 1    | 2010/06/15 14:42:27 | 2010-06-15 18:42:27,821 ERROR
[JDBCExceptionReporter] : The last packet successfully received from the server
was 38729 seconds ago.The last packet sent successfully to the server was 38729
seconds ago, which  is longer than the server configured value of 'wait_timeout'.
You should consider either expiring and/or testing connection validity before
use in your application, increasing the server configured values for client
timeouts, or using the Connector/J connection property 'autoReconnect=true' to
avoid this problem.
INFO   | jvm 1    | 2010/06/15 14:42:27 | Jun 15, 2010 6:42:27 PM
org.apache.catalina.core.ApplicationContext log
INFO   | jvm 1    | 2010/06/15 14:42:27 | SEVERE: Exception while dispatching
incoming RPC call

I have read so many different things (none of which worked), please help

A: Look at this link http://www.databasesandlife.com/automatic-reconnect-from-hibernate-to-mysql/
 In "hibernate.cfg.xml":

<!-- hibernate.cfg.xml -->
<property name="c3p0.min_size">5</property>
<property name="c3p0.max_size">20</property>
<property name="c3p0.timeout">1800</property>
<property name="c3p0.max_statements">50</property>
<property name="connection.provider_class">
   org.hibernate.connection.C3P0ConnectionProvider</property>
<!-- no "connection.pool_size" entry! -->

Then create a file "c3p0.properties" which must be in the root of the classpath (i.e. no way to override it for particular parts of the application):
# c3p0.properties
c3p0.testConnectionOnCheckout=true

A: Romain, I do not have a hibernate.cfg.xml (all done in applicationContext.XML)
c3p0.properties
c3p0.testConnectionOnCheckout=true

applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xsi:schemaLocation="
           http://www.springframework.org/schema/context
           http://www.springframework.org/schema/context/spring-context-2.5.xsd
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
           http://www.springframework.org/schema/tx
           http://www.springframework.org/schema/tx/spring-tx-2.0.xsd
           ">

    <context:annotation-config/>

    <context:component-scan base-package="za.co.cmsoftware.traintrack.server"/>

    <!-- Application properties -->
    <bean id="propertyConfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="locations">
            <list>
                <value>file:${user.dir}/@propertiesFile@</value>
            </list>
        </property>
    </bean>

    <bean id="sessionFactory"
          class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.dialect">${connection.dialect}</prop>
                <prop key="hibernate.connection.username">${connection.username}</prop>
                <prop key="hibernate.connection.password">${connection.password}</prop>
                <prop key="hibernate.connection.url">${connection.url}</prop>
                <prop key="hibernate.connection.driver_class">${connection.driver.class}</prop>
                <prop key="hibernate.show_sql">${show.sql}</prop>
                <prop key="hibernate.hbm2ddl.auto">update</prop>
                <prop key="hibernate.c3p0.min_size">5</prop>
                <prop key="hibernate.c3p0.max_size">20</prop>
                <prop key="hibernate.c3p0.timeout">1800</prop>
                <prop key="hibernate.c3p0.max_statements">50</prop>
                <prop key="hibernate.c3p0.idle_test_period">300</prop>
                <prop key="connection.provider_class">org.hibernate.connection.C3P0ConnectionProvider</prop>
            </props>
        </property>
        <property name="annotatedClasses">
            <list>
                <value>za.co.xxxx.traintrack.server.model.Answer</value>
                <value>za.co.xxxx.traintrack.server.model.Company</value>
                <value>za.co.xxxx.traintrack.server.model.CompanyRegion</value>
                <value>za.co.xxxx.traintrack.server.model.Merchant</value>
                <value>za.co.xxxx.traintrack.server.model.Module</value>
                <value>za.co.xxxx.traintrack.server.model.Question</value>
                <value>za.co.xxxx.traintrack.server.model.User</value>
                <value>za.co.xxxx.traintrack.server.model.CompletedModule</value>
            </list>
        </property>
    </bean>

    <bean id="dao" class="za.co.xxxx.traintrack.server.DAO">
        <property name="sessionFactory" ref="sessionFactory"/>
        <property name="adminUsername" value="${admin.user.name}"/>
        <property name="adminPassword" value="${admin.user.password}"/>
        <property name="godUsername" value="${god.user.name}"/>
        <property name="godPassword" value="${god.user.password}"/>
    </bean>

    <bean id="transactionManager"
          class="org.springframework.orm.hibernate3.HibernateTransactionManager">
        <property name="sessionFactory">
            <ref local="sessionFactory"/>
        </property>
    </bean>

    <!-- enable the configuration of transactional behavior based on annotations -->
    <tx:annotation-driven transaction-manager="transactionManager"/>

</beans>


text:
Q: Why does Harry address the Weasley-parents with "Mr. & Mrs"? The relationship between Harry & the Weasley-parents grows to be quite close. At one point I think Molly even says that Harry is like a son to her. Nevertheless Harry keeps addressing them with "Mr. Weasley" and "Mrs. Weasley" and doesn't use their first names.
Why does he do that? Is it a normal thing to do in Britain?

A: The short answer is that it's perfectly normal in the UK for a child to address
the parents of a school friend as Mister and Mrs, even into adulthood. The flipside is that it would seem very odd if he started referring to them by their first names even if you had a scene where they told him to do so.
You might also want to note that it would make picking up a subsequent book harder for new readers since you'd basically have changed their character names.

A: I'm not sure that this needs to be a competing answer, but since other people have pressed for it:
Yes, it is perfectly normal in some parts of British society.  There are some parts of the independent schools system where this form of address between children and adults is perfectly normal, and indeed the children address one another by surname only.
Draco Malfoy's "Potter", "Weasley", and "Granger" are in fact how all pupils address one another in such schools.  Adults, both masters/mistresses and the parents of other pupils, would be "sir" or "miss", or "Mr Weasley" or "Mrs Weasley".
Whether Hogwarts is an independent school, or is state-funded, is a good question (especially as many people's assumption that it is independent seems flatly contradicted by recent pronouncements from the author).  But it's another question.  ☺  To this question: Yes, what you see is quite normal, and one of the many facets of this particular British schools sector that one can see reflected in the stories.
Don't mistake this for thinking that this is necessarily common across British society as a whole.  It is not at all unified in this respect.  There are, equally, parts of the British schools system to which these mores seem utterly alien and even appalling.  So it can be surprising even to other Brits to hear anecdotes such as:

*

*One can go through school without ever learning the first names of some of one's fellow pupils.  As someone who systematically attempted to learn people's first names, I can report from direct experience that it even went so far as there being people who actually refused to tell me their first names.

*Faced with two pupils sharing the same surname, rather than resort to given names as disambiguators, my Lower Fourth form-master promptly gave both pupils ad-hoc nicknames based upon their (then) appearance, which pretty much stuck with them for the rest of their school lives.

There is also a movement amongst teachers that objects to female teachers being "miss" whilst male teachers are "sir".  The twain are not equivalent in status.  This is part of a larger linguistic debate over the titles for men and for women, of course.  (I rather like James Tiptree Jr's gender-neutral approach to the subject.)
Equally, do not mistake this for being something that is strictly peculiar to independent schools.  It is just far more common and far more pronounced, to the inclusion of pupils, there.  There are some state-funded schools which adopt similar codes to lesser or greater extent.  To give two current examples:

*

*Addressing adults in this manner is actually in rule #1 of the School Rules for the Queen's School, a state-funded school in Hertfordshire, today: Be polite, kind and helpful to teachers, support staff, visitors and other students, regardless of their age, colour, religion, race, language, sexuality or background.  Address male staff as "Sir" or "Mr" with their surname and female staff as Ma'am', "Mrs" or "Miss" with their surname.

*It is in the first rule of the School Rules for St Dunstan's School, an Academy Converter in Somerset, today: Behave politely and sensibly at all times. Show respect for other people and their property.  Female staff should be addressed as Mrs, Miss with the surname. Male staff as 'Sir' or Mr with the surname.
Yes, being required to address teachers in this way does bleed over into addressing all adults, in and out of school, in this way.  In the opinions of some, it is intended to.
If you want to read even further about this across society as a whole, then you can do worse than to start with the publications of the Society for Name Studies in Britain (president: Peter McClure, Honorary Professor within the Institute for Name-Studies, University of Nottingham).
Further reading

*

*School Rules.  The Queen's School.  2016.

*"School Rules".  Code of Behaviour.  St Dunstan's School.  2016.

*Tim Walker (2014-10-06).  A tale of two schools.  The Independent.

*Maev Kennedy (2014-05-13).  Just who is that woman at the front of the class?.  The Guardian.

*Robyn Wilder (2014-02-19). 23 Things That Happen To You At A British Boarding School.  buzzfeed.

*Pete Wharmby (2013-02-13).  Ofsted Report: Hogwarts School of Witchcraft and Wizardry.  Life, teaching and other distractions.  blogspot.

*Peter McClure (1981).  "Nicknames and petnames: linguistic forms and social contexts".  Nomina.  ISSN 0141 6340.  vol. 4.  pp. 63–76.  Society for Name Studies in Britain and Ireland.


text:
Q: Clicking hyperlink changed value of cell on different worksheet to link cell's value I have a worksheet with full price offers and a seperate worksheet which makes alterations to this price based on factors such as condition.
Since there is quite a large amount of full price offers, I thought an easy way would be to make each price a hyperlink which copies to a cell in the worksheet with price adjustments, where the prices will automatically adjust.
I'm not really good with VBA, but I've conjured up a basic code.
Dim ClickCell As String

Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
    If Sh.Name = "Book 1" Then
        If ClickCell = "A3" Then
            Sheets("Book 2").Range("B2").Value = "Sample Data"
        End If
    End If
End Sub

Private Sub Workbook_SheetSelectionChange(ByVal Sh As Object, ByVal Target As Range)
    If Sh.Name = "Book 1" Then
        ClickCell = Target.Address(False, False)
    End If

End Sub

The main problem with this code (I'll be able to change the IF statement to a range to cover the entire column containing prices), is that I can't fetch the value of the cell containing the hyperlink and paste it to cell B2. ActiveCell.Value only seems to copy the value of B2 (the cell where the price should be pasted, essentially replacing the value of that cell with itself), and BeforeDoubleClick didn't seem to work for me at all.
Finally, I've been running this code as a Workbook module since it runs across different worksheets, is that right?
Edit: Asked to provide data samples (I'm not sure if this is right).
Sheet1
Sheet2

A: Target contains the cell in which the Hyperlink is located. You can get the location from Target.SubAddress (see comments in code):
Private Sub Workbook_SheetFollowHyperlink(ByVal Sh As Object, ByVal Target As Hyperlink)
    Dim subAddress() As String

    If Sh.Name = "Book 1" Then
        ''.SubAddress is for example 'Book 2'!B2
        ''Get sheet name by splitting into an array by delimiter !
        subAddress = Split(Target.subAddress, "!")
        ''Trim ' from the first item
        subAddress(0) = Replace(subAddress(0), "'", "")

        Sheets(subAddress(0)).Range(Target.subAddress).Value = Target.Range.Value
    End If
End Sub


text:
Q: Problems trying to mock a Model within Flask-SQLAlchemy I'm testing a Flask application that have some SQLAlchemy models using Flask-SQLAlchemy and I'm having some problems trying to mock a few models to some methods that receive some models as parameters.
A toy version of what I'm trying to do is like this. Suppose I have a model given by:
// file: database.py
from flask_sqlalchemy import SQLAlchemy

db = SQLAlchemy()

class User(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    username = db.Column(db.String(80), unique=True)
    birthday = db.Column(db.Date)

That is imported in an app that is built with the app factory pattern:
// file: app.py
from flask import Flask
from database import db

def create_app():
    app = Flask(__name__)
    app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db'
    db.init_app(app)

And some function that needs a User as parameter:
// file: actions.py
import datetime

SECONDS_IN_A_YEAR = 31556926

def get_user_age(user):
    return (datetime.date.today() - user.birthday).total_seconds() //  SECONDS_IN_A_YEAR

Moreover there should be a couple of views and blueprints that are imported in app.py and registered in the app that latter call the function get_user_age somewhere.
My problem is: I want to test the function get_user_age without having to create an app, registering with a fake database, etc, etc. That shouldn't be necessary, the function is totally independent from the fact that it is used in a Flask app.
So I tried:
import unittest

import datetime
import mock

from database import User
from actions import get_user_age

class TestModels(unittest.TestCase):
    def test_get_user_age(self):
        user = mock.create_autospec(User, instance=True)
        user.birthday = datetime.date(year=1987, month=12, day=1)
        print get_user_age(user)

That raises me a RuntimeError: application not registered on db instance and no application bound to current context exception. So I thought "yeah, obviously I must patch some object to prevent it from checking if the app is registered with the database and etc". So I tried decorating it with @mock.patch("database.SQLAlchemy") and other things to no avail.
Do anyone know what should I patch to prevent this behavior, or even if my test strategy is all wrong?

A: I found another way around this problem. The basic idea is to control the access to static attributes. I used pytest and mocker, but the code could be adapted to use unittest.
Let's look at a working code example and than explain it:
import pytest

import datetime

import database

from actions import get_user_age

@pytest.fixture
def mock_user_class(mocker):
    class MockedUserMeta(type):
        static_instance = mocker.MagicMock(spec=database.User)

        def __getattr__(cls, key):
            return MockedUserMeta.static_instance.__getattr__(key)

    class MockedUser(metaclass=MockedUserMeta):
        original_cls = database.User
        instances = []

        def __new__(cls, *args, **kwargs):
            MockedUser.instances.append(
                mocker.MagicMock(spec=MockedUser.original_cls))
            MockedUser.instances[-1].__class__ = MockedUser
            return MockedUser.instances[-1]

    mocker.patch('database.User', new=MockedUser)

class TestModels:
    def test_test_get_user_age(self, mock_user_class):
        user = database.User()
        user.birthday = datetime.date(year=1987, month=12, day=1)
        print(get_user_age(user))

The test is pretty clear and to the point. The fixture does all the heavy lifting:

*

*MockedUser would replace the original User class - it would create a new mock object with the right spec every time it's needed

*The purpose of MockedUserMeta has to be explained a bit further: SQLAlchemy has a nasty syntax which involves static functions. Imagine your tested code has a line similar to this from_db = User.query.filter(User.id == 20).one(), you should have a way to mock the response: MockedUserMeta.static_instance.query.filter.return_value.one.return_value.username = 'mocked_username'
This is the best method that I found which allows to have tests without any db access and without any flask app, while allowing to mock SQLAlchemy query results.
Since I don't like writing this boilerplate over and over, I have created a helper library to do it for me. Here is the code I wrote to generate the needed stuff for your example:
from mock_autogen.pytest_mocker import PytestMocker
print(PytestMocker(database).mock_classes().mock_classes_static().generate())

The output is:
class MockedUserMeta(type):
    static_instance = mocker.MagicMock(spec=database.User)

    def __getattr__(cls, key):
        return MockedUserMeta.static_instance.__getattr__(key)

class MockedUser(metaclass=MockedUserMeta):
    original_cls = database.User
    instances = []

    def __new__(cls, *args, **kwargs):
        MockedUser.instances.append(mocker.MagicMock(spec=MockedUser.original_cls))
        MockedUser.instances[-1].__class__ = MockedUser
        return MockedUser.instances[-1]

mocker.patch('database.User', new=MockedUser)

Which is exactly what I needed to place in my fixture.

A: So, I found a solution after banging my head on the keyboard for a few hours. The problem seems to be the following (if anyone knows better, please correct me).
When I run mock.create_autospec(User), the mock module tries to inspect all attributes of User to create the adequate spec for the Mock object it will spit out. When this happens, it tries to inspect the attribute User.query, which can only be evaluated when you are inside the scope of a Flask app.
This happens because when User.query is evaluated, an object is created that needs a valid session. This session is created by the create_scope_session method on the SQLAlchemy class inside Flask-SQLAlchemy.
This method instantiates a class called SignallingSession whose __init__ method calls the SQLAlchemy.get_app method. This is the method that raises the RuntimeError when there's no app registered in the db.
By patching the SignallingSession method everything works nicely. Since I don't want to interact with the database this is ok:
import unittest
import datetime

import mock

from actions import age

@mock.patch("flask_sqlalchemy.SignallingSession", autospec=True)
class TestModels(unittest.TestCase):

    def test_age(self, session):
        import database

        user = mock.create_autospec(database.User)
        user.birthday = datetime.date(year=1987, month=12, day=1)
        print age(user)


text:
Q: Python Lexical Diversity Calculation Reads In Twitter JSON to a point and then fails I have written a script which calculates lexical diversity and a few other meaningful statistics. My problem is that on some files it fails when it hits what I can only assume is a bad json line. Each of my data files contain strings of json each on their own lines. The meaningful field for these calculations is the "text" field.
My code:
import fileinput
import json
import sys
import os
from collections import defaultdict

line = []                                                       # set to list
tw = 0                                                          # set total words to int
tuw = 0                                                         # set total unique words to int
lexd = 0                                                        # set total lexical diversity to int
awpt = 0                                                        # set average words per tweet to int
line_counter = 0

inputfilename = sys.argv[1]                                     # read the first system argument as the input file name

word_count = defaultdict(int)                                   # set word_count to the default dictionary

for line in fileinput.input([inputfilename]):                   # FOR each line in the input file
        line = line.strip();                                            # strip any blank lines and throw them out
        if not line: continue                                           # if the file does contain a blank line still: in the case of EOF then continue
        tweettext = json.loads(line).get('text')                        # load the line with json.loads and get the "text" field
        if not json.loads(line).get('text'): continue                   # if the line does not contain json data then continue
        words = tweettext.split()                                       # split the words from the single line into individual dicts
        tw += len(words)                                                # total words counter
        line_counter += 1                                               # total lines counter
        print line_counter                                              # so we know what line we're on
        for word in words:                                              # FOR each word in the individual line "text" corpus
                word_count[word]+=1                                             # Take the word_count dict, insert the words and incriment

tuw = len(set(word_count))                                      # calculate the total number of unique words
lexd += 1.0*tuw/tw                                              # calculate the lexical diversity
awpt = 1.0*tuw/line_counter                                     # calc average number of words per tweet

print word_count                                                # print the word list dictionary
print "total number of words", tw                               # print the total number of words
print "total uniq words", tuw                                   # print the total number of unique words
print "total corpus lexical diversity", lexd                    # print the total lexical diversity of the entire corpus
print "average number of words per tweet", awpt                 # print the average number of words per tweet

Sample Data:
{"favorited": false, "in_reply_to_user_id": 213741147, "contributors": null, "truncated": false, "text": "@Rafinha_Angelo sim sim, manda o print l\u00e1 HUSAHUS!", "created_at": "Tue Feb 14 00:30:59 +0000 2012", "retweeted": false, "in_reply_to_status_id_str": "169216950453542912", "coordinates": null, "in_reply_to_user_id_str": "213741147", "entities": {"user_mentions": [{"indices": [0, 15], "screen_name": "Rafinha_Angelo", "id": 213741147, "name": "Rafael A. Figueiredo", "id_str": "213741147"}], "hashtags": [], "urls": []}, "in_reply_to_status_id": 169216950453542912, "id_str": "169217034821976067", "in_reply_to_screen_name": "Rafinha_Angelo", "user": {"follow_request_sent": null, "profile_use_background_image": true, "profile_background_image_url_https": "https://si0.twimg.com/images/themes/theme9/bg.gif", "verified": false, "profile_image_url_https": "https://si0.twimg.com/profile_images/1769152407/223_normal.JPG", "profile_sidebar_fill_color": "252429", "is_translator": false, "id": 67115876, "profile_text_color": "666666", "followers_count": 310, "profile_sidebar_border_color": "181A1E", "location": "Somewhere.", "default_profile_image": false, "listed_count": 0, "utc_offset": -10800, "statuses_count": 6027, "description": "it's like one more day, with no more things !", "friends_count": 106, "profile_link_color": "2FC2EF", "profile_image_url": "http://a2.twimg.com/profile_images/1769152407/223_normal.JPG", "notifications": null, "show_all_inline_media": false, "geo_enabled": true, "profile_background_color": "1A1B1F", "id_str": "67115876", "profile_background_image_url": "http://a1.twimg.com/images/themes/theme9/bg.gif", "screen_name": "Guiii_Fernandes", "lang": "en", "profile_background_tile": false, "favourites_count": 112, "name": "Guilherme Fernandes", "url": "http://facebook.com/GuiiFernandes", "created_at": "Wed Aug 19 20:43:05 +0000 2009", "contributors_enabled": false, "time_zone": "Brasilia", "protected": false, "default_profile": false, "following": null}, "place": null, "retweet_count": 0, "geo": null, "id": 169217034821976067, "source": "web"}
{"favorited": false, "in_reply_to_user_id": null, "contributors": null, "retweeted_status": {"favorited": false, "in_reply_to_user_id": null, "contributors": null, "truncated": false, "text": "On the stage in Vegas for the last few days of rehearsal...this is epic! Going to be a huge show. I like! (said in Borat voice). Xoxo, JM", "created_at": "Mon Feb 13 23:27:08 +0000 2012", "retweeted": false, "in_reply_to_status_id_str": null, "coordinates": null, "in_reply_to_user_id_str": null, "entities": {"user_mentions": [], "hashtags": [], "urls": []}, "in_reply_to_status_id": null, "id_str": "169200965151494144", "place": null, "user": {"follow_request_sent": null, "profile_use_background_image": true, "id": 69751644, "description": "", "verified": true, "profile_image_url_https": "https://si0.twimg.com/profile_images/387138234/1_normal.jpg", "profile_sidebar_fill_color": "5c5c5c", "is_translator": false, "geo_enabled": false, "profile_text_color": "333333", "followers_count": 473162, "profile_sidebar_border_color": "00e35f", "id_str": "69751644", "default_profile_image": false, "location": "Los Angeles", "utc_offset": -28800, "statuses_count": 5380, "profile_background_color": "00e35f", "friends_count": 10730, "profile_link_color": "05bcff", "profile_image_url": "http://a0.twimg.com/profile_images/387138234/1_normal.jpg", "notifications": null, "show_all_inline_media": false, "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/72720138/green.jpg", "profile_background_image_url": "http://a0.twimg.com/profile_background_images/72720138/green.jpg", "screen_name": "jamesmaslow", "lang": "en", "profile_background_tile": false, "favourites_count": 1, "name": "james maslow", "url": "http://www.JamesMaslow.com", "created_at": "Sat Aug 29 01:32:02 +0000 2009", "contributors_enabled": false, "time_zone": "Pacific Time (US & Canada)", "protected": false, "default_profile": false, "following": null, "listed_count": 8348}, "in_reply_to_screen_name": null, "retweet_count": 465, "geo": null, "id": 169200965151494144, "source": "Osfoora for iPhone"}, "truncated": true, "text": "RT @jamesmaslow: On the stage in Vegas for the last few days of rehearsal...this is epic! Going to be a huge show. I like! (said in Bora ...", "created_at": "Tue Feb 14 00:30:59 +0000 2012", "retweeted": false, "in_reply_to_status_id_str": null, "coordinates": null, "in_reply_to_user_id_str": null, "entities": {"user_mentions": [{"indices": [3, 15], "id_str": "69751644", "id": 69751644, "name": "james maslow", "screen_name": "jamesmaslow"}], "hashtags": [], "urls": []}, "in_reply_to_status_id": null, "id_str": "169217034817765377", "place": null, "user": {"follow_request_sent": null, "profile_use_background_image": true, "id": 466873377, "description": "Totally dedicate for @1LoganHenderson MINE perfect BTBoy!!!! *--* Rusher for the infinity and beyond and much more beyond!!! Since 01/17/12 =*", "verified": false, "profile_image_url_https": "https://si0.twimg.com/profile_images/1781262618/_20120126_023206_424_normal.gif", "profile_sidebar_fill_color": "940a2d", "is_translator": false, "geo_enabled": false, "profile_text_color": "eb4466", "followers_count": 103, "profile_sidebar_border_color": "d61153", "id_str": "466873377", "default_profile_image": false, "location": "", "utc_offset": -7200, "statuses_count": 3730, "profile_background_color": "070808", "friends_count": 154, "profile_link_color": "de243d", "profile_image_url": "http://a2.twimg.com/profile_images/1781262618/_20120126_023206_424_normal.gif", "notifications": null, "show_all_inline_media": false, "profile_background_image_url_https": "https://si0.twimg.com/profile_background_images/421884815/tumblr_lz7316OE041rnvmm7o1_500.jpg", "profile_background_image_url": "http://a3.twimg.com/profile_background_images/421884815/tumblr_lz7316OE041rnvmm7o1_500.jpg", "screen_name": "Logiehbear", "lang": "en", "profile_background_tile": true, "favourites_count": 209, "name": "BBFFF da Laryh!!", "url": null, "created_at": "Tue Jan 17 21:53:17 +0000 2012", "contributors_enabled": false, "time_zone": "Mid-Atlantic", "protected": false, "default_profile": false, "following": null, "listed_count": 1}, "in_reply_to_screen_name": null, "retweet_count": 465, "geo": null, "id": 169217034817765377, "source": "web"}

Script output:
1
2
defaultdict(<type 'int'>, {u'be': 1, u'is': 1, u'Going': 1, u'in': 2, u'I': 1, u'(said': 1, u'RT': 1, u'huge': 1, u'for': 1, u'l\xe1': 1, u'few': 1, u'Vegas': 1, u'manda': 1, u'print': 1, u'sim,': 1, u'sim': 1, u'On': 1, u'to': 1, u'like!': 1, u'HUSAHUS!': 1, u'rehearsal...this': 1, u'@jamesmaslow:': 1, u'...': 1, u'epic!': 1, u'stage': 1, u'a': 1, u'show.': 1, u'last': 1, u'of': 1, u'days': 1, u'o': 1, u'@Rafinha_Angelo': 1, u'the': 2, u'Bora': 1})
total number of words 36
total uniq words 34
total corpus lexical diversity 0.944444444444
average number of words per tweet 17.0

This runs actually quite fast, however on some of my datasets after a few thousands lines it will fail with:
Traceback (most recent call last):
  File "lex.py", line 21, in <module>
    tweettext = json.loads(line).get('text')                        # load the line with json.loads and get the "text" field
  File "/usr/lib64/python2.7/json/__init__.py", line 326, in loads
    return _default_decoder.decode(s)
  File "/usr/lib64/python2.7/json/decoder.py", line 366, in decode
    obj, end = self.raw_decode(s, idx=_w(s, 0).end())
  File "/usr/lib64/python2.7/json/decoder.py", line 382, in raw_decode
    obj, end = self.scan_once(s, idx)
ValueError: Unterminated string starting at: line 1 column 1531 (char 1531)

If the script is getting hung up on the format of the line that it is reading in then I would like to just skip that line and move on. Any suggestions?

A: I've solved this issue using Jesse Harris' solution of including an exception if json.loads errors out.
import fileinput
import json
import sys
import os
from collections import defaultdict

line = []
tw = 0
tuw = 0
lexd = 0
awpt = 0
line_counter = 0

inputfilename = sys.argv[1]

word_count = defaultdict(int)

for line in fileinput.input([inputfilename]):
        line = line.strip();
        if not line: continue
        try:
               tweettext = json.loads(line).get('text')
               if not json.loads(line).get('text'): continue
               words = tweettext.split()
               tw += len(words)
               line_counter += 1
               print line_counter
               for word in words:
                      word_count[word]+=1
        except:
               print "Problem Line: " + line

tuw = len(set(word_count))
lexd += 1.0*tuw/tw
awpt = 1.0*tuw/line_counter

# print word_count
print "total number of words", tw
print "total uniq words", tuw
print "total corpus lexical diversity", lexd
print "average number of words per tweet", awpt

When I ran this against my data it resulted in the print out of a gzip'd line of data. As I mentioned in my previous comment this was due to switching to the gzip streaming API from twitter. Two thumbs up to @jesseharris


text:
Q: Why can't I write sematicLabel in Flutter I am quite a beginner at Flutter so I have  a question why can't I fit sematicLabel in here?

A: Container doesn't have a property called semanticLabel. You can use instead Semantics.
Semantics(
  label: 'Venus',
  child: Container(
    child: Image.asset('assets/images/venus.png'),
    height: 200,
    width: 200,
  ),
)


text:
Q: Update value of attribute with count condition requirement I have a data query result from query
select count(type_of_vegetation)as count,type_of_vegetation
from tb_patrol
group by type_of_vegetation

as shown below:
count | type of vegetation
1     | Semak Belukar, Pepohonan
2     | Pakis, Sawit, Senduduk
1     | Pakis, Sawit, Ilalang, Akasia
49    | Sawit
15    | Pakis, Karet
17    | Semak Belukar

I'd like to update the value of "type of vegetation" which has value of count that is less than 15 into "Others" but with condition group by type of vegetation, as in the example below:
count | type of vegetation
1     | Others
2     | Others
1     | Others
49    | Sawit
15    | Pakis, Karet
17    | Semak Belukar

I use postgres SQL.

A: Use a subquery and IN operator:
UPDATE tb_patrol
SET type_of_vegetation = 'Other'
WHERE type_of_vegetation  IN (
   select type_of_vegetation
   from tb_patrol
   group by type_of_vegetation
   having count(type_of_vegetation) < 15
);


text:
Q: Taking an existing private image and flash to another server I'm trying to figure out a way to take an existing private exported standard image template to flash to another server / instance. Looking through the API, I haven't been able to find anything, i've only found way to look up the private images on has. (Doing this via python / custom module ansible)

A: You need to make sure that the image template is being listed here: https://control.softlayer.com/devices/images
if you can see the imagetemplate so you can use the reload method, see the code example here, make sure that you are using the correct image templateID
this code can help you to list your image templates:
"""
Get private image template

the script calls the SoftLayer_Account::getPrivateBlockDeviceTemplateGroups method
to list the private templates in the account and uses an object mask
to display more related information of the images templates

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Account
http://sldn.softlayer.com/reference/services/SoftLayer_Account/getPrivateBlockDeviceTemplateGroups
http://sldn.softlayer.com/reference/dataypes/SoftLayer_Virtual_Guest_Block_Device_Template_Group

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

# Your SoftLayer API username and key.
USERNAME = 'set me'
API_KEY = 'set me'

# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
accountService = client['SoftLayer_Account']

# declaring an object mask to get more information about the images templates
objectMask = "mask[summary,note,status[name],storageRepository[datacenter],transaction[transactionGroup,transactionStatus],children[storageRepository[datacenter],blockDevices[diskImage[type]]]]"

try:
    result = accountService.getPrivateBlockDeviceTemplateGroups(mask=objectMask)
    print(result)
except SoftLayer.SoftLayerAPIError as e:
    """
    # If there was an error returned from the SoftLayer API then bomb out with the
    # error message.
    """
    print("Unable to retrieve the list of image templates. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))

also may this code can help you to create your image template, in case you are not able to see it in the portal, make sure that the image template is in one of your clusters of object storage.
"""
Create Image Template from external source

This script creates a transaction to import a disk image from an external source and create
a standard image template

Important manual pages:
http://sldn.softlayer.com/reference/services/SoftLayer_Virtual_Guest_Block_Device_Template_Group/createFromExternalSource
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Container_Virtual_Guest_Block_Device_Template_Configuration
http://sldn.softlayer.com/reference/datatypes/SoftLayer_Virtual_Guest_Block_Device_Template_Group

License: http://sldn.softlayer.com/article/License
Author: SoftLayer Technologies, Inc. <sldn@softlayer.com>
"""
import SoftLayer

# Your SoftLayer username and apiKey
USERNAME = 'set me'
API_KEY = 'set me'

# Declare the group name to be applied to the imported template
name = 'imageTemplateTest'
# Declare the note to be applied to the imported template
note = 'This is for test Rcv'

'''
Declare referenceCode of the operating system software description for the imported VHD
available options: CENTOS_6_32, CENTOS_6_64, CENTOS_7_64, REDHAT_6_32, REDHAT_6_64, REDHAT_7_64,
UBUNTU_12_32, UBUNTU_12_64, UBUNTU_14_32, UBUNTU_14_64, WIN_2003-STD-SP2-5_32, WIN_2003-STD-SP2-5_64,
WIN_2008-STD-R2-SP1_64, WIN_2012-STD_64.
'''
operatingSystemReferenceCode = 'CENTOS_6_64'

'''
Define the parameters below, which refers to object storage where the image template is stored.
It will help to build the uri.
'''
# Declare the object storage account name
objectStorageAccountName = 'SLOS307608-10'
# Declare the cluster name where the image is stored
clusterName = 'dal05'
# Declare the container name where the image is stored
containerName = 'OS'
# Declare the file name of the image stored in the object storage, it should be .vhd or
fileName = 'testImage2.vhd-0.vhd'

"""
Creating an SoftLayer_Container_Virtual_Guest_block_Device_Template_Configuration Skeleton
which contains the information from external source
"""
configuration = {
    'name': name,
    'note': note,
    'operatingSystemReferenceCode': operatingSystemReferenceCode,
    'uri': 'swift://'+ objectStorageAccountName + '@' + clusterName + '/' + containerName + '/' + fileName
}

# Declare the API client
client = SoftLayer.Client(username=USERNAME, api_key=API_KEY)
groupService = client['SoftLayer_Virtual_Guest_Block_Device_Template_Group']

try:
    result = groupService.createFromExternalSource(configuration)
    print(result)
except SoftLayer.SoftLayerAPIError as e:
    print("Unable to create the image template from external source. faultCode=%s, faultString=%s" % (e.faultCode, e.faultString))
    exit(1)


text:
Q: Why does window.variable returns undefined let a = {};
console.log(window.a);
console.log(a);

why is result:
undefined
Object

rather than both Object
Updated:
How do I access global a from within this function without going to Var?
let a = {
    func1() {
        let a = 'something';  // local a

        // need to access the global a not the local a here
        window.a.func2();
    },
    func2() {
    }
};