text:
Q: image cropping with codeigniter I am working with jcrop and codeigniter to allow users to crop images that they upload, I want to the image t crop to a size of 90x60 but what ever I try nothing seems to work, my current code looks like this,
CONTROLLER
function save_crop() {
        $this->load->library('image_lib');

        $config['image_library'] = 'gd2';
        //$config['library_path'] = '/usr/X11R6/bin/';
        $config['source_image'] = './media/images/uploads/company_uploads/' . $this->input->post('image_name');
        //$config['new_image'] = './media/images/uploads/company_uploads/cropped' . $this->input->post('image_name').'_'.time();
        //die($config['source_image']);
        $config['x_axis'] = $this->input->post('x');
        $config['y_axis'] = $this->input->post('y');
        $config['width'] = $this->input->post('w');
        $config['height'] = $this->input->post('h');
        $config['maintain_ration'] = TRUE;
        $config['dynamic_output'] = TRUE;
        $this->image_lib->initialize($config);

        if(!$this->image_lib->crop()) {
            echo $this->image_lib->display_errors();
        } else {
            echo "Success";
        }
    }

JAVASCRIPT
$('#jcrop_target').Jcrop({
        onChange: showPreview,
        onSelect: showCoords,
        aspectRatio: 1,
        addClass: 'custom',
        maxSize: [90,60]
    });

    function showPreview(coords)
    {
        var rx = 100 / coords.w;
        var ry = 100 / coords.h;

        $('#preview').css({
            width: Math.round(rx * 500) + 'px',
            height: Math.round(ry * 370) + 'px',
            marginLeft: '-' + Math.round(rx * coords.x) + 'px',
            marginTop: '-' + Math.round(ry * coords.y) + 'px'
        });
    };

    function showCoords(c)
    {
        $('#x').val(c.x);
        $('#y').val(c.y);
        $('#x2').val(c.x2);
        $('#y2').val(c.y2);
        $('#w').val(c.w);
        $('#h').val(c.h);
    };

HTML
<?php if(isset($upload_data)) :?>
            <?php if($upload_data['image_width'] > 90 || $upload_data['image_height'] > 60) : ?>

Your image is a little large

            <form action="<?php echo base_url();?>employer/save_crop" method="post">

                <img src="<?php echo base_url();?>media/images/uploads/company_uploads/<?php echo $upload_data['file_name'];?>" id="jcrop_target"/>

                <img src="<?php echo base_url();?>media/images/uploads/company_uploads/<?php echo $upload_data['file_name'];?>" id="preview"/>

                <input type="hidden" name="x" id="x" />
                <input type="hidden" name="y" id="y" />
                <input type="hidden" name="x2" id="x2" />
                <input type="hidden" name="y2" id="y2" />
                <input type="text" name="w" id="w" />
                <input type="text" name="h" id="h" />
                <input type="hidden" name="image_name" value="<?php echo $upload_data['file_name'];?>"/>
                <input type="submit" name="crop_image" value="Crop" />
            </form>
            <?php endif; ?>
        <?php endif; ?>

A: $config['maintain_ratio'] = TRUE;

You must put maintain_ratio instead of maintain_ration.

A: If you posted the error message(s) that Codeigniter was throwing, it would allow us to be a lot more helpful.
Are you utilizing Codeigniter's 'Form helper' for validation? If 'maxSize' is set correctly in jCrop, you shouldn't be having any problems...
Errors please :)


text:
Q: Forced unwrap of a return type? I'm starting to get my head around optionals and forced unwrapping, except for in one particular context: when it is a return type to a function.
What is the difference between:
func myFunction() -> NSData { ... }

func myFunction() -> NSData! { ... }

func myFunction() -> NSData? { ... }

Furthermore, when I use a return value of NSData!, I am forced to use ? which seems odd.
func myFunction() -> NSData! { ... }
let data = myFunction()
data?.write()

Why do I need the ? if I force unwrapped the return?

A:
func myFunction() -> NSData { ... }

The above means that myFunction returns an instance of NSData.

func myFunction() -> NSData? { ... }

The above means that myFunction returns a value of type Optional<NSData> (also called NSData?). Optional is an enum with two cases: .some(value) and .none (also called nil). So the function returns either an NSData (wrapped in the .some case), or nil.

func myFunction() -> NSData! { ... }

The above means that myFunction returns a value of type Optional<NSData>, just like the NSData? return type in the previous example.
However, the use of ! means that, if you use the value of myFunction() in a way that doesn't type-check, the compiler will try unwrapping the returned value for you. So if you say this:
let maybeLength = myFunction()?.length

then the compiler will see that you are treating the return value of myFunction as an Optional<NSData>. But if you say this:
let dataLength = myFunction().length

then the compiler will see that Optional<NSData> doesn't have a length member, so it will pretend you wrote this:
let dataLength = myFunction()!.length

and if that compiles, it will carry on.
This behavior was defined in Swift Evolution proposal SE-0054, Abolish ImplicitlyUnwrappedOptional type.

Now let's finally consider this:

func myFunction() -> NSData! { ... }
let data = myFunction()
data?.write()

What is the type of data? The compiler has to infer the type of data based on the expression on the right side of the =. As I explained in the example above, the type of myFunction() is Optional<NSData>. So the type of data is Optional<NSData>, also called NSData?.
The compiler doesn't run into any trouble making data's type NSData?, so it has no reason to implicitly unwrap the return value of myFunction.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Calculate Euclidean distance for each item in a list I'm using Pillow with Python 3.3, and for each image I have, I want to analyse all pixels colors and calculate if each color is nearest to white or to black. I've tried with Euclidean distance with this formula:
>>>a,b=(127,255) #color value of pixel at position (1,1)
>>>whitedist=sqrt((a-255)**2 + (b-255)**2)
>>>print (whitedist)
128.0

Pixels have two values because I'm working with a greyscale image.
The thing is that of course I can't do this for each pixel of a 128x128 image, so I tried to write my first "for" cycle ever:
colors=im.getdata() #all pixel values
for item in col:
    for item in range (0, 127):
    print ("B") #if the value is between 0 and 127 the color is nearer to black

this was a totally stupid attempt, python went into an infinite loop and I had to quit it. My problem is that I have a raw idea of what to do but I don't know python so well to translate my reasoning into code. I think my reasoning it's not completely wrong but I can't find a way to translate it into code.
Since list(im.getdata()) returns a list of tuples, one tuple for each pixel containing two values, what I think I should do is to apply the formula whitedist=sqrt((a-255)**2 + (b-255)**2) to each tuple and if the result of the formula is <128, tag the pixel as "dark", if >128 then tag the pixel as "light", then I need to count all dark and light pixels and see if the image has more dark or light pixels.
Is it totally wrong to do this with a for cycle?

A: With getdata you retrieve all pixels, so if the image size is 128 x 128 this means 16384 pixels. These are stored as 16384 values in the variable colors as you mentioned.
You can just loop over the complete values with one loop:
for item in colors:
  whitedist=sqrt((item[0]-255)**2 + (item[1]-255)**2)
  if whitedist <= 128:
     darkPixels++
  else:
     lightPixels++

If you know how the colors are represented you can calculate the euclidean-distance as you mentioned. Note that you did not specify what todo if the value is 128, and how you want to store the tags. If it is only necessary to know how many pixels are dark or light you can use the example above.

A: Try this:
colors = im.getdata() #all pixel values
# initialize lists for dark and light pixels
darkList=[]
lightList=[]
# set counter for dark and light pixels
dark = 0
light = 0
for item in colors:  # iterate over each tuple
    if sqrt((item[0]-255)**2 + (item[1]-255)**2) < 128:  # See if Euclidean distance is less than 128
        lightList.append(item)  # append pixel to light pixel list
        light+=1   # increment light pixel counter
    else:
        darkList.append(item)  # append pixel to dark pixel list
        dark+=1   # increment dark pixel counter

print("Total light pixels =",light)
print(lightList)
print("Total dark pixels =",dark)
print(darkList)


text:
Q: Use the laws of logic to show that $[a\Rightarrow(b\lor c)]\Leftrightarrow[(a\land\lnot b)\Rightarrow c]$ I am trying to prove that $[a\Rightarrow(b\lor c)]\Leftrightarrow[(a\land\lnot b)\Rightarrow c]$.
My proof is the following:

*

*$a\Rightarrow(b\lor c)~$ Premise

*$(a\Rightarrow b)\lor c~$ Associative Law

*$(\lnot a\lor b)\lor c~$ Material Implication

*$\lnot(a\lor\lnot b)\lor c~$ De Morgan's Law

*$(a\land\lnot b)\Rightarrow c~$ Material Implication
I'm having doubts about my second step. I tried to check for the validity of my step using truth table,  and the statements in the first and second steps are logically equivalent. Is my application of associative law legal?

A: Yes it is logically equivalent. See that you can go directly from first line to third line by material implication
$$ a \rightarrow (b \lor c) \iff \neg a \lor (b \lor c) \iff (\neg a \lor b) \lor c $$
Assuming you know how to go from step 2 to 3, then you should know how to go from step 3 to step 2.
Also, see Material Implication. As a rule of thumb to look at boolean algebra, remove that arrow!


text:
Q: JSON Post Response from JSON Post Request I have created a REST webservice which gives me
'GET JSON Response' as :
 {
        "payload": {
            "RFID": "E2005180040F003122202E5F",
            "chassisNumber": "4654689761",
            "vehicleNumber": "TN 01 1991"
        },
        "success": "true"
    }

Now I want Post Response from below Post Request :
Vehicle tag Request
{
  "vehicle_no": "TN07B0054"
 }

I have created the post method but it takes the whole thing as argument.
How to take vehicle argument as "TN07B0054" only from the Vehicle tag request.
Below is the POST response when I give above Vehicle Tag Request :
{
    "payload": {
        "vehicleNumber": "\"vehicle_no\": \"TN 07 B 0054\""
    },
    "success": "false"
}

A: You can make a entity named VehicleTagRequest
public class VehicleTagRequest {
    private String vehicle_no;

    public String getVehicle_no() {
        return vehicle_no;
    }

    public void setVehicle_no(String vehicle_no) {
        this.vehicle_no = vehicle_no;
    }
}

Easiest way to deserialise your string to above java object is to use Jackson library (https://github.com/FasterXML/jackson)
If you are Maven for dependency management, you can add dependency like below in your pom.xml (this step is not required if you are maintaining your dependencies locally)
        <dependency>
            <groupId>com.fasterxml.jackson.core</groupId>
            <artifactId>jackson-databind</artifactId>
            <version>2.9.0.pr4</version>
        </dependency>

Now comes deserialisation of your vehicle tag request json
Deserialisation using Jackson is done using ObjectMapper API if you are not using annotations,
I have made a sample code snippet attached below-
public class VehicleSerialisation {

    public static void main(String[] args) {
        String vehicle = "{\"vehicle_no\": \"TN07B0054\"}";

        ObjectMapper objectMapper = new ObjectMapper();
        VehicleTagRequest vehicleTagRequest = null;
        try {
            vehicleTagRequest = objectMapper.readValue(vehicle, VehicleTagRequest.class);
        } catch (IOException e) {
            e.printStackTrace();
        }
        System.out.print(vehicleTagRequest.getVehicle_no());
    }
}

You can then use the vehicleTagRequest.getVehicle_no() to form your request of GET JSON Response

A: This is not valid Json
{
    "payload": {
        "vehicleNumber": "\"vehicle_no\": \"TN 07 B 0054\""
    },
    "success": "false"
}

Without escape char
{
    "payload": {
        "vehicleNumber": "vehicle_no": "TN 07 B 0054"
    },
    "success": "false"
}

You can use like this
{
        "payload": {
            "vehicleNumber": {
          "vehicle_no": "TN 07 B 0054"
              }
        },
        "success": "false"
    }

And your POJO should be like
public class MyPojo
{
    private Payload payload;

    private String success;

    public Payload getPayload ()
    {
        return payload;
    }

    public void setPayload (Payload payload)
    {
        this.payload = payload;
    }

    public String getSuccess ()
    {
        return success;
    }

    public void setSuccess (String success)
    {
        this.success = success;
    }

    @Override
    public String toString()
    {
        return "ClassPojo [payload = "+payload+", success = "+success+"]";
    }
}


text: Q: Any ideas how to create auto-cutting file when it's size overflow some value? I have some primitive logger that writes information to file, but we have memory limitations with sending files to server, is there any practices to auto-cut file when it's size overflow some size value, for example, 2MB?


text:
Q: large memory: wakeup slower than boot I've upgraded my Windows 7 machine to 24GB.
As described here, I found out that 24GB of my precious C: SSD were taken for swap file. To solve this, I moved the swap file to my 2TB non SSD E: drive.
So, I though I've got everything under control. However, I find out that resuming after sleep is much slower than booting up the system. I think this is because on wakeup the system has to read 24GB of RAM from the hard disk (non SSD), while on boot-up the system has to read much a much smaller amout and from an SSD, to boot (pun intended). This is bad because a system wakes-up much more frequently that it boots-up.
Any ideas how to solve this large-memory/SSD driver gotcha?


text:
Q: Sequence number based on set of values in SQL I have a temp table like this.
DECLARE @temp TABLE
(PID INT)
INSERT INTO @temp values(1)
INSERT INTO @temp values(1)
INSERT INTO @temp values(1)
INSERT INTO @temp values(1)
INSERT INTO @temp values(2)
INSERT INTO @temp values(3)
INSERT INTO @temp values(1)
INSERT INTO @temp values(1)
INSERT INTO @temp values(4)
INSERT INTO @temp values(4)
INSERT INTO @temp values(5)
INSERT INTO @temp values(5)
INSERT INTO @temp values(5)
INSERT INTO @temp values(6)
INSERT INTO @temp values(6)

SELECT * FROM @temp
PID
1
1
1
1
2
3
1
1
4
4
5
5
5
6
6

OUTPUT: I want to give a sequence number for each set only based on next value.
 PID Sequence
  1    1
  2    2
  3    3
  1    4
  4    5
  5    6
  6    7

I tried all possible ways. Nothing worked. Can anyone please help me on this?


text:
Q: Using realloc to shrink memory allocation I want to use realloc to free memory from the end of a chunk of memory. I understand that the standard does not require that realloc succeed, even if the memory requested is lower than the original malloc/calloc call. Can I just realloc, and then if it fails returns the original?
// Create and fill thing1
custom_type *thing1 = calloc(big_number, sizeof(custom_type));
// ...

// Now only the beginning of thing1 is needed
assert(big_number > small_number);
custom_type *thing2 = realloc(thing1, sizeof(custom_type)*small_number);

// If all is right and just in the world, thing1 was resized in-place
// If not, but it could be copied elsewhere, this still works
if (thing2) return thing2;

// If thing2 could not be resized in-place and also we're out of memory,
// return the original object with extra garbage at the end.
return thing1;

This is not a minor optimization; the part I want to save might be as little as 5% of the length of the original, which could be several gigabytes.

Note: Using realloc to shrink the allocated memory and Should I enforce realloc check if the new block size is smaller than the initial? are similar but do not address my particular question.

A: Yes, you can. If realloc() is not successful, the original memory region is left untouched. I usually use code like this:
/* shrink buf to size if possible */
void *newbuf = realloc(buf, size);
if (newbuf != NULL)
    buf = newbuf;

Make sure that size is not zero. The behaviour of realloc() with a zero-length array depends on the implementation and can be a source of trouble. See this question for details.


text:
Q: Vectorize a manipulation of a portion of DataFrame I have this assignment and I'm not trying to get it solved for me, I only want to solve it using the most PYTHONIC way "then what is the meaning of programing by doing 100 for loops while techniques like vectorization exist", Besides I have stuck at a certain point and I do not know why it is not working with me.
The Task
My dataset is a subset of The National Centers for Environmental Information, which is the daily climate records from thousands of land stations. The data are as below I'm supposed to clean the data and plot the temp against each day of the 365 days of the year.
df
    ID          Date        Element Data_Value
0   USW00094889 2014-11-12  TMAX    2.2
1   USC00208972 2009-04-29  TMIN    5.6
2   USC00200032 2008-05-26  TMAX    27.8
3   USC00205563 2005-11-11  TMAX    13.9
4   USC00200230 2014-02-27  TMAX    -10.6
5   USW00014833 2010-10-01  TMAX    19.4
6   USC00207308 2010-06-29  TMIN    14.4
7   USC00203712 2005-10-04  TMAX    28.9
8   USW00004848 2007-12-14  TMIN    -1.6
9   USC00200220 2011-04-21  TMAX    7.2

df.shape
(165085, 4)

My Strategy
1- Split the DF into two(2) DFs one for Element='TMAX' and one for the other for the Element='TMIN', because I didn't find a way to group by 'Date' and 'Element' then having the result of each in a separate column using one vectorized command.
2- Group by 'Date' aggregate on 'Data_Value' with MAX for DFMAX and with MIN for DFMIN.
3- Merge both DFs using outer and index for both = True
< 1st checkpoint: if there is one command which is really considered pythonic and professional to do this task instead of these 3 steps  >
4- Remove leap days
5- add the 'Day_of_Year' column which will hold the day of year number. Here I stuck, as the leap year has 366 days, meaning that Mar, 1st in the normal year has the Day_of_Year=60, while the same day Mar, 1st in the leap Year has the Day_of_Year=61.
as a result, the final plot will not be correct as there is a day shifting of one day in the leap year.
I tried to apply a lambda function to change the value of this specific leap year but it raises an error. Code and error are below.
df['2008']['Day_of_Year'] = df['2008']['Day_of_Year'].apply(lambda x: x for x in range(1, 366))

at this point, the df.index is dateobject accordingly the df['2008'] is used.
Error
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-47-f60e8731fc55> in <module>()
      4 #
      5
----> 6 df['2008']['Day_of_Year'] = df['2008']['Day_of_Year'].apply(lambda x: x for x in range(1, 366))

/opt/conda/lib/python3.6/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
   2292             else:
   2293                 values = self.asobject
-> 2294                 mapped = lib.map_infer(values, f, convert=convert_dtype)
   2295
   2296         if len(mapped) and isinstance(mapped[0], Series):

pandas/src/inference.pyx in pandas.lib.map_infer (pandas/lib.c:66124)()

TypeError: 'generator' object is not callable

appreciate it in advance.

A: You can convert your "Date" column to a timestamp:
df["Date"] = pd.to_datetime(df["Date"])

Then you can set that same column as the index:
df = df.set_index("Date")

And finally plot the "Data_Value":
df['Data_Value"].plot()

If you want to plot TMAX and TMIN separate, then:
df['Data_Value"][df["Element"] == "TMAX"].plot()
df['Data_Value"][df["Element"] == "TMIN"].plot()


text:
Q: Counter issue ( C Program) I only want my count_float to reset back to 0 when Alarm_Status.bits.b3 is not set and when leakDetected=0. However it never seems to reset for some reason. When alarm goes off I put leakDetected to 1 so the counter cant be reset. But if alarm goes off for 2 seconds and is disabled again it holds this count of 2. It should reset to 0.
{
    int count_float
    int fixedCount = 50;
    short  leakDetected=0;
    BS(TRISB,7);    // Bund sw port=input.
    DelayMs(2); // will rise is bund SW open
    if(RB7){
        if(Control.bits.BUND_ENABLE){       // if bund alarm enabled
            if(Alarm_Status.bits.b3){   // if  already set
                count_float +=10;       //count increased by 10
                if(count_float == fixedCount) {
                    leakDetected=1;
                    DU_Reason.bits.EmergencyDialIn=1;// alarm!
                }
            }
            if((!Alarm_Status.bits.b3)&&(!leakDetected)){
                count_float=0;
            }
        }
    } else {
        Alarm_Status.bits.b3=1;     // Bund Sw Closed
        BC(TRISB,7);
    }
}

A: You are using count_float uninitialized. Accessing a variable without initializing it leads to undefined behavior.
To fix it, simply initialize as:
int count_float = 0;

About your updated question, you initialize count_float everytime you come to this loop. If you want it to maintain the previous count(as it is looping every second), please make it static as shown below.
static int count_float = 0;  /* '= 0' is optional but recommended */


text:
Q: How to run Python code with pandas, request etc dependencies from Java? There is of course JPython, that allows to run Python within JVM.
But will it do to run Python that have some or many dependencies/libraries like pandas, requests ?
Is there guaranteed way to run any Python script on JVM?

P.S. within the same process, so that memory structures can be shared.
P.P.S Jython version is 2.7, compatible with Python 2.x, there is likely no Python 3.6+ support.

The most recent release is Jython 2.7.2. It was released on 21 March 2020 and is compatible with Python 2.7

More general question was Calling Python in Java?
GraalVM Python Runtime is experimental, but aims at Python 3.8 and supporting SciPy/NumPy
https://www.graalvm.org/reference-manual/python/

GraalVM provides a Python 3.8 compliant runtime. A primary goal of the GraalVM Python runtime is to support SciPy and its constituent libraries, as well as to work with other data science and machine learning libraries from the rich Python ecosystem. At this point, the Python runtime is made available for experimentation and curious end-users.

A: Last answer from https://stackoverflow.com/a/62082797/482717 gives full options list
https://talvi.net/a-brief-overview-of-python-java-bridges-in-2020.html -> https://github.com/pont-us/python-java-bridge-demos
As GraalVM is the latest effort, it is unlikely any older project succeeded in supporting  SciPy/NumPy/pandas
A brief overview of Python-Java bridges in 2020:

*

*GraalVM

Website: https://www.graalvm.org/
Documentation: https://www.graalvm.org/docs/
Source: https://github.com/oracle/graal
Initial release: 2019

*Javabridge

Website: https://github.com/LeeKamentsky/python-javabridge
Documentation: https://pythonhosted.org/javabridge/
Source: https://github.com/LeeKamentsky/python-javabridge
PyPI: https://pypi.org/project/javabridge/
Initial release: 2014

*jep

Website: https://github.com/ninia/jep
Documentation: https://github.com/ninia/jep/wiki
Source: https://github.com/ninia/jep
PyPI: https://pypi.org/project/jep/
Initial release: 2015

*jpy

Website: https://github.com/bcdev/jpy/
Documentation: https://jpy.readthedocs.io/en/latest/
Source: https://github.com/bcdev/jpy
PyPI: https://pypi.org/project/jpy/
Initial release: 2014

*JPype

Website: https://github.com/jpype-project/jpype/
Documentation: https://jpype.readthedocs.io/en/latest/
Source: https://github.com/jpype-project/jpype/
PyPI: https://pypi.org/project/JPype1/
Initial release: 2005

*Jython

Website: https://www.jython.org/
Documentation: https://www.jython.org/
Source: https://github.com/jythontools/jython
Releases announced on: http://fwierzbicki.blogspot.com/
Initial release: 1997 (as JPython)

*Py4j

Website: https://www.py4j.org/
Documentation: https://www.py4j.org/contents.html
Source: https://github.com/bartdag/py4j
PyPI: https://pypi.org/project/py4j/
Initial release: 2009

*

*https://cwiki.apache.org/confluence/display/SPARK/PySpark+Internals

*https://github.com/invesdwin/invesdwin-context-python

*PyJNIus

Website: https://github.com/kivy/pyjnius
Documentation: https://pyjnius.readthedocs.io/en/stable/
Source: https://github.com/kivy/pyjnius
PyPI: https://pypi.org/project/pyjnius/
Initial release: 2012
See also

*

*Java equivalent for the Numpy multi-dimensional object

*https://softwarerecs.stackexchange.com/questions/43154/java-equivalent-to-numpy

*https://www.infoworld.com/article/3600459/a-guide-to-using-ndarrays-in-java.html -> https://github.com/awslabs/djl


text:
Q: SSH connect error I use a notebook with Ubuntu 12.10 and try to connect a server with Ubuntu 12.04.
The server has already installed openssh-server. And allow publick key and password to login.
But I connect the server sometime well but after minutes it will be error.
First, it will show me these messages:
   WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!
     ......
     Add correct host key in /home/myname/.ssh/known_hosts to get rid of this message.
but I never reinstall system and the openssh-server. Both are never changed!
The server nerver shutdown or reboot.
Second, after I remove the relative key from my known_hosts and use ssh connect the server again, it will let me type my password.
then my nightmare coming...
 Permission denied (publickey,password)
But I typed the correct password!
PS: I used password and public key both success. But the problem will appear again after i logout then login.

A: Do you want to allow password auth? If so you can edit the /etc/ssh/sshd_config to include:
PasswordAuthentication yes

Also make sure these are set correctly for your key auth:
PubkeyAuthentication yes
AuthorizedKeysFile     %h/.ssh/authorized_keys

You can also have it ignore your known_hosts file... for debugging only please :)
IgnoreUserKnownHosts yes

Also ensure you have correct perms on your key files.. ssh is very particular about it:
chmod 700 ~/.ssh
chmod 600 ~/.ssh/*

Lastly, if all else fails send us output of your session attempt using 'ssh -vvvv'.


text:
Q: Android get Support Action Bar always returns NULL I'm using the support library v7 on a certain project. I'm trying to instantiate the support action bar like this:
ActionBar actionBar = getSupportActionBar();

    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayOptions(ActionBar.DISPLAY_SHOW_CUSTOM);
    actionBar.setCustomView(R.layout.top_action_bar);
    actionBar.setDisplayShowCustomEnabled(true);
    actionBar.setHomeButtonEnabled(true);

Everything works fine on Android devices with API lvl below 11. However, while trying to run the same code on newer devices, like a Samsung Galaxy S4 with Android 4+, getSupportActionBar() always returns null, causing the expected crash.
I'm using this style file:
<style name="my_style" parent="@style/Theme.AppCompat.Light">
    <item name="android:actionBarStyle">@style/my_style_ab</item>
    <item name="android:windowNoTitle">true</item>

</style>

<style name="my_style_ab" parent="@style/Theme.AppCompat.Light.DarkActionBar">
    <item name="android:height">70dp</item>
</style>

Any hints on what may be wrong? I think it has something to do with the style, or maybe I just can't use the support ActionBar on API lvl above 11. Thanks in advance.

A: I got the solution. And I didn't provide enough information in the question so it may be hard for others to help. However, I don't know why the problem happens, I just found out how to solve it. The error was due to the app title. I removed this item from the style:
        <item name="android:windowNoTitle">true</item>

And also all the references in the code regarding that title bar, like this one:
  requestWindowFeature(Window.FEATURE_NO_TITLE);

Why does this solve it? still don't know. It may be useful for me if someone can explain it.

A: If you are using Toolbar and AppCompat then you probably have android:windowNoTitle set to true, hiding your action bar.  Create a Toolbar in your xml and add this code in the onCreate() of your activity.
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);

A: Using android:windowNoTitle with true is hiding your ActionBar

A: Inside Manifest file, check the activity for which are you having the issue.
I have the theme with "NoActionBar" Property.
Removing it resolved this code worked for me.
android:theme="@style/AppTheme.NoActionBar"


text:
Q: Incorrect syntax when using sp_executesql I have trouble executing the dynamic sql returned by the select procedure.
Below is a sample of my code:
DECLARE
    @ID int
  , @Query nvarchar(max)
SET @ID = CONVERT(int, '[P:Field_ID]')
SET @Query =
    (
        SELECT
            FF.[External_Source_Query]
        FROM WF_Form_Field FF
            LEFT JOIN WF_Field F ON
                FF.[Field_ID] = F.[ID]
        WHERE
            FF.[External_Source_Query] IS NOT NULL
        AND F.[ID] = @ID
    )

EXEC SP_EXECUTESQL(@Query)

I am receiving an error saying Incorrect syntax near '@Query'.
Any help please?

A: Don't use brackets:
EXEC SP_EXECUTESQL @Query

You would use brackets if you we're doing a plain EXEC:
EXEC(@Query)

However, I also fail to see how this line will ever produce a correct result:
SET @ID = CONVERT(int, '[P:Field_ID]')

Since I can see no rational way to interpret the string [P:Field_ID] as an integer.


text:
Q: Make HTTP request with Elixir and Phoenix I'm a Ruby dev trying to get into elixir. I'm trying to interact with an API in order to learn a little Elixir. I'm basically trying to make an http request. In ruby the thing I'm trying to do would look like this.
require 'httparty'

url = "https://api.sportradar.us/nba/trial/v4/en/games/2016/11/05/schedule.json?api_key={api_key}"
response = HTTParty.get(url)
req = response.parsed_response

Pretty straightforward and simple. Now I have a json decoded response that I can use. How can I do this with Elixir and Phoenix?

A: With httpoison (HTTP Client) and poison (JSON Encoder/Decoder) packages, this is almost as simple as your code which uses HTTParty:
url = "https://api.sportradar.us/nba/trial/v4/en/games/2016/11/05/schedule.json?api_key=#{api_key}"

response = HTTPoison.get!(url)
req = Poison.decode!(response.body)

A: Not only can you write your code as simply as before as shown in @Dogbert's example, but you can do cool things with pattern matching, too (and be as granular as you like)
Using HTTPoison and Poison, as well:
url = "https://api.sportradar.us/nba/trial/v4/en/games/2016/11/05/schedule.json?api_key={api_key}"

case HTTPoison.get(url) do
  {:ok, %{status_code: 200, body: body}} ->
    Poison.decode!(body)

  {:ok, %{status_code: 404}} ->
    # do something with a 404

  {:error, %{reason: reason}} ->
    # do something with an error
end


text:
Q: How to send large byte arrays between activities in Android? I need to send byte[] data from Activity1 to Activity2, in order to writedata("FileOutputStream.write(data)") in a jpg file. My final .jpg file could exceed 1mb.
Activity1:
public void onPictureTaken(byte[] data, Camera camera) {

    Log.w("ImageSizeMyApp", String.valueOf(data.length));

    mCamera.startPreview();
    Intent shareWindow = new Intent(Activity1.this, Activity2.class);
    shareWindow.putExtra("photo",data);
    startActivity(shareWindow);
    closeCamera();

    Log.w("CameraActivity:", "onPictureTaken");

}

In Activity2:
Bundle extras = getIntent().getExtras();
data = extras.getByteArray("photo");

I use Log.w("ImageSizeMyApp", String.valueOf(data.length)); to get this:

*

*ImageSizeMyApp﹕ 446367 (this size sends to the next activity, and everything is good)

*ImageSizeMyApp﹕ 577368 (this size closes my camera, and does not send to the next activity)
So 500kb is the limit dimension for Intent. Is there any other stable method to send my byte[] larger than 500kb between activities?
Any reference or advice is welcome. Thanks in advance!
Update:
Could I make another class to store that byte[] array? Or is it better to use a static variable?

A: *

*Create a temporary file.

*Pass the file path to the Other Activity.

*Get the path and load the image.

Activity 1 :
    //creates the temporary file and gets the path
String filePath= tempFileImage(context,yourBitmap,"name");

Intent intent = new Intent(context, Activity2.class);

//passes the file path string with the intent
intent.putExtra("path", filePath);

startActivity(intent);

Use this method to create the file:
   //creates a temporary file and return the absolute file path
public static String tempFileImage(Context context, Bitmap bitmap, String name) {

    File outputDir = context.getCacheDir();
    File imageFile = new File(outputDir, name + ".jpg");

    OutputStream os;
    try {
        os = new FileOutputStream(imageFile);
        bitmap.compress(Bitmap.CompressFormat.JPEG, 100, os);
        os.flush();
        os.close();
    } catch (Exception e) {
        Log.e(context.getClass().getSimpleName(), "Error writing file", e);
    }

    return imageFile.getAbsolutePath();
}

Activity 2 :
//gets the file path
String filePath=getIntent().getStringExtra("path");

//loads the file
File file = new File(filePath);

Finally load the image:
Picasso.with(context).load(file).fit().centerCrop().into(imageView);

Or:
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath());
imageView.setImageBitmap(bitmap);

A: I had the same problem. In short: subclass the Application (or create a helper singleton), use it (<application android:name=".App" .../> in manifest.xml) and store the image data there.
App.java snippet:
public final class App extends Application {
    private static App sInstance;
    private byte[] mCapturedPhotoData;

    // Getters & Setters
    public byte[] getCapturedPhotoData() {
        return mCapturedPhotoData;
    }

    public void setCapturedPhotoData(byte[] capturedPhotoData) {
        mCapturedPhotoData = capturedPhotoData;
    }

    // Singleton code
    public static App getInstance() { return sInstance; }

    @Override
    public void onCreate() {
        super.onCreate();
        sInstance = this;
    }
}

Camera Activity saves the data:
private Camera.PictureCallback mJpegCaptureCallback = new Camera.PictureCallback() {
    @Override
    public void onPictureTaken(byte[] data, Camera camera) {
        // We cannot pass the large buffer via intent's data. Use App instance.
        App.getInstance().setCapturedPhotoData(data);
        setResult(RESULT_OK, new Intent());
        finish();
    }
};

Parent Activity reads the data:
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == RequestCode.CAPTURE && resultCode == RESULT_OK) {
        // Read the jpeg data
        byte[] jpegData = App.getInstance().getCapturedPhotoData();
        App.log("" + jpegData.length);

        // Do stuff

        // Don't forget to release it
        App.getInstance().setCapturedPhotoData(null);
    }
}

A: Following are the steps:
1) Create table in sqlite with byte and id columns
2) Save this byte and his id (you will give) from Activity 1
3) Go to Activity 2 (do not forget to send parameter id)
4) In Activity 2 get this parameter from intent and query database using id to get you byte.
I hope this helps.


text:
Q: CKEditor configuration in django admin I need to add richtextfield to my admin panel in Django, so I choose CKEditor, but I've got some problems with configuration:
When I try to move a row in django administration panel (with Enter key) editor for some reason add p tag to my text, that I don't need (i mean in admin editor, not in template). Can I somehow deactivate it? Or replace with br tag?

I use default configuration of CKEditor.
settings.py
CKEDITOR_CONFIGS = {
    'awesome_ckeditor': {
        'toolbar': 'Basic',
    },
}

models.py
class Section_1(models.Model):
    order = models.IntegerField(blank=True, default=0)
    picture = models.ImageField(blank=True)
    text = RichTextField(max_length=200, blank=True)
    ytlink = models.URLField(blank=True)

        def __str__(self):
        return self.text

    class Meta:
        verbose_name = 'Секция 1'
        verbose_name_plural = 'Секция 1'

integration in template:

{% for sec_1 in sec_1 %}
{% if sec_1.order == 1 %}

{{ sec_1.text }}

{% else %}

{{ sec_1.text }}

{% endif %}
{% endfor %}

So when I open template without {{ sec_1.text| safe }} I see this:

if I use it, CKEditor just ignore h4 tag:

Questions are:
1) How to remove auto adding 'p' in admin panel?
2) How, if I use |safe to my variable, to make it not ignore external html-tags?

A: If you prefer to not wrap the text in anything, you can choose to insert a line break tag because by default it takes p tag for wrapping.
config.enterMode = CKEDITOR.ENTER_P;

You need to add below line in config.js file for CKEditor:

CKEDITOR.editorConfig = function (config)
{
   config.enterMode = CKEDITOR.ENTER_BR;

   ...
};

or else if you want to wrap in div tag then,
config.enterMode = CKEDITOR.ENTER_DIV;

A: Find an answer for django:
settings.py
CKEDITOR_CONFIGS = {
    'default': {
        'toolbar': 'Basic',
        **'enterMode': 2,**
    },
    'awesome_ckeditor':{
        'toolbar': 'Custom',
        'toolbar_Custom': [
            [ 'Bold','Italic','Underline','Strike','-
','Link','Unlink','Anchor','-', 'Styles','Format','Font','FontSize','-',
'Image' ]
        ]
    },
}


text:
Q: How to style form inside modal with Bootstrap 3 I place this form using modal.In order to do so I use this helper library like this:
 BootstrapDialog.show({
    message:formHtml
   ,cssClass:'.form-dialog'
 });

I use this css:
 #ma-form-container{
            width:600px;
            height:100%;
        }

        #ma-form label
        {
            display:inline-block;
            text-align:right;
        }

I find that the form is much larger than the modal,I also tried using the css:
     #ma-form-container{
            width:100%;
            height:100%;
        }

y
I find that $("#ma-form") and $("#ma-form-container") are empty when the modal  is open.
EDIT:
I have changed the template and removed the plugin:

        <button type="button" class="close" data-dismiss="modal">×Close</button>

Details

          <form class="form form-horizontal" role="form" id="ma-form">

                  AuthorizGroup

                      <input type="text" class="form-control" name="AUTHGRP" id="AUTHGRP" placeholder="AuthorizGroup">

                  Description

                      <input type="text" class="form-control" name="DESCRIPT" id="DESCRIPT" placeholder="Description">

                  Object type

                      <input type="text" class="form-control" name="OBJECTTYPE" id="OBJECTTYPE" placeholder="Object type">

                  Planner group

                      <input type="text" class="form-control" name="PLANGROUP" id="PLANGROUP" placeholder="Planner group">

                  Planning plant

                      <input type="text" class="form-control" name="PLANPLANT" id="PLANPLANT" placeholder="Planning plant">

                  EquipCategory

                      <input type="text" class="form-control" name="EQUICATGRY" id="EQUICATGRY" placeholder="EquipCategory">

                      <input type="" class="form-control" name="" id="" placeholder="">

          </form>

        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
        <button type="button" class="btn btn-primary" id="formSubmit">Submit</button>

With this I am using this to open the dialog:
  $("#map-actions a").on("click",function(e){
                        event.preventDefault();
                         $("#openModal").html(formHtml);
                         $("#openModal").css("display","block");

                    });

A: in your form you are using a wrong syntax for set an id attribute
change
id="#ma-form"

to
id="ma-form"

and it will work, dont forget to fix this recursively to all occurences of your fault
alert($('#ma-form').html())

will output the content instead of "undefined"
cheers


text:
Q: How to pass an ADODB Recordset to a function in PowerShell I'm trying to take an ADODB recordset that is an extract of Active Directory data and then do a recursive search through it to build the equivalent of an organizational tree starting at a given name. In order of preference, I would like to find out how to make one of the following work:
   1. Ideally I would like to create the recordset in one function and read it in another.
   2. Create the recordset as global, fill it in one function and read from it in another
   3. Minimally, I need to create it in the body of the script and read it in a function due to recursively building the list of names.
Any help you can give will be immensely appreciated. Here is my code:
    Param(
        [Parameter(Mandatory=$False)]
        [string]$Name,

        [Parameter(Mandatory=$False)]
        [string[]]$Attr
    )

    Set-StrictMode -Version Latest

    function Get-ADData() {
        Param (
            [Parameter(Mandatory=$True)]
            [string[]] $Attr,

            [Parameter(Mandatory=$True)]
            [string] $Filter
        )

        $conAdData = new-Object  -com "ADODB.Connection"
        $comAdData = new-Object -com "ADODB.Command"
        $rsAdData = New-Object -ComObject "ADODB.Recordset"

        $conAdData.Provider = "ADsDSOObject"
        $conAdData.Open( "Active Directory Provider")
        $comAdData.ActiveConnection = $conAdData

        $comAdData.Properties.Item("Page Size").value = 1000
        $comAdData.Properties.item("Searchscope").value = 2

        $comAdData.CommandText = "Select " + ($attr -join ", ") + " From 'LDAP://jive.jive.com:3268/DC=jive,DC=jive,DC=com' Where " + $Filter
        $rsAdData = $comAdData.Execute()
        $rsAdData
    }

    function Get-Subordinates() {
        Param (
            [Parameter(Mandatory=$True)]
            [string] $Name,

            [Parameter(Mandatory=$True)]
            $Recordset
         )

        $aaData = @{}
        $fields = @()

        $Recordset.MoveFirst()
        $Recordset.Find("Name = '" + $Name + "'")

        $aaData.Add($Name, "")

        if ($Recordset.Fields.Item("directReports"))
        {
            $arReports = ($Recordset.Fields.Item("directReports")) -split ';'

            ForEach ($report in $arReports)
            {
                if ($report.Trim() -ne "")
                {
                    Write-Host $report
                    $report = ($report -split ",")[0,1] -join ","
                    $report = $report.Substring(3)
                    $report = $report.Replace("\", "")
                    $aaData += Get-Subordinates -Name $report
                }
            }
        }
        $aaData
    }

    $objRecordSet = New-Object -ComObject ADODB.Recordset

    # Set the name for the top of the tree
    # if it's not set
    if (!$Name)
    {
        $Name = "Turkey, Jive"
    }

    # Creat the list of attributes we want to collect
    # And add the supplied attribute if one was supplied
    # Name and directReports are necessary to build the tree
    if ($Attr)
    {
        $Attr = @("Name", $Attr, "Manager", "directReports")
    }
    else
    {
        $Attr = @("Name", "sAMAccountName", "Manager", "directReports")
    }

    # Filter used to get AD information. Strip out non users and any account
    # without either a Manager or name
    $Filter = "objectCategory = 'Person' And Manager = '*' And name = '*'"

    # Grab our bulk AD data
    $objRecordset = Get-ADData -Attr $Attr -Filter $Filter

    # Build the tree recursively
    $aaReportData = Get-Subordinates -Name $Name -Recordset $objRecordSet


text:
Q: Turn two columns into one SQL I'm trying to turn this result:
Data1   Data2
  A       C
  A       C
  A       D
  B       F

Into this one:
Data
A
B
C
D
F

Is there a way of doing this in SQL without using UNION, because the query to get this results is really long and I don't want to call it twice.
Thanks

A:
the consult to get this results is really long and I don't want to call it twice.

I assume this means you have a complicated or expensive query you don't want to duplicate. You can use subquery factoring, also known as a common table expression or CTE, to treat your existing query as if it was a table:
with cte as (
  -- your existing query goes here
)
select data1 as data from cte
union
select data2 from cte
order by data


text:
Q: Determine the point at which moment vector is zero on a 3D body I have information about total force and moment on a body for three points, whose coordinates I know. From this information I would like to determine the point at which moment would be zero.
Generally,
$\vec{M} = \vec{r} \times \vec{F}$
...which can be written as ...
$\vec{M} = \begin{bmatrix} \vec{i}&\vec{j}&\vec{k} \\ r_x&r_y&r_z \\ F_x&F_y&F_z \end{bmatrix}  $
...or expanded out ...
$\vec{M} = (r_yF_z-r_zF_y)\vec{i} + (r_zF_x-r_xF_z)\vec{j} + (r_xF_y-r_yF_x)\vec{k}$
Taking a cross product of the two vectors is trivial and even I'm capable of grasping this, but what I would really like to do is backsolve for a point at which $\vec{M}=[0,0,0]$. Is this possible?
Here's what I'm seeing...
$M_x = r_yF_z-r_zF_y = 0\\
M_y = r_zF_x-r_xF_z = 0\\
M_z = r_xF_y-r_yF_x = 0$
...so in my head I'm thinking that if the forces are known and we want the moment to equal zero, this system of equations can be set up and solved for the vector:
$\begin{bmatrix}M_x\\M_y\\M_z\end{bmatrix} = \begin{bmatrix}r_x\\r_y\\r_z\end{bmatrix} \cdot \begin{bmatrix}0&F_z&-F_y\\-F_z&0&F_x\\F_y&-F_x&0\end{bmatrix} = \begin{bmatrix}0\\0\\0\end{bmatrix}$
...but obviously this is a singular matrix and there is not a distinct solution.
What am I missing here?

A: *

*The engineering answer

Every force $[F_x, F_y, F_z]$ acting on the same line of action will produce the same $[M_x, M_y, M_z]$ moments.

*

*The mathematical answer

As you said the singularity of the matrix is telling you that there is not a distinct solution.
If the coefficient matrix has a null determinant the system can be either impossible or have solutions, depending on the determinant of the complete matrix (Rouché-Capelli Theorem).
In this case the system has more than one solution: if you compute the determinant on every $3\times 3$ minor of the complete matrix you'll find out that it is zero, too$\color{red}{^1}$.
Since both the coefficient and the complete matrix are rank $2$ and there are $3$ equations, there are $\infty^1$ solutions to the problem.
$\color{red}{^1}$ This is because $\mathbf F \cdot \mathbf M=0$, that is the force and the moment vectors are perpendicular by definition, since $\mathbf M = \mathbf r \times \mathbf F \Rightarrow \mathbf F \cdot \mathbf r \times \mathbf F=0$ (triple product with two elements being the same).

What I would do to solve the problem is just to pin one of the $\mathbf r$ vector components.
For instance in your case if you pick $r_y$ you end up with
$$r_x=\frac{F_x r_y + M_z}{F_y}$$
$$r_z=\frac{F_z r_y - M_x}{F_y}$$
where $r_y$ is a value of your choice. The third equation will give $F_x M_x + F_y M_y + F_z M_z=0$ being satisfied since $\color{red}{^1}$.
At that point having a point on the line and by knowing the force components you can find any other point on the same line by defining a curvilinear abscissa $t$
$$p_x=r_x+t \cdot F_x$$
$$p_y=r_y+t \cdot F_y$$
$$p_z=r_z+t \cdot F_z$$
so that you can choose the point at which the line of action meets the object (it could also not meet it at all for some loading conditions).
Please correct me if I'm wrong!

A: You are looking for the equipollent force (and its location). This is also known as the force axis (line). Given the force vector $\boldsymbol{F}$ and moment $\boldsymbol{M}$ defined at a point, the force axis is located at
$$ \boldsymbol{r} = \frac{\boldsymbol{F} \times \boldsymbol{M}}{\| \boldsymbol{F} \|^2}$$
Note also that you can see if any moments are parallel to the force axis. You do this by calculating the scalar pitch value
$$ h = \frac{ \boldsymbol{F} \cdot \boldsymbol{M}}{\| \boldsymbol{F} \|^2}$$
This gives the parallel moment magnitude ratio to the force magnitude.
NOTE: $\cdot$ the the vector dot product, $\times$ the vector cross product and $\| \mbox{ } \|$ the vector magnitude
Proof
A force $\boldsymbol{F}$ is applied at a location $\boldsymbol{r}$ causing a moment at the origin $\boldsymbol{M} = \boldsymbol{r} \times \boldsymbol{F}$. We can get the location (at least the closest point to the force axis) by
$$ \boldsymbol{r} = \frac{\boldsymbol{F} \times \boldsymbol{M}}{\| \boldsymbol{F} \|^2} = \frac{\boldsymbol{F} \times (\boldsymbol{r} \times \boldsymbol{F})}{\| \boldsymbol{F} \|^2}$$
using the vector triple product identity $\boldsymbol{a}\times(\boldsymbol{b}\times\boldsymbol{c}) = \boldsymbol{b} (\boldsymbol{a}\cdot \boldsymbol{c})- \boldsymbol{c} (\boldsymbol{a}\cdot \boldsymbol{b})$ the above is
$$\require{cancel}
 \boldsymbol{r} = \frac{\boldsymbol{r} (\boldsymbol{F}\cdot \boldsymbol{F})- \boldsymbol{F} (\boldsymbol{F}\cdot \boldsymbol{r})}{\| \boldsymbol{F} \|^2} = \frac{\boldsymbol{r} \|\boldsymbol{F}\|^2 - \boldsymbol{F} \cancel{ (\boldsymbol{F}\cdot \boldsymbol{r})}}{\| \boldsymbol{F} \|^2} = \boldsymbol{r}$$
The cancellation happens because the location vector must be perpendicular to the force (since location along the force do not change the moments).


text:
Q: What's the fastest way to get data off Time Capsule and onto an external drive? I plugged an external drive into Time Capsule using the USB input on the back.
Then I used Finder to move data from the Time Capsule's drive to the USB drive.
Finder says it'll take over 24 hours to move that data.
There must be a faster way. Do you know how I can do that?

A: If you want an exact copy of the TC drive, the fastest way is to connect the USB drive directly to the TC and use the archiving option in Airport Utility:

Other things to consider:

*

*Transfering data over wire (ethernet) is faster than over Wi-Fi

*Connecting the USB drive directly to the computer (than to the TC) gives better results if you use the Finder to copy data.

A: I can't say for sure (so someone can correct me if AFP (which I assume is being used) works differently) but a common problem with Windows network transfers from one remote device to another is it will pull the file TO the computer you use to initiate the transfer, then move it to the destination, which is much slower than a direct transfer.
If Time Capsule has a function in its interface for transferring files to a connected drive (or can be connected to via ssh to do the same), that will probably be a better solution than initiating the transfer via Finder.

A: If you are not going to take apart Time Capsule then connect USB drive to your Mac and connect your Mac to TM by wire if possible. That would be the fastest way to copy.


text:
Q: How to send and receive data sparingly client User A connects to example.php
I know that when the client connects to example.php it tries to receive all the available content on the page...
Im also aware that if a page contains php lets say that contains a sleep(10) that the page will wait for the php to finish...
So my question how long with the client wait to get a response. Putting the users browser out of the question how long is the connection valid and open waiting for a response.
The why(not really stack overflow content beyond here)...if your so inclined
...I have a client device(not a browser) this device makes a http request to example.php...
I want the device to stay connected to my server for as long as possible...as well as maybe my server sends some data occasionally

A: It sounds like what you're looking for is long-polling.  If your non-browser HTTP client supports it, you may also want to look at WebSockets, which allows you to establish a connection via JavaScript from the client to the server and maintain an open connection where either the client or the server can initiate sending data back and forth over that established connection.


text:
Q: Spark Streaming - Kafka auto offset reset (Spark 2.4.5, kafka 0.8.2) I have a Spark Streaming application (Spark 2.4.5, kafka 0.8.2) which I am currently performance testing with different message sizes.
def create_context():
    logger.info("Creating new context - not from checkpoint")
    print("Creating new context")
    ssc = StreamingContext(sc, 5)
    opts = {"metadata.broker.list": globals()['kafka_hosts'],
            "auto.offset.reset": "largest",
            "group.id": "test_v1"}
    kvs = KafkaUtils.createDirectStream(ssc, [topic_listen], opts)
    kvs.checkpoint(120)
    print("Processing started")
    lines = kvs.map(lambda row: row[1])
    lines.foreachRDD(my_streaming_function)
    ssc.checkpoint(checkpoint)
    return ssc

ssc = StreamingContext.getOrCreate(checkpoint, lambda: create_context())
ssc.start()

The application starts, processing begins, but after some point (not being able to catch up with the messages) I get the following (expected) error on a certain batch:
Caused by: kafka.common.OffsetOutOfRangeException
    at sun.reflect.GeneratedConstructorAccessor33.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.Class.newInstance(Class.java:442)
    at kafka.common.ErrorMapping$.exceptionFor(ErrorMapping.scala:86)
    at org.apache.spark.streaming.kafka.KafkaRDD$KafkaRDDIterator.handleFetchErr(KafkaRDD.scala:188)
    at org.apache.spark.streaming.kafka.KafkaRDD$KafkaRDDIterator.fetchBatch(KafkaRDD.scala:198)
    at org.apache.spark.streaming.kafka.KafkaRDD$KafkaRDDIterator.getNext(KafkaRDD.scala:213)
    at org.apache.spark.util.NextIterator.hasNext(NextIterator.scala:73)
    at scala.collection.Iterator$class.foreach(Iterator.scala:891)
    at org.apache.spark.util.NextIterator.foreach(NextIterator.scala:21)
    at org.apache.spark.api.python.PythonRDD$.writeIteratorToStream(PythonRDD.scala:224)
    at org.apache.spark.api.python.PythonRunner$$anon$2.writeIteratorToStream(PythonRunner.scala:561)
    at org.apache.spark.api.python.BasePythonRunner$WriterThread$$anonfun$run$1.apply(PythonRunner.scala:346)
    at org.apache.spark.util.Utils$.logUncaughtExceptions(Utils.scala:1945)
    at org.apache.spark.api.python.BasePythonRunner$WriterThread.run(PythonRunner.scala:195)

The problem is that the application never recovers from this state. After 'catching up' with all the batches (no active batches waiting), when I publish any new messages the error still persists, even though the message has just been produced seconds before processing it.
I'd have thought that the 'auto.offset.reset=largest' parameter resets the offsets automatically, but I guess that's only applicable for the start of the application. What options do I have for automatic recovery?


text:
Q: Apps for multi-device firmware updating of my PC According to this question, are there some free (freeware) applications that can help me easily update whole PC's hardware's firmware? App that can find and install new versions of firmware for every single device that's in my PC, like new BIOS for motherboard, graphic card, network card or firmware for hard drive .etc?
Or even paid apps, I'd just like to know.

A: No, there's no easy, magic-bullet app for that; as least not that I'm aware of.
If there is, I would STRONGLY recommend against using it. :)
Firmware is very device and revision specific.  The way to load a firmware varies wildly between devices, manufacturers and sometime between firmware releases.
If there is trouble writing the firmware you can easily end up with a "bricked" (dead/useless) device.
Check out this SU question: What is firmware and what happens when I update it?
I think it has some points which may help you see why this would be a bad idea (an app that does them all).


text:
Q: how can i fix this slow print input error? I am working on a word game in mu and I'm using the slow print code:
import sys, time
def sprint(str):
   for c in str + '\n':
     sys.stdout.write(c)
     sys.stdout.flush()
     time.sleep(3./90)

Whenever I try to use this with an input e.g., example = input (sprint (" example")). When I run it, it comes up with example none


text:
Q: What order should the books in the Percy Jackson universe be read in? There are several dozen novels, short stories and other works set in the same world as Rick Riordan's Percy Jackson and the Olympians. Many of them aren't released chronologically in relation to each other. If I was a completely new reader, what would be the best order to read these in?
Novels:

*

*The Lightning Thief

*The Sea of Monsters

*The Titan's Curse

*The Battle of the Labyrinth

*The Last Olympian

*The Lost Hero

*The Son of Neptune

*The Mark of Athena

*The House of Hades

*The Blood of Olympus

*The Red Pyramid

*The Throne of Fire

*The Serpent's Shadow

*The Sword of Summer

*The Hammer of Thor (Unreleased)

*The Hidden Oracle

*The Dark Prophecy

*The Burning Maze

*The Tyrant's Tomb

*The Tower of Nero (Unreleased)

Short Stories:

*

*The Two Headed Guidance Counselor

*The Library of Deadly Weapons

*My Demon Satyr Tea Party

*My Personal Zombie Apocalypse

*Percy Jackson and the Stolen Chariot

*Percy Jackson and the Bronze Dragon

*Percy Jackson and the Sword of Hades

*The Diary of Luke Castellan

*Percy Jackson and the Staff of Hermes

*Leo Valdez and the Quest for Buford

*The Son of Magic (Written by Haley Riordan but still canon)

*The Son of Sobek

*The Staff of Serapis

*The Crown of Ptolemy
Graphic Novels:

*

*The Lightning Thief Graphic Novel

*The Sea of Monsters Graphic Novel

*The Titan's Curse Graphic Novel

*The Lost Hero Graphic Novel

*The Red Pyramid Graphic Novel

*The Throne of Fire Graphic Novel
Other:

*

*Percy Jackson's Greek Gods

*Percy Jackson's Greek Heroes

*Demigods and Monsters (A book of real-world essays on the original series with an introduction by Riordan)

*Percy Jackson and the Olympians: The Ultimate Guide

*The Kane Chronicles Survival Guide

*Camp Half-Blood Classified

*Camp Jupiter Classified (Unreleased)

Let's just ignore the movies and video game.

A: I would read the main books by order of release so:

*

*The Lightning Thief

*The Sea of Monsters

*The Titan's Curse

*The Battle of the Labyrinth

*The Last Olympian

*Percy Jackson and the Stolen Chariot

*Percy Jackson and the Bronze Dragon

*Percy Jackson and the Sword of Hades

*The Lost Hero

*The Red Pyramid

*The Son of Neptune

*The Diary of Luke Castellan

*Percy Jackson and the    Staff of Hermes

*Leo    Valdez and the Quest for Buford

*The Son of    Magic

*The Throne of Fire

*The Mark of Athena

*The Serpent's Shadow

*The Son of Sobek

*The Staff of    Serapis

*The House of Hades

*The Blood    of Olympus

*The Two Headed    Guidance Counselor

*The Library of Deadly    Weapons

*My Demon Satyr Tea    Party

*The Crown of Ptolemy

*My Personal    Zombie Apocalypse

*The Sword of    Summer

*The Hidden Oracle

*The Hammer    of Thor (Unreleased)

*The Dark    Prophesy (Unreleased)

The graphic novels should be in the same order as the main books, but I would suggest reading them after you read the main books:

*

*The Lightning Thief Graphic Novel

*The Sea of Monsters Graphic Novel

*The Titan's Curse Graphic Novel

*The Lost Hero Graphic Novel

*The Red Pyramid Graphic Novel

*The Throne of Fire Graphic Novel

All of the 'other' ones should be read after you've read all of the main books.
PJGG and PJGH are the only ones that need an order, PJGG coming first and then PJGH:

*

*Percy Jackson's Greek Gods

*Percy Jackson's Greek Heroes

*Demigods and Monsters

*Percy Jackson and the Olympians: The Ultimate Guide

*The Kane Chronicles Survival Guide

A: I recommend reading chronologically
Chronological order is usually the best way to avoid spoilers (except in books with lots of time travel, or where characters can see the future…which come to think of it does apply here). This isn't strictly chronological, though: for some books, it doesn't make much difference if you read them slightly out of order.
First, read:

*

*The Diary of Luke Castellan
This describes how Luke and Thalia found Annabeth, and as such is set some       years before the main in Percy Jackson and the Olympians
Then, start  Percy Jackson and the Olympians:

*

*The Lightning Thief

*The Lightning Thief Graphic Novel
After this, it should be safe to read:

*

*The Two Headed Guidance Counselor

*The Library of Deadly Weapons

*My Demon Satyr Tea Party

*My Personal Zombie Apocalypse
These are interactive novels. I'm not sure where these books are located chronologically, but I don't think they'll spoil anything that you wouldn't have learned in the first book.
We have a short story that occurs after  The Lightning Thief:

*

*Percy Jackson and the Stolen Chariot
Then return to the main series:

*

*The Sea of Monsters

*The Sea of Monsters Graphic Novel
Another short story:

*

*Percy Jackson and the Bronze Dragon
This provides useful background for events that occur in The Lost Hero, but if you like surprises you might want to hold off until after that novel.
Back to Percy Jackson and the Olympians

*

*The Titan's Curse

*The Titan's Curse Graphic Novel

*The Battle of the Labyrinth

*The Battle of the Labyrinth Graphic Novel
Next is:

*

*The Red Pyramid

*The Red Pyramid Graphic Novel
Apparently this short story happens during The Red Pyramid:

*

*Percy Jackson and the Sword of Hades
Then is the second book in the Kane Chronicles:

*

*The Throne of Fire

*The Throne of Fire Graphic Novel

*The Kane Chronicles Survival Guide
This last book was published before The Serpent's Shadow, and should therefore be safe to read here
Then:

*

*The Last Olympian

*The Last Olympian Graphic Novel
Then read

*

*The Son of Magic
This story follows a demigod who fought in the Manhattan battle in The Last Olympian, and as such should be read after that novel.
Next is probably:

*

*The Staff of Hermes

*Percy Jackson and the Singer of Apollo
Back to the Kane Chronicles:

*

*The Serpent's Shadow
After that, we start on Heroes of Olympus:

*

*The Lost Hero

*Leo Valdez and the Quest for Buford

*The Son of Neptune

*The Mark of Athena

*The House of Hades

*The Blood of Olympus
You might as well read these afterwards:

*

*Percy Jackson's Greek Gods

*Percy Jackson's Greek Heroes

*Demigods and Monsters

*Percy Jackson and the Olympians: The Ultimate Guide
Most of these could be read earlier, but are probably best enjoyed once one has gained a full appreciation of the Greek side of the Riordanverse.
Then come:

*

*The Son of Sobek

*The Staff of Serapis

*The Crown of Ptolemy
Then comes the first entry in Magnus Chase and the Gods of Asgard:

*

*The Sword of Summer
This is out of the order that the chronology in the notes presents it, but The Sword of Summer is definitely set before or concurrently with The Hidden Oracle. Percy references Annabeth being in Boston:

"Annabeth." I tried to place the name. "She's the blond scary one?"
"That's her. I promised her specifically that I wouldn't get myself
  killed while she's gone."
"Gone?"
Percy waved vaguely toward the north. "She's in Boston for a few
  weeks. Some family emergency. The point is—"
The Hidden Oracle

Lest we think that this refers to some meeting between Annabeth and Magnus after the events of The Hidden Oracle, The Hammer of Thor references the events of that series:

'There's a crisis happening,' Annabeth said. 'A god fell to earth as a
  human. These evil Roman emperors are back, causing trouble.'
The Hammer of Thor

Then go on to:

*

*The Hidden Oracle
Finally:

*

*The Hammer of Thor

*The Dark Prophecy
These last one has not been released as of the time this answer was written, and as such must be read last. Also, practically speaking, since it is unreleased I don't really know where it fits in chronologically.
Note: Graphic novels tend to be less detailed than prose novels, so reading the print version of each novel before the graphic version might help you understand the graphic novel better.
Note : I received a great deal of help from this timeline. It's not certain, but I'm not going to do all that work over myself.

A: Personally, I would read series that were meant to be in order in the order they were intended. For example, instead of cutting the Kane Chronicles together with Heroes of Olympus just because they were released around the same time, I would read Heroes of Olympus then Kane Chronicles, or vice versa, just because it can be somewhat jarring to jump back and forth between relatively unrelated stories.


text:
Q: Q: PayPal collecting the amount from the basket I want the amount from the basket to be downloaded when I click the PayPal button and instead of the total entered. I can not seem to get it to work.
I use this.
Anyone have any pointers?

A: You need to update below total with the total of your basket - it's not going to happen automatically.
     {
        amount: { total: '0.01', currency: 'USD' }
     }


text:
Q: Alternate Way of dblinks in oracle I am having the multiple client instance of Oracle db and one central Oracle db.
we are required to communicate to Central db from client db without creating the dblinks. We are having the application developed on java.
Problems:
we cant have the central db connections in properties file or in any other classes.
We cant create dblinks to client database.
Its like one running application on client side is having its own db instance.
Please suggest us how to proceed.
Thanks in advance.

A: A solution is to develop your own protocol.
Any time a transaction happens on one database, you dump the DML associated with it, and you run it on the other ones.

*

*The source database has any modification audited (see SQL-trace or V$SQL...). This is one java daemon, or can also be PL/SQL.

*You must have a queue to handle the DML or DDL orders and run them after that in the same order on any other database.

*The destination database collects the DML or DDL, let's say on a Samba share or something, and run them locally. This can be a java daemon doing the job.

Hope it helps and good luck!


text:
Q: FileNotFound while File is there I am using getClassLoader().getResources to find the path for Jsoup to parse.
String path = JsoupDemo1.class.getClassLoader().getResource("student.xml").getPath();
Document document = Jsoup.parse(new File(path), "utf-8");
Elements names = document.getElementsByTag("name");
System.out.println(names.size());

My student.xml has been placed under the src folder in my module "day11_xml" and this code snippet comes from the class JsoupDemo1 in the package cn.itcast.xml.jsoup under the same module of "day11_xml". The error messages reads as follows:

java.io.FileNotFoundException:/Users/dingshun/Downloads/New%20Java%20Projects/demo/out/production/day11_xml/student.xml (No such file or directory)

I don't get it, as I can find the exact file in the given path. I'm confused, but could you guys help me out? Also, I'm new to both Java programming and this forum and if this question sounds silly or my question format is not right, please let me know.

A: What you're doing looks good. Maybe use the stream version JSoup.parse.
URL url = JsoupDemo1.class.getClassLoader().getResource("student.xml");
InputStream stream = JsoupDemo1.class.getClassLoader().getResourceAsStream("student.xml");
document = Jsoup.parse(stream, "utf-8", url.toURI()toString());

The documentation linked seems to imply it will work with html not xml, so maybe you need to use the other argument which provides a parser?

A: Actually, it turned out that Jsoup could not find my file because the path name "New%20Java%20Projects" has spaces between them. When I reload the file in a folder which has no spaces in its name, it works out just fine. So it can parse xml using parse(File in, String charsetName) method. It seems it cannot parse path name which has spaces in it.


text:
Q: Does any RCA connector work for S/PDIF interface? I'd like to work with this chip : http://www.cirrus.com/cn/pubs/proDatasheet/WM8804_v4.5.pdf
The S/PDIF Input mentioned in the datasheet states that the input impedance is 75Ohm. So I think that it should be used with 75Ohm coaxial cable, with RCA jacks.
So, my question is simple (and probably stupid too) : does any RCA connector work for S/PDIF interface ?

A: Yes, it will work with ANY RCA ("Cinch" in EU) connector. RCA connectors have a fixed mechanical dimension and it is not possible to make them 75-ohm (or 50 ohm or whatever).  However using 75 ohm cable is desirable if you are using lengths ~>1m


text:
Q: Magento 2 : skip error thrown Is their any way we can skip through this ?
throw new \Magento\Framework\Exception\LocalizedException(
                                __('Any error Msg.'),
                                $e
                            );

I have created an application where i refund shipping amount online when i upload a csv with order numbers.
but for some order it did not pass through as i get exception & the execution stops.
I need to skip if error thrown & start execution of another row in csv.

A: Sure, just catch the exception where you want to continue execution...
try {
    SomeOperation();
} catch (SomeException $e) {
    // do nothing... php will ignore and continue
}

Or you can add error message in log
try {
    /* Some logic that could throw an Exception */
} catch (\Exception $e) {
    $this->logger->critical($e->getMessage());
}

It will continue your execution.


text:
Q: mySQL backup and restore c# The code have no errors. but when the I back up,the size of the file is 0kb or 1kb only. And when I restore nothing happens. All data is still deleted.
Back up Code:
string path;
path = "D:\\MySqlBackup"+ ".sql";
StreamWriter file = new StreamWriter(path);

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName ="C:\\xampp\\mysql\\bin\\mysqldump.exe";
psi.RedirectStandardInput = false;
psi.RedirectStandardOutput = true;
psi.Arguments = "--user=root --password=database --database=hotelreservationandbillingsystem < D:\\MySqlBackup.sql";
psi.UseShellExecute = false;

Process process = Process.Start(psi);
string output;
output = process.StandardOutput.ReadToEnd();
file.WriteLine(output);
process.WaitForExit();
file.Close();
process.Close();
MessageBox.Show("Back Up Successfully!","Saved",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);

Restore Code:
string path;
path = "D:\\MySqlBackup.sql";
StreamReader file = new StreamReader(path);
string input = file.ReadToEnd();
file.Close();

ProcessStartInfo psi = new ProcessStartInfo();
psi.FileName = "C:\\xampp\\mysql\\bin\\mysqldump.exe";
psi.RedirectStandardInput = true;
psi.RedirectStandardOutput = false;
psi.Arguments = "--user=root --password=database --database=hotelreservationandbillingsystem < D:\\MySqlBackup.sql";
psi.UseShellExecute = false;

Process process = Process.Start(psi);
process.StandardInput.WriteLine(input);
process.StandardInput.Close();
process.WaitForExit();
process.Close();
MessageBox.Show("Restored Successfully!", "Restored", MessageBoxButtons.OKCancel, MessageBoxIcon.Information);

A: Why not you should try a more easiest way of taking backup and restore option available
MySqlBackup.NET - MySQL Backup Solution for C#
Where the code for Backup is
string constring = "server=localhost;user=root;pwd=qwerty;database=test;";
string file = "C:\\backup.sql";
using (MySqlConnection conn = new MySqlConnection(constring))
{
    using (MySqlCommand cmd = new MySqlCommand())
    {
        using (MySqlBackup mb = new MySqlBackup(cmd))
        {
            cmd.Connection = conn;
            conn.Open();
            mb.ExportToFile(file);
            conn.Close();
        }
    }
}

And Restore
string constring = "server=localhost;user=root;pwd=qwerty;database=test;";
string file = "C:\\backup.sql";
using (MySqlConnection conn = new MySqlConnection(constring))
{
    using (MySqlCommand cmd = new MySqlCommand())
    {
        using (MySqlBackup mb = new MySqlBackup(cmd))
        {
            cmd.Connection = conn;
            conn.Open();
            mb.ImportFromFile(file);
            conn.Close();
        }
    }
}


text:
Q: Use more than 3 GB of memory on SQL Server 2005 on Windows Server 2003 R2 Enterprise x64 I am running SQL Server 2005 Standard x64 on Windows server 2003 R2 x64. I have 32GB of total server RAM. I am unable to make SQL Server use more than 3 GB of memory, even I set min and max server options as follows:
sp_configure 'show advanced options', 1
RECONFIGURE
GO

sp_configure 'min server memory', 1024
RECONFIGURE
go

sp_configure 'max server memory', 24576
RECONFIGURE
GO

What could be a problem?
Update
There was SQL Server 2005 32bit installed. See my answer.

A: Actually I did recognize that there was 32 bit version of SQL server installed. After re-installation the problem was solved.
Thank you very much for your efforts.
Cheers
Darius

A: You need to add a directive to the Boot.ini on your root drive.
under the
[operating systems] header
you should add /3gb  switch at the end of the OS entry.


text:
Q: How can I calculate total values of table column after filtering in React? Good Day! I have a simple table with filter functionality in react. The table contains only car name and price with dropdown select for filtering cars with their name. I need to display the total price of filtered cars. here is the sandbox .
What I tried was defining a function like this
const updateSubTotal = () => {
        var table = document.getElementById("myTable");
        let subTotal = Array.from(table.rows)
          .slice(1)
          .reduce((total, row) => {
            return total + parseFloat(row.cells[1].innerHTML);
          }, 0);
        setTot(subTotal);
      };

Unfortunately, this function returns invalid value. Here is the whole code
import { useState } from "react";
import "./styles.css";
const data = [
  {
    name: "Saab",
    price: 100
  },
  {
    name: "Mercedes",
    price: 50
  },
  {
    name: "Audi",
    price: 10
  }
];
export default function App() {
  const [tot, setTot] = useState();

  const updateSubTotal = () => {
    var table = document.getElementById("myTable");
    let subTotal = Array.from(table.rows)
      .slice(1)
      .reduce((total, row) => {
        return total + parseFloat(row.cells[1].innerHTML);
      }, 0);
    setTot(subTotal);
  };
  //CALCULATE sum of prices
  const totalPrice = data.map((item) => item.price).reduce((a, b) => a + b, 0);
  const [searchValue, setSearchValue] = useState("");
  const DisplayData = data
    ?.filter((row) => row?.name?.match(new RegExp(searchValue, "i")))
    .map((cars) => {
      return (

          {cars?.name}
          {cars?.price}

      );
    });
  return (

      Choose a car:
      <select
        name="cars"
        id="cars"
        value={searchValue}
        onChange={(e) => {
          setSearchValue(e.target.value);
          updateSubTotal();
        }}
      >
        <option value="saab">Saab</option>
        <option value="mercedes">Mercedes</option>
        <option value="audi">Audi</option>
      </select>

            Car Name
            Price

{DisplayData}

Total Price without filter: {totalPrice}

Total Price after filter: {tot}

  );
}

A: I would suggest using useState hook for the variables and grouping them at the beginning of your component (filteredCars list, filteredTotal)
  const [searchValue, setSearchValue] = useState(dropdownItems[0]);
  const [filteredData, setFilteredData] = useState(filterData(searchValue));
  const [filteredTotal, setFilteredTotal] = useState(
    calculateTotal(filteredData)
  );

total value doesnt change, so its okay to leave it as a constant
  const total = calculateTotal(data);

then you trigger useEffect hook when those states change,
in your example everything depends on the dropdown selection, so filtering and summing should be done when selection changes
  useEffect(() => {
    setFilteredData(filterData(searchValue));
    setFilteredTotal(calculateTotal(filteredData));
  }, [searchValue, filteredData]);

Bonus tip :
Make dropdown items dynamic, create them by spreading names from data array
const dropdownItems = [notSelectedLabel, ...data.map((row) => row.name)];

You can take a look at the codepen here

A: *

*You can pass the value to handler and filter, then calculate sum using reduce method.

*I have added id for unique keys amongst list which is crucial when the list is not static.


text:
Q: Bulk data import in Mysql table without index drop We have one single table with size 10 TB, 5 billion rows.
create table dummy_table (
  id BIGINT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  type INT, -- ENUM type, only few fixed values
  create_date DATE,
  user VARCHAR(10),
  A VARCHAR(10),
  B VARCHAR(10),
  C VARCHAR(10),
  D VARCHAR(10)
)

Data is immutable (no update operation is required. Only bulk insertion(ie. daily data load) and bulk deletion(ie. monthly data cleaning)).
Our prime use case to search by user and then type and then creation_date. For that, I am analyzing two strategies

*

*STRATEGY1: via composite index:

create index user_type_creation_date_idx on dummy_table(user, type, create_date)

*STRATEGY2: via partition and index

alter table dummy_table PARTITION BY LIST(type)
    SUBPARTITION BY HASH(YEAR(create_date) + MONTH(create_date)) (
        PARTITION pA VALUES IN (0) (
            SUBPARTITION s0,
            SUBPARTITION s1,
.....)
create index user_idx on dummy_table(user)
SELECT operation is giving almost same execution time. Problem I am facing is in bulk insertion. We are trying to pump 30 million rows(4.2 GB) from s3 file in it.
Without index and partition, it is taking around 360 sec to load that much data. But with STRATEGY2, data load time is increased to 850 sec, and with STRATEGY1, it is still running from past 15000 sec and still going on.
Dropping index is not in scope, as creating one is taking more than 7 hours and we are planning to have four more composite index
- index on user, A
- index on user, B
- index on user, C
- index on user, D

Here is my questions:

*

*In many SO post i have read NOT to create partition, but it seems that partition concept is performing well for bulk insertion. Is anything wrong
I am doing with STRATEGY1?

*Is there anyway to increase speed up bulk insertion like partition, sub-partition, mysql/innodb property, as we have advantage of single (without any join) table, that too no UPDATE is ever required?

*Is there anyway to increase bulk insertion speed by loading multiple files in parallel? LOAD DATA FROM S3 is blocking other such command. Can we run them in parallel somehow?

Version:
MySQL: 5.6

A: Plan A:  Include the index, no partitioning, and pre-sort the incoming data by user+type+create_date.  This will be the fastest.  But it needs room to presort the CSV file.
Plan B:  No index, no partitioning, just load the data, but then ADD INDEX.  This needs a huge amount of disk space to do the sorting.  This Plan may be close to as fast as Plan A.
Plan C:  If you don't need id and (user+type+create_date) is unique, then remove id and do Plan A.  Now this is the best approach.
The issues:

*

*Partitioning provides no performance benefit for your situation.

*Inserting the rows in order or building the index by sorting -- either is much faster than inserting rows randomly.

*More indexes:  (user + A/B/C/D) -- this further necessitates having user as the first item in the PK.  How many rows per user?  (Sounds like millions?)

*You mentioned monthly deletion.  This really needs PARTITION BY RANGE(TO_DAYS(...)) together with monthly partitions.  This is because DROP PARTITION is immensely faster than DELETE.  See this for more details.  So, now I recommend A or C, plus monthly partitions.

*If you must have id, then to benefit the common SELECT (and because of the huge data size),

do
PRIMARY KEY(user, type, create_date, id), -- clustered, unique, etc
INDEX(id)   -- sufficient to keep AUTO_INCREMENT happy

The math puzzles me:  5B rows of about 100 bytes each would be about 1TB (after InnoDB overhead), yet you say 10TB.
I have assumed InnoDB; if you are using some other engine, I may need to modify my answer.
Thinking further 'out of the box'...
With InnoDB and parallel loads, you should be able to do the following with "transportable tablespaces".  But it is not available for partitions until 5.7.4.
This would involve having a bunch of separate loads going on, each loading into a separate table.  When finished use "transportable tablespaces" to move each into the main table as a partition.


text:
Q: Regex without positive lookahead to match password with one uppercase, one lowercase, one digit and at least eight characters I am looking for a regex that matches strings (i.e., passwords) that have at least 8 characters, at least one upper case character, at least one lower case character, and at least one number.
A regex that works (with the help of here) would be:
(^(?=.*\d)(?=.*[a-z])(?=.*[A-Z])[0-9a-zA-Z]{8,}$)

This regex uses positive lookahead (?=). This is an expensive operation. Is it possible to make this regex without using positive lookahead?

A:
at least 8 characters, at least one upper case character,
  at least one lower case character, and at least one number

It is kind of like a puzzle

Ok, I'm going to take this as a puzzle, provided it's understood that:

*

*Coding without regex would be more efficient.

*A lookahead is NOT sinificantly expensive compared to the cost of using regex on its own.

And that this solution may be even more expensive than using a lookahead.
Description

*

*We can use a subpattern like
\A(?:[A-Z]|[a-z]|[0-9]|.){8,}

to check there are at least 8 characters in the subject, while providing the 4 options (uppercase, lowercase, digit, or some other character).

*Then, we'll create a backreference for the first 3 required options:
\A(?:(?<upper>[A-Z])|(?<lower>[a-z])|(?<digit>[0-9])|.){8,}

*And finally, we'll use an IF clause to check that each group was captured:
(?(upper)  (?#check 2nd condition)  |  (?#make it fail)  )

using (?!) to make it fail if any of the conditions isn't met:
(?(upper)(?(lower)(?(digit)|(?!))|(?!))|(?!))

Regex
\A                        #beggining of string
(?>                       #MAIN iteration (atomic only for efficiency)
    (?<upper>[A-Z])       #  an uppercase letter
  |                       # or
    (?<lower>[a-z])       #  a lowercase letter
  |                       # or
    (?<digit>[0-9])       #  a digit
  |                       # or
    .                     #  anything else
){8,}?                    #REPEATED 8+ times
                          #
                          #CONDITIONS:
(?(upper)                 # 1. There must be at least 1 uppercase
    (?(lower)             #    2. If (1), there must be 1 lowercase
        (?(digit)         #       3. If (2), there must be 1 digit
          | (?!)          #          Else fail
        )                 #
      | (?!)              #       Else fail
    )                     #
  | (?!)                  #    Else fail
)                         #

One-liner:
\A(?>(?<upper>[A-Z])|(?<lower>[a-z])|(?<digit>[0-9])|.){8,}?(?(upper)(?(lower)(?(digit)|(?!))|(?!))|(?!))

regex101 demo


text:
Q: Range in Excel to go from a specific cell to the end of the column I am wondering how to define a range in order for it to be define from C5 until the last value of the column. C5 is a constant but the end of the list isn't.
Sub Merge()
Worksheets("Sub").Range("C5").End(xlToLeft).Select.copy
Worksheets("Master Worksheet").Range("A1:A23").PasteSpecial Paste:=xlPasteValues

End Sub
I am getting a subscript out of range error. Any guidance would be really nice.

A: You don't have to copy and paste special, values. Transfer the values over directly and avoid using the clipboard.
This could probably use one or two variable assignments to clean up the code.
With Worksheets("Sub")
    Worksheets("Master Worksheet").Range("A1") _
      .Resize(.Range(.Cells(5, 3), .Cells(5, Columns.Count).End(xlToLeft)).Columns.Count, 1) = _
      Application.Transpose(.Range(.Cells(5, 3), .Cells(5, Columns.Count).End(xlToLeft)).Value)
End With

*

*The code is a little long because we need to resize the destination in order to receive the values. As mentioned, one or more vars would clean it up tidily.

*When creating a Range(Cells, Cells.End) type cell range reference, MAKE SURE that the Range.Cells property inside the Range object know what their Range .Parent property is. In this case, I've used a With...End With statement and prefixed the .Cells with a period (aka full stop) so that they know that they belong to Worksheets("Sub") .

*Use Application.Transpose to flip the columns of values into rows.

A: You could do: Worksheets("Sub").Range(Cells(5,3),Cells(5,Cells(5,3).End(xltoLeft).column)).Select
This will start at cell C5 (aka Cells(5,3)), and go left.
edit: As Jeeped points out, it might be better to do:
With Worksheets("Sub")
    .Range(.Cells(5,3),.Cells(5,.Cells(5,3).End(xlToLeft).Column)).Select
End With


text:
Q: LM386 with Gain of 40 I am trying to build one of the example circuits in the LM386 datasheet (any of the first 3) but with a gain of 40 rather than 20, 50 or 200.
I understand that the gain is controlled by the impedance between pins 1 and 8 and that a smaller impedance results in a larger gain. So for a gain of 40, the impedance must obviously be more than the 1.2k and 10uF in series.
So apart from trying different values for the resistor, how can I find the required impedance to get a gain of 40?
Also, why is the capacitor necessary? If it's just a question of impedance then can't the capacitor's reactance be replaced by an equivalent resistor?

A: From the circuit diagram and the paragraph Gain control I derive the following two formula's:

With pins 1 and 8 open the 1.35 kΩ resistor sets the gain at 20 (26 dB).

\$G = \dfrac{x}{150Ω + 1350Ω} = 20 \Rightarrow x = 20 \cdot (150Ω+1350Ω) = \boxed{30000}\$

If a capacitor is put from pin 1 to 8, bypassing the 1.35 kΩ resistor, the
  gain will go up to 200 (46 dB).

For AC the capacitor can be neglected in our formula:
\$G = \dfrac{x}{150Ω} = 200 \Rightarrow x = 200 × 150Ω = \boxed{30000}\$
The formula derived from the circuit appears to be correct because for both situations we get the same result.
Now for a Gain of 40:
\$G = \dfrac{30000}{R_p} = 40 \Rightarrow R_p = \dfrac{30000}{40} = \boxed{750Ω}\$
Where Rp is the internal 1350Ω resistor in parallel with the external resistor you need to apply. Again we neglected the series capacitor:
\$R_p = 1350Ω||R_x\$
\$\dfrac{1}{R_p} = \dfrac{1}{R_x} + \dfrac{1}{R_i}\$
\$\dfrac{1}{R_x} = \dfrac{1}{R_p} - \dfrac{1}{R_i}\$
\$\dfrac{1}{R_x} = \dfrac{1}{750Ω} - \dfrac{1}{1350}\$
\$R_x \approx \boxed{ 1688Ω }\$
The nearest E12 value would be 1k5 or 1k8.
Don't forget to include the 10μF series capacitor when you actually build the circuit. Notice that the capacitor makes the circuit's response frequency dependent. A large cap (like the one proposed) will have a fairly low cut off frequency at the low frequency end.

A:
Just to add that the DC quiescent operating point is defined by the 3 circled resistors. This needs to be "left alone" when changing the AC gain hence put a 10uF in series with anything across pins 1 and 8.

A: I noticed in the above for calculating "Now for a gain of 40", the formula left out the 150 Ohm resistor.
I don't know how to type in Mathlab format, but it says
G = 30,000 / Rp
That's a mistake.  It should say
G = 30,000 / (150 + Rp)
Otherwise, shorting pins 1 and 8 would give infinite gain, instead of 200.
The answer for a gain of 40 should give Rp = 600 Ohms (1350 Ohms in parallel with the appropriate resistor), giving an answer of about 1250 Ohms for the resistor needed to set the gain.
Oddly, using this formula with the value given in the datasheet for a gain of 50 (1.2 kOhms) only gives a gain of 38.2.
So, if the datasheet is correct, the gain calculation doesn't quite work, and is not linear.  It gives both end points correctly (gain = 20 or 200), but only approximates points in between.

A: I have just looked up the datasheet and came up with this. Tested it and works correctly as well.
G = (15150 + (1350*R)/(1350+R)) / (150 + (1350*R)/(1350+R)) * 2
R = Resistor in series with a 10uF capacitor between pin 1 and 8
 - pin 1 is positive
G= gain amount i.g. 50 = Output is 50*the input
As far as I know this is the simplest formula as of yet, hope it helps anybody struggling with this issue.


text:
Q: working with span and div to get 2 rows text beside a icon I am working divs and spans to achieve UI as I shown in the image. I am struck with css properties. How can I achieve this with css

this is the sample html

.row .logo {float:left;}
.row .venue {float:right;}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>

O

zeee

2017

MyDate

MyLocation

A: You may use boostrap 4 and enjoy the flex properties :
https://v4-alpha.getbootstrap.com/utilities/flexbox/#justify-content

Justify content
Use justify-content utilities on flexbox containers to change the alignment of flex items on the main axis (the x-axis to start, y-axis if flex-direction: column). Choose from start (browser default), end, center, between, or around.

You can update your class name and turn
 into

/* demo purpose only */
.logo {
  color: green;
  font-size: 40px;
  font-weight: bold;
}

.logo :first-child {
  font-size: .65em;
  color: purple;
  vertical-align: bottom;
}

.logo :last-child {
  font-size: 0.35em;
  word-wrap: break-word;
  width: 1.5em;
  display: inline-block;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<link href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.0.0-alpha.6/css/bootstrap.min.css" rel="stylesheet"/>

    O

zeee

2017

MyDate

MyLocation

codepen and flex to play with

A: Check this:

.row .logo {
  float: left;
}

.row .venue {
  float: right;
}

.fa {
  font-size: 36px !important;
}

#calender {
  float: left;
}

#text {
  float: right;
}

#o {
  font-size: 64px !important;
  color: #07b512;
  display: flex;
  float: left;
}

#zee {
  display: flex;
  float: left;
  color: #3b1670;
  font-weight: bold;
  padding-top: 40%;
  margin-right: 12px;
}

#year {
  display: flex;
  width: 25px;
  color: #8e1b30;
  word-break: break-word;
  font-size: 23px;
  font-weight: bold;
}
.a,.b{
color:blue;
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />

      O

      zeee

      2017

        MyDate

        MyLocation