text:
Q: Which ID do I need to use as Subscriber Key in Marketing Cloud to keep in sync with Service/Sales Cloud? I'm currently about to start an IP warm-up for Marketing Cloud and I have done the following:

*

*Imported my warm-up dataset to Service Cloud (to obtain Contact ID)

*Exported the dataset from Service Cloud with Contact ID

I've now seen this: https://help.salesforce.com/articleView?id=mc_co_subscriber_key.htm&type=5
It appears the recommendation is to not use the 15-digit Contact ID but to use an 18-digit CASESAFEID as the Subscriber Key in Marketing Cloud.
Does this mean I need to re-run my Service Cloud report with the formula to get the extra ID and also, does this mean that when we add contacts to Service Cloud via API calls and retrieve the Contact ID to store in our own database, we'll also need the 18-digit one and not the 15-digit one?

A: General rule is that it should always be the 18-digit ID from Salesforce.
In case you are using Synchronised Data Extensions, Salesforce Report Imports / Sends or Salesforce Campaign Imports / Sends through the UI features, then the default 15-digit ID will be automatically converted to 18-digit ID before it lands in Marketing Cloud.
However if you are exporting a list of ID's in their 15-digit state, then there are actually some validation rules in place in MC that prevent you from uploading these to Marketing Cloud as SubscriberKey's.
The error will be with status code CaseSensitiveSalesforceID.
So if you're ever doing manual exports/imports then you will need to convert the ID's to 18-digit before uploading them to Marketing Cloud. For any built-in Marketing Cloud Connect scenarios, the ID's will be automatically converted.


text:
Q: fetch() delete method in react hooks (with context api) I have problem with delete item from json server. Rigth now I have a component where I stateless func component I generate li's with item from api. In another compinent I have a form, where I can add data. All works fine, till I try to delete items... The idea id to remove item after clicking (the method is on li). The weird part is, that after clicking, nothing is happening, but after refreshing the page clicked item is gone... I've als tried to use filter method, but it didn't help. In this 'app' I'm using context api to manage state.
Code:
import React, { useContext, useEffect } from 'react';
import { MovieContext } from '../contexts/MovieContext';

const MovieList = () => {
  const { movies, setMovie } = useContext(MovieContext);

  const handleDelete = e => {
    const saved = e;
    fetch(
      `http://localhost:3004/movies/${e.target.id}`,
      {
        method: 'DELETE'
      },
      e.persist()
    )
      .then(m => m.json())
      .then(() => movies.filter(movie => movie.id === saved.target.id))
      .then(() => console.log(movies));
  };

  useEffect(() => {
    console.log(movies);
  });

  return (

        {movies.map(movie => (

            {movie.title}

        ))}

  );
};

export default MovieList;

thanks for any help!

A: Array.filter does not modify the original array; it returns a new one with the filtered elements removed. Even if it did, with React, modifying the original array doesn't change the state, you need to call the setter and pass it a new object. So you want to do setMovie(movies.filter(movie => movie.id === saved.target.id))

redpajama_set_name: RedPajamaStackExchange


text:
Q: What is the difference between critical points in calculus and critical points in inequality? In our school textbook there is a chapter called "Linear Inequalities" which states that critical points are those points where the rational fraction is either 0 or undefined.
But "calculus" chapter states that critical points are those points where the derivative of the function is either 0 or undefined.
Please clarify this. This has created a lot of confusion in my mind.

A: The critical points for the derivative of a function are the critical points for the inequality $f'(x) >0$  (or, if you like, $f'(x) <0.$)  For rational functions, you want to know where the graph crosses the $x$-axis.   The critical points for a function in calculus are the points where the derivative crosses the $x$-axis or is undefined.


text:
Q: Animating a Scatter Plot with Respect to Time I currently have an array G = [x,y,t] where each spatial point (G[0][i], G[1][i]) has a time component t = G[2][i]. The array is sorted by time. I am trying to animate the scatter plot so points show up in chronological order and do not disappear. Here is my current code:
from matplotlib.animation import FuncAnimation
import matplotlib.animation as animation

fig = plt.figure(figsize=(10,7))
ax = plt.subplot(111, xlim=(0,1), ylim=(0,1))

def animationUpdate(k):
    x = G[0][:k]
    y = G[1][:k]
    scat.set_offsets(np.c_[x,y])
    return scat

anim = FuncAnimation(fig, animationUpdate, frames=10, interval=100, blit=True)

I get the error "'PathCollection' object is not iterable" which I am not sure how to fix. I am also unsure how to arrange it so the points show up with respect to their time component. Do I modify the frames or interval section of FuncAnimation? Thanks!


text:
Q: Smalltalk Seaside - How do I change the size of a button? I am writing a Smalltalk Seaside app where the resulting HTML pages will be viewed on a laptop/an iPad and/or an iPhone. The size of a standard submit or cancel button is fine on the laptop but way to small on the tablet or the phone. How do I change the size? I have the required style sheets for each type of viewer.
I have little experience in style sheets in Seaside so I have had difficulty getting anywhere with this.
I guess that I need to set a class and a size but not sure how to do this.

A: I don't know which style sheet you are using, but assuming is one of the kind of Bootstrap or Material Design Lite try adding this to your root component on the instance side:
updateRoot: anHtmlRoot

    super updateRoot: anHtmlRoot.
    anHtmlRoot meta
        name: 'viewport';
        content: 'width=device-width, initial-scale=1.0'

This will add the correspoding <meta> tag to the <head> element in your page, producing the following HTML output:
<meta name="viewport" content="width=device-width, initial-scale=1.0">

This will indicate the browser how to scale the contents.
For additional info, see this question: What is initial scale, user-scalable, minimum-scale, maximum-scale attribute in meta tag?


text:
Q: Mongoose how to search array in array I have array with dates. User passes 2 dates: start and stop. I generate array with dates between these dates. Then I have to check in my model if any date from array is in that model. If there's no date (or dates) from array then I want this car, else - i don't want it. How to write whis mongoose query?
I have this model:

const CarSchema = mongoose.Schema({
    mark:{
        type: String,
        required: true,},
    model:{
        type: String,
        required: true,},
    price:{
        type: Number,
        required: true,},
    available: {
        type: Boolean,
        required: true,},
    reserved:{
        type:[Date],

    },
    pic_1:{
        type:String,
        required:true,
    },
    pic_2:{
        type:String,
        required:true,
    },

},
{ collection: 'cars' }
)

Lets suppose user passes 2 dates 12-02-2021 and  16-02-2021. My method generates array with all dates betweeen array = [12-02-2012,13-02-2021,14-02-2021 ... 16-02-2021] in my model i have field reserved  - this is array as well. How to take from database only that cars which field reserved doesn't contains ANY date from array?
Car.find({??what here??});
Thanks in advance!

A: Demo - https://mongoplayground.net/p/HpliQ8Q70uM
Use $nin  for - doesn't contains ANY date from array

$nin selects the documents where:
the field value is not in the specified array or the field does not
exist.

db.collection.find({
  reserved: {
    $nin: [
      "12-02-2021",
      "12-04-2021"
    ]
  }
})

Demo - https://mongoplayground.net/p/ewG_6dQ1UaL
Use $in if you want to match values from array

The $in operator selects the documents where the value of a field equals any value in the specified array.

db.collection.find({
  reserved: {
    $in: [
      "12-02-2021", "12-04-2021"
    ]
  }
})


text:
Q: How create a column that increase according to the value of another column I have a table where I want to put all the information about articles use, and I need to create a column with autoincrement, where the ID can have the same value if the field (tipo) have another value, unique for this particular ID. For example:
ID  /  TIPO
1   /   AJE -- Is Ok
1   /   AJS -- Is Ok (because this Tipo is AJS, different from AJE)
1   /   SI    -- Is Ok
2   /   AJE  -- Is Ok (New ID)
2   /   AJE  -- Is Wrong, because ID=2, TIPO=AJE already exist.

I've done the unique sentence:
ALTER TABLE public.art_movimientos
ADD CONSTRAINT uk_mov UNIQUE (id,tipo) USING INDEX TABLESPACE sistema_index;

But how I can create the autoincrement covering two columns?
My table Code:
CREATE TABLE public.art_movimientos
(
  id integer NOT NULL DEFAULT nextval('seq_art_movimientos'::regclass),
  tipo character(3) NOT NULL, -- Tipos de Valores:...
  documento integer,
  fecha_doc date[] NOT NULL,
  fecha_mov date[] NOT NULL,
  calmacen integer NOT NULL,
  status character(13) NOT NULL DEFAULT 'PENDIENTE'::bpchar, -- PENDIENTE...
  mes integer NOT NULL,
  "año" integer NOT NULL,
  donado integer NOT NULL DEFAULT 0
)
WITH (
  OIDS=FALSE
);

A: You can manage this situation by using an before insert trigger, mimicking the behaviour statedby @dhke:
CREATE TABLE art_movimientos
(
  id integer NOT NULL DEFAULT NULL, -- You don't want a serial, nor a default
  tipo character(3) NOT NULL, -- Tipos de Valores:...
  documento integer,
  fecha_doc date[] NOT NULL,
  fecha_mov date[] NOT NULL,
  calmacen integer NOT NULL,
  status character(13) NOT NULL DEFAULT 'PENDIENTE'::bpchar, -- PENDIENTE...
  mes integer NOT NULL,
  "año" integer NOT NULL,
  donado integer NOT NULL DEFAULT 0,

  /* You have actually a 2-column Primary Key */
  PRIMARY KEY (tipo, id)

);
-- Create a trigger function to generate 'id'
CREATE FUNCTION art_movimientos_insert_trigger()
    RETURNS trigger
AS
$$
BEGIN
    /* Compute "id", as the following id for a certain "tipo" */
    new.id = coalesce(
                  (SELECT max(id) + 1
                     FROM art_movimientos a
                    WHERE a.tipo = new.tipo), 1);
    return new;
END
$$
    LANGUAGE 'plpgsql'
    VOLATILE ;

-- This trigger will be called whenever a new row is inserted, and "id" is
-- not specified (i.e.: it defaults to null), or is specified as null
CREATE TRIGGER art_movimientos_ins_trg
    BEFORE INSERT
    ON art_movimientos
    FOR EACH ROW
    WHEN (new.id IS NULL)
    EXECUTE PROCEDURE art_movimientos_insert_trigger();

You can then insert the following rows (without specifying the id column):
INSERT INTO art_movimientos
   (tipo, documento, fecha_doc, fecha_mov, calmacen, mes, "año")
VALUES
   ('AJE', 1, array['20170128'::date], array['20170128'::date], 1, 1, 2017),
   ('AJS', 2, array['20170128'::date], array['20170128'::date], 1, 1, 2017),
   ('SI',  3, array['20170128'::date], array['20170128'::date], 1, 1, 2017),
   ('AJE', 4, array['20170128'::date], array['20170128'::date], 1, 1, 2017),
   ('AJE', 5, array['20170128'::date], array['20170128'::date], 1, 1, 2017) ;

... and see that you get what you intended:
SELECT
    id, tipo
FROM
    art_movimientos
ORDER BY
    documento ;

| id | tipo |
|----|------|
|  1 |  AJE |
|  1 |  AJS |
|  1 |  SI  |
|  2 |  AJE |
|  3 |  AJE |

You can check everything a SQLFiddle  (which is a bit picky about PL/pgSQL functions and semicolons).

Side note: There can be a few corner cases where this procedure might fail within a transaction because of deadlocks and/or race conditions, if other transactions are also inserting data into the same table at the same time. So, your overall code should be able to handle aborted transactions, and retry them or show an error to the user.


text:
Q: Click while element isEnabled in protractor I have to click a right arrow button while is enabled on the page.
This is my code:
var sig = element(by.id('#right_button'));
sig.isEnabled().then(function (result) {
    while (result) {
        sig.click();
        return sig;
    }
}

It only clicks two times, and I need clicking while element is enabled. How can I do?

A: Solved this way:
    var sig = element(by.id('#right_button'));
    reclick = function (sig) {
        sig.isEnabled().then(function (result) {

            while (result) {
                sig.click();
                return reclick(sig);
            }

        });
    };
    reclick(sig);

A: Make sure that your element is on the DOM even before you start executing the loop as the loops get executed much more faster than we think. Probably waiting for an element to load before clicking on it should do the trick. Or instead using function calls, is the best approach to it. Here's how you can do it -
var EC = protractor.ExpectedConditions;
var sig = element(by.id('#right_button'));

(function clickIt(){
  browser.wait(EC.presenceOf(sig), 2000).then(function(){
    sig.isEnabled().then(function (enabled) {
        if(enabled){
            sig.click().then(function(){
              clickIt.call();
            });
        }
    });
    });
})();

Hope it helps.


text:
Q: a Textfiled does not use functions on props Doesn't a TextField recognise functions of props?
This is a class component that takes a prop.
the prop includes a function. it is recognised out of text field. However
When it in Textfield , "onChange" and onClick are unable to find textInput: (text: string).
export type props = {
    kind: 'Test'
    textInput: (text: string) => void
}

export class KlassComponent extends Component<props, {}> {

    render() {
        switch (this.props.kind) {
            case 'Test':
                return (
                    <TextField
                onChange = { (e) => this.props.textInput(e.target.value)
                    />
        }
    }
}

Property 'textInput' does not exist on type '(Readonly<{ kind: "Test";

A: First of all, you have an error in the onChange o the <TextField /> because you are missing a } closing bracket, then you'll have to check if you are getting the textInput prop (If not, you're setting the default value that won't handle your event).
export type props = {
    kind: 'Test'
    textInput: (text: string) => void
}

export class KlassComponent extends Component<props, {}> {
    const { kind, textInput } = this.props;

    render() {
        switch (.kind) {
            case 'Test':
                return (
                    <TextField
                      onChange={e => textInput(e.target.value)}
                    />
        }
    }
}


text:
Q: Simulating the significance level of a t-test in R The following code generates 10000 t-tests on a custom distribution I have created.
> x <- replicate(10000,{
  t.test(rcn(20,.25,25), mu=0, alternative="greater")
  })

I am constructing an empirical level of significance and so I am interested in the number of test-statistics that are greather than the critical value of the respective t-distribution, which is 1.729 (for a t-distribution with 19 degrees of freedom).
How can I select (and count) these test-statistics here? The ratio of their number over 10000, the total number of simulations, will give me my empirical level of significance.

A: You can directly access the test statistic of each t.test in replicate. For example:
x <- replicate(10000, {
 t.test(rcn(20,.25,25), mu=0, alternative="greater")$statistic
})

This returns a vector of t-values.
You can compare it with your critical value and count the TRUEs:
crit <- 1.729
sum(x > crit)


text:
Q: Problem with using Selenium to load a page and scraping information I'm trying to scrape the top 200 artists from https://www.rollingstone.com/charts/artists/ but after successfully loading all 200 artists through Selenium using the .click() to click on the "load more" button and .implicitly_wait() functions, and inserting them in my DB I only get the top 50 artists.
driver.find_element_by_css_selector(code).click() and driver.implicitly_wait(10) code
The first place artist has a different css selector so I collected the rest of the artist through this code
the_rest = soup.select( '#site_wrap > div.l-page__content.l-page__charts.l-page__charts--single.l-page__charts--artists > div.l-section.l-section__charts--single > div.c-content.c-content--charts > section.l-section__charts--grid > section.l-section__charts.c-chart__table--single')
And then I used this for loop to insert the artists
for rest in the_rest:
    rest_ranking = rest.select_one(
        'div.c-chart__table--top > div.c-chart__table--rank').text
    # while rest_ranking <= '200':
    rest_img = rest.select_one('div.c-chart__table--top > img')['src']
    rest_name = rest.select_one('div.c-chart__table--top > div.c-chart__table--details > div').text
    doc = {
        'name': rest_name,
        'img_url': rest_img,
        'lyrics': [],
        'probability': 0
    }
    db.selen_top200.insert_one(doc)

But it only inserts the top 50 artists in my database.
Is there a problem with the way I click on the "load more" button using Selenium or is it the way I all "the rest" of the artists?

A: I try to click load more button with this selector div.load-more-link span with .execute_script(...) using a loop.
Following import first:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

Try following code to get rank, name and image source:
driver.get('https://www.rollingstone.com/charts/artists/')

target_artis = 200
list_artist = []
while True:
    if(len(driver.find_elements_by_css_selector('div.load-more-link span')) >0):
        load_more = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.load-more-link span')))
        driver.execute_script("arguments[0].click()", load_more)

    list_artist = WebDriverWait(driver, 20).until(EC.visibility_of_all_elements_located((By.CSS_SELECTOR, '.l-section__charts')))
    if(len(list_artist)>=target_artis):
        break

print(len(list_artist))

list_rest_ranking = []
list_rest_img = []
list_rest_name = []

for x in range(target_artis):
    list_rest_ranking.append(driver.find_elements_by_css_selector('div.c-chart__table--rank')[x].text)
    list_rest_img.append(driver.find_elements_by_css_selector('img.c-chart__table--cover')[x].get_attribute('src'))
    list_rest_name.append(driver.find_elements_by_css_selector('div.c-chart__table--title p')[x].text)

print(list_rest_ranking)
print(list_rest_img)
print(list_rest_name)

Console output:
[u'1', u'2', u'3', u'4', u'5', u'6', u'7', u'8', u'9', u'10', u'11', u'12', u'13', u'14', u'15', u'16', u'17', u'18', u'19', u'20', u'21', u'22', u'23', u'24', u'25', u'26', u'27', u'28', u'29', u'30', u'31', u'32', u'33', u'34', u'35', u'36', u'37', u'38', u'39', u'40', u'41', u'42', u'43', u'44', u'45', u'46', u'47', u'48', u'49', u'50', u'51', u'52', u'53', u'54', u'55', u'56', u'57', u'58', u'59', u'60', u'61', u'62', u'63', u'64', u'65', u'66', u'67', u'68', u'69', u'70', u'71', u'72', u'73', u'74', u'75', u'76', u'77', u'78', u'79', u'80', u'81', u'82', u'83', u'84', u'85', u'86', u'87', u'88', u'89', u'90', u'91', u'92', u'93', u'94', u'95', u'96', u'97', u'98', u'99', u'100', u'101', u'102', u'103', u'104', u'105', u'106', u'107', u'108', u'109', u'110', u'111', u'112', u'113', u'114', u'115', u'116', u'117', u'118', u'119', u'120', u'121', u'122', u'123', u'124', u'125', u'126', u'127', u'128', u'129', u'130', u'131', u'132', u'133', u'134', u'135', u'136', u'137', u'138', u'139', u'140', u'141', u'142', u'143', u'144', u'145', u'146', u'147', u'148', u'149', u'150', u'151', u'152', u'153', u'154', u'155', u'156', u'157', u'158', u'159', u'160', u'161', u'162', u'163', u'164', u'165', u'166', u'167', u'168', u'169', u'170', u'171', u'172', u'173', u'174', u'175', u'176', u'177', u'178', u'179', u'180', u'181', u'182', u'183', u'184', u'185', u'186', u'187', u'188', u'189', u'190', u'191', u'192', u'193', u'194', u'195', u'196', u'197', u'198', u'199', u'200']
[u'https://api.buzzanglemusic.com/images/artists/1374', u'https://api.buzzanglemusic.com/images/artists/1075289', u'https://api.buzzanglemusic.com/images/artists/2543301', u'https://api.buzzanglemusic.com/images/artists/4384780', u'https://api.buzzanglemusic.com/images/artists/4609765', u'https://api.buzzanglemusic.com/images/artists/5562543', u'https://api.buzzanglemusic.com/images/artists/1347', u'https://api.buzzanglemusic.com/images/artists/1350', u'https://api.buzzanglemusic.com/images/artists/6762453', u'https://api.buzzanglemusic.com/images/artists/1151925', u'https://api.buzzanglemusic.com/images/artists/1598398', u'https://api.buzzanglemusic.com/images/artists/6273541', u'https://api.buzzanglemusic.com/images/artists/197', u'https://api.buzzanglemusic.com/images/artists/4', u'https://api.buzzanglemusic.com/images/artists/6240779', u'https://api.buzzanglemusic.com/images/artists/10996', u'https://api.buzzanglemusic.com/images/artists/5019556', u'https://api.buzzanglemusic.com/images/artists/5330407', u'https://api.buzzanglemusic.com/images/artists/4878653', u'https://api.buzzanglemusic.com/images/artists/6462708', u'https://api.buzzanglemusic.com/images/artists/7501280', u'https://api.buzzanglemusic.com/images/artists/1340', u'https://api.buzzanglemusic.com/images/artists/931', u'https://api.buzzanglemusic.com/images/artists/4034234', u'https://api.buzzanglemusic.com/images/artists/4893654', u'https://api.buzzanglemusic.com/images/artists/6218616', u'https://api.buzzanglemusic.com/images/artists/3105901', u'https://api.buzzanglemusic.com/images/artists/5764159', u'https://api.buzzanglemusic.com/images/artists/1344', u'https://api.buzzanglemusic.com/images/artists/1380', u'https://api.buzzanglemusic.com/images/artists/202', u'https://api.buzzanglemusic.com/images/artists/162', u'https://api.buzzanglemusic.com/images/artists/804921', u'https://api.buzzanglemusic.com/images/artists/1345', u'https://api.buzzanglemusic.com/images/artists/19621', u'https://api.buzzanglemusic.com/images/artists/808927', u'https://api.buzzanglemusic.com/images/artists/223', u'https://api.buzzanglemusic.com/images/artists/1514', u'https://api.buzzanglemusic.com/images/artists/7', u'https://api.buzzanglemusic.com/images/artists/21', u'https://api.buzzanglemusic.com/images/artists/590329', u'https://api.buzzanglemusic.com/images/artists/7466212', u'https://api.buzzanglemusic.com/images/artists/263', u'https://api.buzzanglemusic.com/images/artists/594558', u'https://api.buzzanglemusic.com/images/artists/7520899', u'https://api.buzzanglemusic.com/images/artists/4529544', u'https://api.buzzanglemusic.com/images/artists/4304221', u'https://api.buzzanglemusic.com/images/artists/26', u'https://api.buzzanglemusic.com/images/artists/208', u'https://api.buzzanglemusic.com/images/artists/33', u'https://api.buzzanglemusic.com/images/artists/1079180', u'https://api.buzzanglemusic.com/images/artists/3305532', u'https://api.buzzanglemusic.com/images/artists/580367', u'https://api.buzzanglemusic.com/images/artists/54', u'https://api.buzzanglemusic.com/images/artists/4694249', u'https://api.buzzanglemusic.com/images/artists/1545', u'https://api.buzzanglemusic.com/images/artists/3391309', u'https://api.buzzanglemusic.com/images/artists/489706', u'https://api.buzzanglemusic.com/images/artists/185', u'https://api.buzzanglemusic.com/images/artists/812522', u'https://api.buzzanglemusic.com/images/artists/5681847', u'https://api.buzzanglemusic.com/images/artists/3195987', u'https://api.buzzanglemusic.com/images/artists/4179629', u'https://api.buzzanglemusic.com/images/artists/5212303', u'https://api.buzzanglemusic.com/images/artists/142', u'https://api.buzzanglemusic.com/images/artists/6384381', u'https://api.buzzanglemusic.com/images/artists/812157', u'https://api.buzzanglemusic.com/images/artists/192', u'https://api.buzzanglemusic.com/images/artists/692', u'https://api.buzzanglemusic.com/images/artists/1256797', u'https://api.buzzanglemusic.com/images/artists/5984690', u'https://api.buzzanglemusic.com/images/artists/5344432', u'https://api.buzzanglemusic.com/images/artists/2381', u'https://api.buzzanglemusic.com/images/artists/1338', u'https://api.buzzanglemusic.com/images/artists/28', u'https://api.buzzanglemusic.com/images/artists/6500275', u'https://api.buzzanglemusic.com/images/artists/4754086', u'https://api.buzzanglemusic.com/images/artists/189', u'https://api.buzzanglemusic.com/images/artists/715', u'https://api.buzzanglemusic.com/images/artists/11', u'https://api.buzzanglemusic.com/images/artists/690440', u'https://api.buzzanglemusic.com/images/artists/722962', u'https://api.buzzanglemusic.com/images/artists/6478745', u'https://api.buzzanglemusic.com/images/artists/1626', u'https://api.buzzanglemusic.com/images/artists/150', u'https://api.buzzanglemusic.com/images/artists/1356', u'https://api.buzzanglemusic.com/images/artists/221', u'https://api.buzzanglemusic.com/images/artists/6216355', u'https://api.buzzanglemusic.com/images/artists/5366988', u'https://api.buzzanglemusic.com/images/artists/771', u'https://api.buzzanglemusic.com/images/artists/610595', u'https://api.buzzanglemusic.com/images/artists/247467', u'https://api.buzzanglemusic.com/images/artists/5215781', u'https://api.buzzanglemusic.com/images/artists/7640', u'https://api.buzzanglemusic.com/images/artists/621107', u'https://api.buzzanglemusic.com/images/artists/4547105', u'https://api.buzzanglemusic.com/images/artists/143', u'https://api.buzzanglemusic.com/images/artists/4827213', u'https://api.buzzanglemusic.com/images/artists/769', u'https://api.buzzanglemusic.com/images/artists/1337', u'https://api.buzzanglemusic.com/images/artists/487', u'https://api.buzzanglemusic.com/images/artists/2643', u'https://api.buzzanglemusic.com/images/artists/8957464', u'https://api.buzzanglemusic.com/images/artists/807069', u'https://api.buzzanglemusic.com/images/artists/517460', u'https://api.buzzanglemusic.com/images/artists/662', u'https://api.buzzanglemusic.com/images/artists/6227591', u'https://api.buzzanglemusic.com/images/artists/330', u'https://api.buzzanglemusic.com/images/artists/2419669', u'https://api.buzzanglemusic.com/images/artists/7299117', u'https://api.buzzanglemusic.com/images/artists/630', u'https://api.buzzanglemusic.com/images/artists/38', u'https://api.buzzanglemusic.com/images/artists/743', u'https://api.buzzanglemusic.com/images/artists/295165', u'https://api.buzzanglemusic.com/images/artists/474', u'https://api.buzzanglemusic.com/images/artists/5085902', u'https://api.buzzanglemusic.com/images/artists/5433623', u'https://api.buzzanglemusic.com/images/artists/15510', u'https://api.buzzanglemusic.com/images/artists/1390', u'https://api.buzzanglemusic.com/images/artists/596038', u'https://api.buzzanglemusic.com/images/artists/465', u'https://api.buzzanglemusic.com/images/artists/503490', u'https://api.buzzanglemusic.com/images/artists/82', u'https://api.buzzanglemusic.com/images/artists/6427308', u'https://api.buzzanglemusic.com/images/artists/199', u'https://api.buzzanglemusic.com/images/artists/7144', u'https://api.buzzanglemusic.com/images/artists/44528', u'https://api.buzzanglemusic.com/images/artists/490', u'https://api.buzzanglemusic.com/images/artists/830802', u'https://api.buzzanglemusic.com/images/artists/178', u'https://api.buzzanglemusic.com/images/artists/20931', u'https://api.buzzanglemusic.com/images/artists/78', u'https://api.buzzanglemusic.com/images/artists/2599', u'https://api.buzzanglemusic.com/images/artists/31865', u'https://api.buzzanglemusic.com/images/artists/755031', u'https://api.buzzanglemusic.com/images/artists/5009248', u'https://api.buzzanglemusic.com/images/artists/7177348', u'https://api.buzzanglemusic.com/images/artists/9046744', u'https://api.buzzanglemusic.com/images/artists/472', u'https://api.buzzanglemusic.com/images/artists/6816051', u'https://api.buzzanglemusic.com/images/artists/603486', u'https://api.buzzanglemusic.com/images/artists/9518002', u'https://api.buzzanglemusic.com/images/artists/856682', u'https://api.buzzanglemusic.com/images/artists/3883529', u'https://api.buzzanglemusic.com/images/artists/173', u'https://api.buzzanglemusic.com/images/artists/236', u'https://api.buzzanglemusic.com/images/artists/225', u'https://api.buzzanglemusic.com/images/artists/4779775', u'https://api.buzzanglemusic.com/images/artists/723917', u'https://api.buzzanglemusic.com/images/artists/1823', u'https://api.buzzanglemusic.com/images/artists/881', u'https://api.buzzanglemusic.com/images/artists/7296610', u'https://api.buzzanglemusic.com/images/artists/3587186', u'https://api.buzzanglemusic.com/images/artists/678', u'https://api.buzzanglemusic.com/images/artists/866831', u'https://api.buzzanglemusic.com/images/artists/4231', u'https://api.buzzanglemusic.com/images/artists/218', u'https://api.buzzanglemusic.com/images/artists/22', u'https://api.buzzanglemusic.com/images/artists/1339', u'https://api.buzzanglemusic.com/images/artists/1352', u'https://api.buzzanglemusic.com/images/artists/181', u'https://api.buzzanglemusic.com/images/artists/806032', u'https://api.buzzanglemusic.com/images/artists/1364', u'https://api.buzzanglemusic.com/images/artists/2611', u'https://api.buzzanglemusic.com/images/artists/828', u'https://api.buzzanglemusic.com/images/artists/885', u'https://api.buzzanglemusic.com/images/artists/36569', u'https://api.buzzanglemusic.com/images/artists/4466817', u'https://api.buzzanglemusic.com/images/artists/13', u'https://api.buzzanglemusic.com/images/artists/227', u'https://api.buzzanglemusic.com/images/artists/2506', u'https://api.buzzanglemusic.com/images/artists/730102', u'https://api.buzzanglemusic.com/images/artists/9284021', u'https://api.buzzanglemusic.com/images/artists/9371339', u'https://api.buzzanglemusic.com/images/artists/164', u'https://api.buzzanglemusic.com/images/artists/1336', u'https://api.buzzanglemusic.com/images/artists/5722286', u'https://api.buzzanglemusic.com/images/artists/4351620', u'https://api.buzzanglemusic.com/images/artists/166', u'https://api.buzzanglemusic.com/images/artists/148', u'https://api.buzzanglemusic.com/images/artists/680', u'https://api.buzzanglemusic.com/images/artists/5880', u'https://api.buzzanglemusic.com/images/artists/335779', u'https://api.buzzanglemusic.com/images/artists/184', u'https://api.buzzanglemusic.com/images/artists/4375959', u'https://api.buzzanglemusic.com/images/artists/646', u'https://api.buzzanglemusic.com/images/artists/289', u'https://api.buzzanglemusic.com/images/artists/502', u'https://api.buzzanglemusic.com/images/artists/596334', u'https://api.buzzanglemusic.com/images/artists/4786404', u'https://api.buzzanglemusic.com/images/artists/224', u'https://api.buzzanglemusic.com/images/artists/379', u'https://api.buzzanglemusic.com/images/artists/29', u'https://api.buzzanglemusic.com/images/artists/9224269', u'https://api.buzzanglemusic.com/images/artists/6221', u'https://api.buzzanglemusic.com/images/artists/590503', u'https://api.buzzanglemusic.com/images/artists/804250', u'https://api.buzzanglemusic.com/images/artists/322', u'https://api.buzzanglemusic.com/images/artists/89', u'https://api.buzzanglemusic.com/images/artists/6944241']
[u'Drake', u'Lil Baby', u'DaBaby', u'Post Malone', u'Lil Uzi Vert', u'YoungBoy Never Broke Again', u'Future', u'The Weeknd', u'Juice Wrld', u'Gunna', u'Luke Combs', u'Polo G', u'Eminem', u'Taylor Swift', u'Rod Wave', u'Travis Scott', u'Xxxtentacion', u'Bad Bunny', u'Billie Eilish', u'Roddy Ricch', u'Pop Smoke', u'Kanye West', u'The Beatles', u'Harry Styles', u'A Boogie wit da Hoodie', u'Megan Thee Stallion', u'Morgan Wallen', u'Trippie Redd', u'Lil Wayne', u'J. Cole', u'Lady Gaga', u'Chris Brown', u'Kevin Gates', u'Kendrick Lamar', u'Ariana Grande', u'Khalid', u'Ed Sheeran', u'Mac Miller', u'Jason Aldean', u'Luke Bryan', u'Jhen\xe9 Aiko', u'NLE Choppa', u'Justin Bieber', u'Lil Durk', u'Iann Dior', u'Moneybagg Yo', u'Kodak Black', u'Florida Georgia Line', u'Beyonc\xe9', u'Kenny Chesney', u'Tory Lanez', u'Doja Cat', u'Young Thug', u'Thomas Rhett', u'Dua Lipa', u'Meek Mill', u'Kehlani', u'Sam Hunt', u'Rihanna', u'BTS', u'Lil Peep', u'NF', u'Kane Brown', u'Chloe x Halle', u'Maroon 5', u'YNW Melly', u'Migos', u'Imagine Dragons', u'Queen', u'Halsey', u'Lewis Capaldi', u'$uicideboy$', u'twenty one pilots', u'Frank Ocean', u'Blake Shelton', u'Lil Mosey', u'G Herbo', u'One Direction', u'Fleetwood Mac', u'Zac Brown Band', u'Maren Morris', u'Nav', u'Don Toliver', u'Panic! at the Disco', u'Bruno Mars', u'2Pac', u'Nicki Minaj', u'6IX9INE', u'SAINt JHN', u'Eagles', u'George Strait', u'Chris Stapleton', u'Russ', u'Tyler, The Creator', u'Eric Church', u'Anuel AA', u'Katy Perry', u'Jack Harlow', u'Elton John', u'Wiz Khalifa', u'AC/DC', u'Jonas Brothers', u'Lil Baby, 42 Dugg', u'Blackbear', u'H.E.R', u'Michael Jackson', u'Lil Skies', u'Red Hot Chili Peppers', u'Bazzi', u'Lil Tjay', u'The Rolling Stones', u'Tim McGraw', u'Tom Petty And The Heartbreakers', u'Summer Walker', u'Led Zeppelin', u'Playboi Carti', u'Surfaces', u'Childish Gambino', u'Gucci Mane', u'Melanie Martinez', u'Five Finger Death Punch', u'Old Dominion', u'Miranda Lambert', u'JayDaYoungan', u'Linkin Park', u'Nipsey Hussle', u'Coldplay', u'Metallica', u'Dan + Shay', u'John Mayer', u'Sam Smith', u'Jon Pardi', u'Kid Cudi', u'Logic', u'5 Seconds of Summer', u'Lil Yachty', u'Natanael Cano', u'StaySolidRocky', u'Pink Floyd', u'Lil Tecca', u'Brett Young', u'6Ix9Ine & Nicki Minaj', u'Tyler Childers', u'Ozuna', u'Adele', u'Jack Johnson', u'Usher', u'21 Savage', u'Lizzo', u'Machine Gun Kelly', u'Bob Marley & The Wailers', u'Sleepy hallow', u'Shawn Mendes', u'Billy Joel', u'Run The Jewels', u'YG', u'Green Day', u'Carrie Underwood', u'Trey Songz', u'A$AP Rocky', u'JAY-Z', u'G-Eazy', u'Notorious B.I.G.', u'Selena Gomez', u'Fall Out Boy', u'Creedence Clearwater Revival', u'Camila Cabello', u'Joji', u'Keith Urban', u'Demi Lovato', u'Frank Sinatra', u'Chance the Rapper', u'Chris Brown & Young Thug', u'Lady Gaga, Ariana Grande', u'Lana Del Rey', u'DJ Khaled', u'Key Glock', u'Brent Faiyaz', u'The Lumineers', u'Pink', u'Journey', u'Tame Impala', u'Jordan Davis', u'OneRepublic', u'YFN Lucci', u'Lynyrd Skynyrd', u'Sublime', u'Nirvana', u'The Chainsmokers', u'Cardi B', u'Calvin Harris', u'Johnny Cash', u'Lee Brice', u'Travis Scott, The Scotts, Kid Cudi', u'Alan Jackson', u'J. Balvin', u'PARTYNEXTDOOR', u'50 Cent', u'Garth Brooks', u'Powfu']


text:
Q: Autowire Spring bean implementing two interfaces Is it possible to have a Spring Bean implement 2 interfaces and be able to autowire that bean using either interface?
I have the following two interfaces:
public interface ServiceA {}

public interface ServiceB {}

Two controllers which use constructor auto-wiring to inject a different service:
@RestController
public class ControllerA {

    public ControllerA(ServiceA service) {}

}

@RestController
public class ControllerB {

    public ControllerB(ServiceB service) {}

}

One class that implements both the services
@Service
public class ServiceImpl implements ServiceA, ServiceB { }

I am getting a NoSuchBeanDefinitionException:

Caused by: org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [ServiceB] found for dependency [ServiceB]: expected at least 1 bean which qualifies as autowire candidate for this dependency. Dependency annotations: {}

I'm using Spring Boot version 1.4.0

A: Yes it is possible, but
it is important, to create the service bean of type ServiceImpl and not as one of the service interfaces :
@Bean
ServiceImpl service() {
    return new Serviceimpl();
}

Spring uses reflection on the declared bean type to find out which interfaces it implements and not on bean.getClass().
Even if this answer was voted dowen, you can be asured : it works . If it does not work for you @scarba05, your problem must be somewhere else...

A: You could use the @Qualifier annotation. It can be applied alongside @Autowired or @Inject at the point of injection to specify which bean you want to be injected:
@Autowired
@Qualifier("iceCream")
public void setDessert(Dessert dessert) {
    this.dessert = dessert;
}

Source: Spring in Action 4th edition.

A: Let me answer your questions one by one:

*

*Yes you can implement more than one interface in any spring bean.

*Yes you can autowire with interface too as you did by constructor.

Your shared code working fine just check your SpringBootConfiguration class I think you are not scanning you service package or your service class is not in child package of SpringBootConfiguration class.
That's why you are facing:

NoSuchBeanDefinitionException


text:
Q: How to use chain rule on it? Let $M$ be a surface in $\mathbb{R}^3$ oriented by $\vec n$. For a fixed number $\varepsilon\neq0$, let $F:M\to\mathbb{R}^3$ be a mapping such that $F(p)=p+\varepsilon\vec n(p)$ and denote $\overline{M}=F(M)$. Knowing $\vec{x}(u,v)$ a parametrization of $M$, so we know parametrization $\vec{y}(u,v)$ of $\overline{M}$ is $\vec{y}(u,v)$=$\vec{x}(u,v)+\varepsilon\vec{n}(\vec{x}(u,v))$.

Now there is a question:Use E(of $\vec{x}(u,v)$)(by fist fundamental forms)to represent $\overline{E}$ of $\vec{y}(u,v)$.

I don't know how to use chain rule on it.
Thanks. Please help me.


text:
Q: Guaranteed precision of sqrt function in C/C++ Everyone knows sqrt function from math.h/cmath in C/C++ - it returns square root of its argument. Of course, it has to do it with some error, because not every number can be stored precisely. But am I guaranteed that the result has some precision? For example, 'it's the best approximation of square root that can be represented in the floating point type usedorif you calculate square of the result, it will be as close to initial argument as possible using the floating point type given`?
Does C/C++ standard have something about it?

A: For C99, there are no specific requirements. But most implementations try to support Annex F: IEC 60559 floating-point arithmetic as good as possible. It says:

An implementation that defines __STDC_IEC_559__ shall conform to the specifications in this annex.

And:

The sqrt functions in <math.h> provide the IEC 60559 square root operation.

IEC 60559 (equivalent to IEEE 754) says about basic operations like sqrt:

Except for binary <-> decimal conversion, each of the operations shall be performed as if it first produced an intermediate result correct to infinite precision and with unbounded range, and then coerced this intermediate result to fit in the destination's format.

The final step consists of rounding according to several rounding modes but the result must always be the closest representable value in the target precision.

A: This question was already answered here as Chris Dodd noticed in the comments section. In short: it's not guaranteed by C++ standard, but IEEE-754 standard guarantees me that the result will be as close to the 'real result' as possible, i.e. error will be less than or equal to 1/2 unit-in-the-last-place. In particular, if the result can be precisely stored, it should be.


text:
Q: Font differences in tkinter & matplotlib I am using Tkinter for a GUI in which is also show Matplotlib graphs. I am trying to align the way how text looks between Tkinter (e.g. Label) and Matplotlib (e.g. graph title, axis labels). To try it out I have set both to Arial with the following commands:
import matplotlib
import ttkbootstrap as ttk

matplotlib.rcParams.update({"font.family": "Arial"}) # Matplotlib
defaultFont = ttk.font.nametofont('TkDefaultFont') # Tkinter (more specifically Ttk Bootstrap)
defaultFont.configure(family = 'Arial')

However, it seems like the font is somewhat 'bolder' for Tkinter (although its not set to bold or anything. You can see that in screenshot below, where upper text is a Tkinter Label and below is the title of a Matplotlib graph. Any idea why I am seeing this difference? I would really want to 1:1 use the same font face everywhere.


text:
Q: Explanation of why the height of a binary tree $\theta(\lg n)$. From Heap Sort chapter of Introduction to algorithms :

Since a heap of $n$ elements is based on a complete binary tree , its
  height is $\theta(\lg n)$.

I know this is correct but how can this be proved ?

A: Using induction one can prove that a full binary tree of height $h$ has $2^h-1$ elements. So you have $n=2^h-1$, i.e. $h=\lg (n+1)=\theta(\lg n)$.

A: If we write down the series counting the number of elements at each level of the tree, then we get
$$ \mbox{Number of elements} = n = 1 + 2 + 4 + 8 + ... + k \tag{1}$$
That is, at the first level, there is only one node, the root of the tree. At the second level are the root's two children. At the third, each of those two children's two children (making the total four at the third level). And so on until the last level, in which there are $k$ leaves of the tree.
$n$ is a finite geometric series whose first element is $a = 1$, ratio is $r = 2$. Using the formula for a geometric series, we get:
$$ n = \frac{a(1 - r^i)}{1 - r} = 2^i - 1 $$
We seek $i$, which is the number of elements in the sequence given by $(1)$:
$$ n = 2^i - 1 \Rightarrow  i = \lceil\lg(n + 1)\rceil $$
This means there are $\lceil\lg(n + 1)\rceil$ levels in the tree, or $\lceil\lg(n + 1)\rceil$ terms in the series in $(1)$. The ceiling is required because nodes taking up part of a level warrant an extra count to the number of levels. We're interested in the height of the tree, not the number of levels. A keen observation will reveal that the height $h$ of a complete binary tree is one less than the number of levels. In other words, the height is the number of plus signs in $(1)$. So the height $h$ of a complete binary tree in terms of its $n$ elements is
$$ h(n) = \lceil\lg(n + 1)\rceil - 1 \tag{2}$$
To show that $h(n) \in \Theta(\lg(n))$, first note the ceiling function will not affect the asymptotic behavior of $h(n)$, so the rounding up will be ignored for the rest of the discussion.
$h(n)$ is in $\Theta(\lg(n))$ if
$$ \exists n_0 \in \mathbb{N},\; c_1, c_2 \in \mathbb{R},\; c_1, c_2 > 0 : c_1 \lg(n) \le \lg(n + 1) - 1 \le c_2 \lg(n), \quad \forall n \ge n_0 \tag{3}$$
For the lower bound, let $c_1 = \frac{1}{2}$. Then we have:
$$\frac{1}{2}\lg(n) = \lg(\sqrt{n}) \le \lg(n + 1) - 1, \quad \forall n \ge 1 \tag{4}$$
In $(4)$, $n_0 = 1$.
For the upper bound, let $c_2 = 2$. We have:
$$2\lg(n) = \lg(n^2) \ge \lg(n + 1) - 1, \quad \forall n \ge 1 \tag{5}$$
where $n_0 = 1$ here too.
So, for $c_1 = \frac{1}{2}$, $c_2 = 2$, and $n_0 = 1$, $(3)$ holds. Therefore
$h(n) \in \Theta(\lg(n))$.


text:
Q: Creating a sticky note with JavaScript and jQuery I'm trying to build a sticky note with Javascript and jQuery. The problem I am having is, that the functions draggable() and deleteNote() can not be called on the newly appended elements. How can I fix this?
EDIT: The ID actually should get an added number, which I'm not sure how to implement, because I don't know how to create a counter. E.g. newbox1
My code on jsfiddle: http://jsfiddle.net/wowpatrick/qexRS/4/

A: You could add the .click handlers to the new element after you create it.

A: You shouldn't create multiple elements with the same ID, use class instead.
Also, you can attach the .draggable() to the created element right away instead of targeting $('#newbox').
Here is a fork that works better: http://jsfiddle.net/YvtLb/
The key is here:
var postit = $('
Delete comment
Your comment:
<textarea></textarea>
').draggable();
$('#canvas').append(postit);

A: You need to attach the eventhandlers live, since there are no elements existent at the moment you initially called them.
Use jQuerys live() (Attention:deprecated Docu) or with new jQuery-version on() (Docu), to be able to attach the events on each newly created note.
Also don't use IDs, since this produces invalid markup because IDs always have to be unique. Use classes instead.

A: This is because on page load #newbox does not exist. A better method would be to store your new element in a variable, append it, then apply draggable, try this:
// Create the new comment at the corsor postition
var $newbox = $('
Delete comment
Your comment:
<textarea></textarea>
');
$('#canvas').append($newbox);
$newbox.draggable();

Example fiddle


text:
Q: How to solve this estimate $m\{t \in[a, b]:|f(t)| \leq \varepsilon\} \leq 4\left(q ! \frac{\varepsilon}{2 \beta}\right)^{\frac{1}{q}}$
*

*(a) Assume that the function $f:[a, b] \rightarrow \mathcal{R}$ with $a<b$ is differentiable and satisfies $\left|f^{\prime}(t)\right| \geq \beta$ for all $t \in[a, b]$ for some $\beta>0 .$ Prove the following estimate
$$
m\{t \in[a, b]:|f(t)| \leq \varepsilon\} \leq \frac{2 \varepsilon}{\beta} \quad \text { for } \varepsilon>0
$$
where $m\{B\}$ denotes the Lebesgue measure of set $B$.

(b) Assume that the function $f:[a, b] \rightarrow \mathcal{R}$ with $a<b$ is $q$-times continuously differentiable and satisfies $\left|f^{(q)}(t)\right| \geq \beta$ for all $t \in[a, b]$ for some positive integer $q$ and $\beta>0 .$ Prove the following estimate
$$
m\{t \in[a, b]:|f(t)| \leq \varepsilon\} \leq 4\left(q ! \frac{\varepsilon}{2 \beta}\right)^{\frac{1}{q}} \quad \text { for } \varepsilon>0
$$
where $m\{B\}$ denotes the Lebesgue measure of set $B$.
I have proved $(a)$. Noting that we can assume that $f^{\prime}(t)\geq \beta$ and $a= 0$, so $f(t)\geq \beta t+f(0)  $ $(*)$. However, it's easy to show that for any linear function with slope $\beta$,  $(a)$ is correct. By $ (*)$ one can prove $(a)$ for all differentiable $f$ with $\left|f^{\prime}(t)\right| \geq \beta$.
For (b), the method we use in (a) is out of work, since we cannot get the inequality like $(*)$. I
also tried to prove it by induction but falied.
May anyone give me some hint or correct solution? Thanks in advance!!!

A: Introduction
I cannot believe that the second question was given as any kind of homework. It is a quite outstanding question, and I think I haven't got the best constants either.
The topic under discussion is called "sublevel set estimation". Why? Well, the set $\{x : |f(x)| \leq \epsilon\}$ is the ($x$ coordinates of the) part of the graph that lies between the lines $y=-\epsilon$ and $y=\epsilon$. If it's a non-negative function, then we're looking at just the part of the graph lying below the line $y=\epsilon$ : hence the word "sublevel".
We are estimating the measure of a sublevel set in this question. The point, however, is that this is a research topic : which is precisely why I'm going to be providing a detailed answer, rather than one with hints.
Throughout this answer, $E = \{x : f(x) \leq \epsilon\}$, for $\epsilon>0$ fixed but arbitrary, and $f^k$ denotes the $k$th derivative of a function $f$.
We will prove a result extremely similar to the one in the question, but it seems to be different at the end. I can confirm that my working is correct, though.
We will assume, throughout, that $f^k > \beta$. Indeed, $f^k$ hasthe intermediate value property, therefore it is either true that $f^k$ either stays above $\beta$ or below $-\beta$, and a switch from $f$ to $-f$ tells you it's enough to consider one case.

Intuition
So, let's review the one-dimensional case first, it's quite easy. Let $x,y \in E$. We note that $|f(x)-f(y)| \leq 2\epsilon$ from the triangle inequality. We , however, also have :
$$
|f(x)-f(y)| = \left|\int_x^y f'(t)dt\right| \geq \beta |x-y|
$$
whence it follows that $|x-y| \leq \frac{2\epsilon}{\beta}$ for all $x,y \in E$ and the desired inequality follows readily by taking $x=\inf E,y = \sup E$ and using monotonicity of the Lebesgue measure.
Now, what is the trouble in the two-dimensional case with this approach? There, if we decide to use Taylor, we get :
$$
f(x)-f(y) = f'(y)(x-y) + \frac{f''(\xi)}{2}(x-y)^2
$$
It feels like you can do something with this : except, you cannot get rid of the arbitrariness of $f'(y)$ here, and that plays the argument out of the park. If you try to proceed , you will not be able to shake off the contribution of the $f'$ term , even with the most naive of approaches, basically because $f'$ can be anything.

Ingenious observation
It is now clear to us, what needs to be done. Let's stick to the question for the second derivative. The point is this : passing from the second derivative to the first derivative cannot be done via Taylor's formula, because that involves the arbitrary-looking first derivative.

Therefore, any key insight to this problem is to find a way to link the second derivative to the initial function, without involving the first derivative at all!

In more generality , it is to basically link the function values to that of any larger derivative , so that once you use the bound on the derivative there, then you can easily translate this to something about the function values!
Can we do this though?

Inventive Rolle
What is a result that we know does something like this? It's the generalized Rolle's theorem, which basically states (roughly) that if $f$ is $k$ times differentiable on $[c,d]$ and there are $k+1$ distinct points in $[c,d]$ where $f$ vanishes, then there is a point where $f^k$ actually vanishes.
That's relating some function values, to a derivative value. Can we do better, though? The answer is, yes : we can actually derive a very generalized version of Rolle's theorem that allows us to get some derivative value as an exact expression of some given function values.
The theorem is quite involved, and relates to Lagrange interpolation. I quote it directly from the best paper I could find in the literature on sublevel estimation , by Carbery,Christ and Wright. I have made some changes to suit this to our discussion.

Let $k \geq 1$ and $a \leq a_1 < \ldots < a_{k+1} \leq b$ be distinct points in $[a,b]$. Suppose that $f$ is $k$ times continuously differentiable on $(a,b)$ and $k-1$ times continuously differentiable on $[a,b]$. Then, there is a $\xi \in (a,b)$ and explicit constants $c_m$ not depending upon $f$,such that:
$$
f^{k}(\xi) = \sum_{m=1}^{k+1} c_m f(a_m) = f^{k}(\xi)
$$

We will prove this using a "polynomial fitting" argument : which is where interpolation comes in.

Indefatigable proof
We start by trying to reduce this result to the Generalized Rolle's theorem (GRT). For that , we need a function such that it vanishes at $k+1$ points. What better than $a_1,...,a_{k+1}$ for those points?
What we will do is the following :

*

*Prove and find a polynomial $p$ of degree $k$ such that $p(a_i) = f(a_i)$ for all $i=1,...,k+1$.

*Apply the GRT to $f-p$, and pullback to $f$.
Finding the polynomial $p$ is a linear-algebraic exercise and is the meat of Lagrange interpolation. Indeed, suppose that $p(x) = b_kx^k + \ldots + b_0$. Then, the following product of matrices must hold true :
$$
V_{k+1}(a_1,\ldots,a_{k+1}) [b_0,\ldots,b_k]^T = [f(a_1),\ldots,f(a_m)]^T
$$
where $V_{k+1}$ is the Vandermonde matrix, defined by $[V_{k+1}]_{i,j} = a_i^{j-1}$. It is well-known by the distinct nature of the $a_i$, that $V_{k+1}$ is invertible, and therefore :
$$
[b_0,\ldots,b_k]^T = V_{k+1}(a_1,\ldots,a_{k+1})^{-1} [f(a_1),\ldots,f(a_m)]^T
$$
What we want from this, is actually the value of $b_{k}$, because we plan to apply the GRT so when we take the $k$th derivative of $p$ we're left with $k!b_k$. We can get that using the usual co-factor rule , and spotting the recurrence of the Vandermonde determinant, but without the $k$th powers and without $a_k$ appearing. Hence, $$
[V_{k+1}(a_1,\ldots,a_{k+1})^{-1}]_{k+1,j} = (-1)^{k+1+j} \frac{\det V_{k}(a_1,\ldots,a_{j-1},a_{j+1},\ldots,a_{k+1})}{\det V_{k+1} (a_1,\ldots,a_{k+1})} \\ = (-1)^{k+1+j} \prod_{i \neq j} |a_i - a_j|^{-1}
$$
Thus, we get :
$$
b_{k} = \sum_{i=1}^{k+1} (-1)^{k+i+1} f(a_i)\prod_{j \neq i} |a_j - a_i|^{-1}
$$
and the polynomial $p$ has been constructed. Now, $(f-p)(a_i)=0$ for all $i$, so using GRT we get a $\xi$ where $(f-p)^k(\xi) = 0$. But then, $(f-p)^{k} = f^k - k!b_k$. Thus, it follows that $$
f^k(\xi) = \sum_{i=1}^{k+1} \underbrace{k!(-1)^{k+i+1}\prod_{j \neq i} |a_j - a_i|^{-1}}_{c_i} f(a_i)
$$
as desired. $\blacksquare$

Intricate finish, but still more to go
I will now show the end of the proof , but we'll leave a nice part to the end. So how does the proof end? Well, we'd have $f'(\xi) = \sum_{i=1}^{k+1} c_if(a_i)$ for some $a_i \in E,c_i$ and $\xi$. By the derivative bound, $\beta \leq \sum_{i=1}^{k+1} c_if(a_i)$.
We will now find a relation of the form $|E|^k \leq \frac{k!C^k}{|c_i|}$ where $C$ is a constant independent of all parameters. This will be done by a very good choice of $a_i$. Once we do that, we get :$$
\beta \leq \sum_{i=1}^{k+1} f(a_i)\frac{k!C^k}{|E|^k} \leq (k+1)! \frac{C^k}{|E|^k} \max_{i} f(a_i) \leq (k+1)! \frac{C^k}{|E|^k} \epsilon
$$
and hence $$
|E| \leq C\sqrt[k]{\frac{(k+1)!\epsilon}{\beta}}
$$
which is the bound desired.

Inequality
We will now prove the claim in the previous section. For this, we make two observations :

*

*Consider the quantity $\prod_{j \neq i} |a_j - a_i|$. This is basically maximized when the $a_i$ are as well-spread out from each other as possible. It's obvious, then, that when possible, they should be uniformly distributed.

*Suppose that $E$ isn't an interval. Then, the point is that the inequality for $E$ is proved by proving the inequality for the smallest interval that contains $E$, simply because the $a_i$ continue to lie in the larger interval. Therefore, we can work with just intervals in this part.
Once we make these two observations, let $E = [c,d]$ and consider the $k+1$ "uniformly distributed" points $a_i = \frac{i}{k}c + \frac{k-i}{k}d$ for $i=0,...,k$. With these points , we can use an inequality like Jensen to prove that the $c_i$ is minimized at $\frac{k\pm 1}{2}$ for $k$ odd, and at $\frac k2$ for $k$ even, since the absolute value is log-convex.
With these, the minimal $c_i$, for $k$ odd,even respectively become :
$$
\frac{k+1}{2k} \prod_{i=1}^{\frac{k-1}{2}} \frac{i^2}{k^2} \quad ;\quad  \prod_{i=1}^{\frac{k}{2}} \frac{i^2}{k^2}
$$
The (last but not the least) miraculous observation at this point is that both these quantities have good bounds. This follows from bounds relating to Stirling's approximation : for the second one, for example, we have $\frac{(k/2)!^2}{k^k}\geq \frac{2 \pi e^{-k}k^{k+1}}{2^{k+1}k^{k}} = k\pi(e^{-k}2^{-k}) \geq (2e)^{-k}$. The other one can be tackled similarly.
Hence, we can take $C = 2e$.

The final statement would then read :

If $f^{k} \geq \beta$ on $[a,b]$ then for any $\epsilon>0$,
$$
|\{x : |f(x)| \leq \epsilon\}| \leq (2e)\sqrt[k]{(k+1)!\frac{\epsilon}{\beta}}
$$

I think it will be difficult to improve upon these constants, unless the situation is refined even more. Having said that, my main aim was to show that this question is way more complicated than it looks initially.


text:
Q: Optimizing a function I've come up with a problem:
I am writing a function that accepts 2 arguments: rug_length and prices, rug_length is an int representing how many meters of a rug you want to buy, prices is a dictionary that holds prices for a different length of a rug where key is the length and the value is the price.
An example of a function call:
rug_length = 10
prices = {1:2, 2:3, 3:1, 4:5, 5:4}

fn(rug_length, prices)

The function needs to return the minimum cost of a selected length of the rug, so for example:
fn(1, prices) # returns 2
fn(3, prices) # returns 1
fn(5, prices) # returns 4
fn(6, prices) # returns 2 ( 1 + 1 )
fn(8, prices) # returns 5 ( 1 + 1 + 2 )
fn(9, prices) # returns 3 ( 3 + 3 + 3 )

I figured I sort the dictionary by the cost of a meter.
I've written two functions:
def fn(rug_length, prices):
    if rug_length == 0:
        return 0
    cost = 0
    while rug_length > 0:
        for key, v in sorted(prices.items(), key=(lambda item : (item[1]/item[0]))):
            while rug_length >= key:
                rug_length -= key
                cost += prices[key]
    return cost

%%timeit -n 250
fn(245245, price)
# 4.54 ms ± 25 µs per loop (mean ± std. dev. of 7 runs, 250 loops each)

And the second one:
def fn_2(rug_length, prices):
    if rug_length == 0:
        return 0
    cost = 0
    prices = sorted(prices.items(), key=(lambda item : (item[1]/item[0])))
    while rug_length > 0:
        for key,v in prices:
            cost += (rug_length//key)*v
            rug_length%=key
    return cost

%%timeit -n 250
fn_2(245245, price)
# 1.76 µs ± 54 ns per loop (mean ± std. dev. of 7 runs, 250 loops each)

Is there a place for improvement?


text:
Q: Make yellow autocomplete transparent in Google Chrome This is the textarea

This is the textarea that is clicked on and has text in it

When Google chrome's autocomplete hijacks the textarea

I've tried fixing it by putting in this code
input:-webkit-autofill {
    -webkit-box-shadow: 0 0 0 1000px #FFFFFF inset;
}

But the best I can get it to look like is this

I want the white box to either be transparent, or it can stay white but be smaller so that it does not block any of the blue parts of the textbox. Is this possible at all? I've tried googling around and I came up with nothing. Or if you guys have any other ideas on how to fix this, that would be great!
Also, if there is a way to make the autocomplete box just a little bit smaller that would be fine too, or maybe a way to move the label down ? =/
I want autocomplete on.

A: Please try this:
input:-webkit-autofill {
    -webkit-box-shadow:5px 5px 5px rgba(0,0,0,0.3);
}

rgba fourth argument is opacity level.

A: also try:
input:-webkit-autofill {
   background:rgba(255,255,255,0) !important;
}

A: try this: background-color: #fff !important;
http://labs.enonic.com/articles/remove-forced-yellow-input-background-in-chrome
Removing input background colour for Chrome autocomplete?
Are you sure I found this: Google Chrome form autofill and its yellow background


text:
Q: Multiple Push / pop in PDA While designing Push Down Automata consider my inputs are {a,b} Now can I push multiple a's or multiple b's while scanning them...and then while popping can I pop multiple number of a's or multiple number of b's... OR is it the case that I can push/pop only one element at a time i.e. pushing single 'a' or single 'b' and also while popping out only single 'a' or single 'b'?

A: Suppose you have a PDA that relies on pushing multiple values onto the stack. Specifically, in state q with top-of-stack symbol x and input symbol y, you replace symbol x with the string s (which may or may not maintain x in its position on the stack) and change to state q'.
This PDA can be transformed into one which does not rely on pushing multiple symbols onto the stack simultaneously as follows:

*

*add states q1, q2, …, q|s| to the PDA

*change the transition (q, x, y) -> (q', s) to (q, x, y) -> (q1, s[1])

*add transitions (qk, x, e) -> (qk+1, s[2]x) for 1 <= k < s

*add a transition (q|s|, x, e) -> (q', x)

Note that if we started with a DPDA, we still have a DPDA after this transformation: we have transitions which do not consume input, however, this is fine for DPDAs as long as only one transition can be taken at any given time.
Popping is a little harder but the idea is the same:

*

*introduce some new states

*start popping the symbols in the right order

*if you pop everything you needed, great, continue on as in the original PDA

*if you find you're missing something you wanted to pop, you should basically just crash (a DPDA cannot possibly have accepted the input since it only came down this path because it had to, while an NPDA can still accept along some other path)


text:
Q: How to re-write count-up loop with system.out in stream API How can I rewrite this code in Java 8 stream API?
public static void main(String[] args) {
    final List<String> ids = Arrays.asList("001", "007", "012", "099", "101", "167");
    int total = 0;
    for (String id : ids) {
        if (id.indexOf("1") >= 0) {
            System.out.println(id);
            total++;
        }
    }
    System.out.println("Total count: " + total);
}

A: The equivalent stream can be like so :
long total = ids.stream()
     .filter(id - > id.indexOf("1") >= 0)
     .peek(System.out::println)
     .count();

A: We can do it like :
    System.out.println(
            "Total count: " + ids.stream()
                                .filter(id -> id.indexOf("1") >= 0)
                                .peek(System.out::println)
                                 .count());

A: It might be even simpler:
long count = Arrays.stream(new String[] {"001", "007", "012", "099", "101", "167"})
                   .filter(id -> id.contains("1"))
                   .peek(System.out::println)
                   .count();

I'd rather have a short break with the condition. The statement id -> id.indexOf("1") >= 0 means that the "1" is contained in the given string at any position, therefore the following expression using String::contains would me more suitable:
.filter(id -> id.contains("1"))

On the other hand, I feel you might want to count these ids having "1" at the first position, therefore String::startsWith is better:
.filter(id -> id.startsWith("1"))

In any case, you have your answer already here.


text:
Q: Change the value of the key in dictionary in Python I have a list called 'li':
dict1={1:'1 okt 2002'}
dict2={1:'2 may 2003'}
li=[dict1,dict2]

I want to change the dates to python date_time format, Python understand 'Oct' not 'Okt'. So I decided to replace 'Okt' by 'Oct' first. I have tried
In[1]: A=[]
        for item in li:
           a=item[1].split()
           replace(a,'okt', 'oct')
           A.append(a)
        A
out[1]: [['1', 'oct', '2002'], ['2', 'may', '2003']]

But this is not exactly what I am looking for. Is there any way to turn
['1','oct','2002'] to '1 oct 2002'?
Or is it any better way to change 'Okt' to 'Oct' inside the dictionary values?
Thank you.
Replace function:
def replace(l, X, Y):
    for i,v in enumerate(l):
        if v == X:
            l.pop(i)
            l.insert(i, Y)

A: ' '.join(['October', '20', '2000'])

is what you want. string.join(list) joins each element of an array separated by a string. In this case, you can plug in your array separated by a space.
As for a better way to replace okt with oct, you can use this as the first line of your loop and get rid of the replace function:
a=item[1].replace('okt', 'oct').split()

EDIT (array->list): Thanks @juanpa.arrivillaga

A: It is hard to know why your code isn't working because we don't know what your replace function does, but apparently, it returns a list. Here's a quick way to achieve what you want, though:
>>> dict1={1:'1 okt 2002'}
>>> dict2={1:'2 may 2003'}
>>> li=[dict1,dict2]
>>> [{k:v.replace('okt','oct') for k,v in d.items()} for d in li]
[{1: '1 oct 2002'}, {1: '2 may 2003'}]
>>>

And you can define a helper function to get your datetime object:
>>> def to_date(dstring):
...     return datetime.datetime.strptime(dstring, '%d %b %Y')
...
>>> [{k:to_date(v.replace('okt','oct')) for k,v in d.items()} for d in li]
[{1: datetime.datetime(2002, 10, 1, 0, 0)}, {1: datetime.datetime(2003, 5, 2, 0, 0)}]
>>>

The equivalent neste-forloop for the comprehension construct would be:
>>> li2 = []
>>> for d in li:
...     temp = {}
...     for k,v in d.items():
...         temp[k] = to_date(v.replace('okt','oct'))
...     li2.append(temp)
...
>>> li2
[{1: datetime.datetime(2002, 10, 1, 0, 0)}, {1: datetime.datetime(2003, 5, 2, 0, 0)}]
>>>


text:
Q: Implementing a Simple Vector Example With Templates Causing Undefined Symbol Error Can anyone tell me why I am getting the error Undefined Symbol: Vector::Vector(int)?
I am trying to learn the language by making a simple vector class.
The first iteration used doubles as elements. Now I am trying to get it to work with templates so it will work with any type. It was working fine until I did that. I must have implemented it wrong.
Here is the code:
//main.cpp
#include <iostream>
#include "Vector.h"
#include <list>
#include <algorithm>

int main(int argc, const char * argv[]) {
    // insert code here...
    std::cout << "Hello, World!\n";

    Vector<int> a(5);
    Vector<int> b(5);

    return 0;
}

//vector.h
#ifndef Vector_h
#define Vector_h

template<typename T>
class Vector {
public:
    explicit Vector(int s); // constr uctor: establish invariant, acquire resources
    ~Vector() { delete[] elem; } // destructor: release resources
    // ... copy and move operations ...
    T& operator[](int i); // for non-const Vectors
    const T& operator[](int i) const; // for const Vectors (§4.2.1)
    int size() const { return sz; }

    friend Vector operator+(const Vector& a, const Vector& b);

    Vector(const Vector& a); // copy constructor
    Vector& operator=(const Vector& a); // copy assignment

    Vector(Vector&& a); // move constructor
    Vector& operator=(Vector&& a); // move assignment move assignment operator

    T* begin(Vector<T>& x);
    T* end(Vector<T>& x);

private:
    T* elem; // elem points to an array of sz elements of type T
    int sz;
};

//vector.cpp:
#include <stdio.h>
#include "Vector.h"
#include <iostream>
#include <exception>

template<typename T>
Vector<T>::Vector(int s) // definition of the constructor
//:elem{new double[s]}, sz{s} // initialize members or do whats in bottom here.
{
    elem = new T[s];
    sz = s;
    std::cout << "Main Constructor" << std::endl;
}

    template<typename T>
    T& Vector<T>::operator[](int i) // definition of subscripting
    {
    return elem[i];
    }

    template<typename T>
    const T& Vector<T>::operator[](int i) const // definition of subscripting
    {
    return elem[i];
    }

    template<typename T>
    Vector<T> operator+(const Vector<T>& a, const Vector<T>& b)
    {
    //if (a.size()!=b.size())
    //  throw Vector_size_mismatch{};
    std::cout << "Move Constructor" << std::endl;
    Vector<T> res(a.size());
    for (int i=0; i!=a.size(); ++i)
    res[i]=a[i]+b[i];
    return res;
    }

    template<typename T>
    Vector<T>::Vector(const Vector<T>& a) // copy constructor
    :elem{new double[a.sz]}, // allocate space for elements
    sz{a.sz}
    {
    for (int i=0; i!=sz; ++i) // copy elements
    elem[i] = a.elem[i];
    std::cout << "Copy Constructor" << std::endl;
    }

    template<typename T>
    Vector<T>& Vector<T>::operator=(const Vector<T>& a) // copy assignment
    {
    std::cout << "Copy Assignment Constructor" << std::endl;
    std::cout << "Element is " << a[0] << std::endl;
    double* p = new double[a.sz];
    for (int i=0; i!=a.sz; ++i)
    p[i] = a.elem[i];
    delete[] elem; // delete old elements
    elem = p;
    sz = a.sz;
    return *this;
    }

    template<typename T>
    Vector<T>::Vector(Vector<T>&& a) // Move construtor
    :elem{a.elem}, // "grab the elements" from a
    sz{a.sz}
    {
        a.elem = nullptr; // now a has no elements
        a.sz = 0;
    }

    template<typename T>
    Vector<T>& Vector<T>::operator=(Vector<T>&&) { return *this;  } // Move assignment

    template<typename T>
    T* begin(Vector<T>& x)
    {
        return x.size() ? &x[0] : nullptr; // pointer to first element or nullptr
    }
        template<typename T>
    T* end(Vector<T>& x)
    {
        return x.size() ? &x[0]+x.size() : nullptr; // pointer to one-past-last element
    }


text:
Q: Numbers to array json format I have the variable that holds numbers...before writing it to database it must be in this format:
["1", "6", "11", "15"]

I got this from my ajax call:
1,6,11,15

I try to convert string with numbers to array...and now one way is to foreach to read from array and add to beginning and ending string " but i think that is bad idea...could be simpler way to archive this above output?
$numbers = '1,6,11,15';

$a = str_split($numbers);

print_r($a);

A: $numbers = '1,6,11,15';

$a = explode(",",$numbers);

echo json_encode($a);


text:
Q: Matching a target velocity and position For a science-fiction computer game I'm writing, I wish to calculate the travel time and accelerations of a ship leaving one (3D) position with an initial velocity, and travelling to a moving target, aiming to match both position and velocity when it arrives.
Since I don't believe I can solve the whole problem analytically, I've broken it up into two parts.  The exercise of intercepting a moving target is being done with successive approximation - I calculate the position and velocity of the target at the departure time (i.e. assuming a zero travel time), then calculate the time it would take to travel to match that position and velocity.  I then repeat the calculation for that updated arrival time, and iterate to converge on a position and velocity which is correct at the time the ship actually arrives.
The other part of the problem is actually calculating the time and accelerations needed to arrive at the target position with a target velocity.  I have not been able to solve this analytically either, but I feel there should be an analytic solution, which is what my question actually relates to.
My assumptions are

*

*The ship has magic science-fiction drives, so it can accelerate continuously without needing reaction mass.

*The ship's acceleration is $>>$ the influence of gravity, so I'm ignoring gravity in the ship's equation of motion.

*I've divided the motion up into two phases of constant acceleration.  Phase 1 is of duration $t_1$ where the ship applies acceleration $\vec{a_1}$, and phase 2 is of duration $t_2$ where the ship applies acceleration $\vec{a_2}$.

*The ship can instantaneously change acceleration at the transition from phase 1 to phase 2.

*I believe that the solution with the shortest possible travel time will involve using the ship's maximum thrust, giving an acceleration of $a$, and therefore $\lvert\vec{a_1}\rvert = \lvert\vec{a_2}\rvert = a$.

The known values are

*

*The initial position $\vec{p_i}$

*The initial velocity $\vec{v_i}$

*The target position $\vec{p_t}$

*The target velocity $\vec{v_t}$

*The ship's maximum acceleration $a$.

The variables I wish to get analytical solutions for are

*

*The duration $t_1$ of phase 1.

*The acceleration $\vec{a_1}$ during phase 1.

*The duration $t_2$ of phase 2.

*The acceleration $\vec{a_2}$ during phase 2.

I wish to minimise the travel time $t_1 + t_2$.
Given all that, I have some vector equations based on the classic equations of motion.
\begin{align}
\lvert\vec{a_1}\rvert & = \lvert\vec{a_2}\rvert = a \tag{1}\label{eq1} \\
\vec{v_t} & = \vec{v_i} + \vec{a_1} t_1 + \vec{a_2} t_2 \tag{2}\label{eq2} \\
\vec{p_t} & = \vec{p_i} + \vec{v_i} t_1 + \frac{\vec{a_1} t_1^2}2 + (\vec{v_i} + \vec{a_1} t_1) t_2 + \frac{\vec{a_2} t_2^2}2 \\
\iff \vec{p_t} & = \vec{p_i} + \vec{v_i} (t_1 + t_2) + \frac{\vec{a_1} t_1^2}2 + \vec{a_1} t_1 t_2 + \frac{\vec{a_2} t_2^2}2 \tag{3}\label{eq3} \\
\end{align}
I can rearrange equation $\ref{eq2}$ to get $a_2$,
\begin{align}
\vec{v_t} & = \vec{v_i} + \vec{a_1} t_1 + \vec{a_2} t_2 \tag{2} \\
\iff \vec{a_2} t_2 & = \vec{v_t} - \vec{v_i} - \vec{a_1} t_1 \\
\iff \vec{a_2} & = (\vec{v_t} - \vec{v_i} - \vec{a_1} t_1) / t_2 \\
\end{align}
and then substitute it into $\ref{eq3}$:
\begin{align}
\vec{p_t} & = \vec{p_i} + \vec{v_i} (t_1 + t_2) + \frac{\vec{a_1} t_1^2}2 + \vec{a_1} t_1 t_2 + \frac{\vec{a_2} t_2^2}2 \tag{3} \\
\iff \vec{p_t} & = \vec{p_i} + \vec{v_i} (t_1 + t_2) + \frac{\vec{a_1} t_1^2}2 + \vec{a_1} t_1 t_2 + \frac{(\vec{v_t} - \vec{v_i} - \vec{a_1} t_1) t_2}2 \\
\iff \vec{p_t} & = \vec{p_i} + \vec{v_i} (t_1 + t_2) + \frac{\vec{a_1} t_1^2}2 + \vec{a_1} t_1 t_2 + \frac{\vec{v_t}t_2 - \vec{v_i}t_2 - \vec{a_1} t_1 t_2}2 \\
\iff \vec{p_t} & = \vec{p_i} + \vec{v_i} (t_1 + \frac{t_2}2) + \frac{\vec{a_1} t_1^2}2 + \frac{\vec{a_1} t_1 t_2}2 + \frac{\vec{v_t}t_2}2 \\
\end{align}
... and that's as far as I've got with this version of the problem.  I've tried taking the dot product of both sides with $\vec{a_1}$ to make it into a scalar quadratic which I could solve, and also $\vec{a_1} . \vec{a_1} = a^2$, a known quantity, but that doesn't actually eliminate the unknown direction of $\vec{a_1}$ because it's still needed to calculate the dot product with $\vec{p_t}$, $\vec{p_i}$, $\vec{v_i}$ and $\vec{v_t}$.
I have four unknowns and only really two equations (I don't know that the two equations in \ref{eq1} really count in terms of eliminating unknowns), plus a desire to minimise $t1 + t2$, so obviously I need to pin down some more things before I can progress.  It feels like there should be enough information to come up with a unique solution (or perhaps a set of solutions), but maybe I'm wrong.
Edit: Actually, I've realised that I can use \ref{eq1} to eliminate an unknown.
\begin{align}
\vec{v_t} & = \vec{v_i} + \vec{a_1} t_1 + \vec{a_2} t_2 \tag{2} \\
\iff \vec{a_2} t_2 & = \vec{v_t} - \vec{v_i} - \vec{a_1} t_1 \\
\implies \lvert \vec{a_2} t_2 \rvert & = \lvert \vec{v_t} - \vec{v_i} - \vec{a_1} t_1 \rvert \\
\iff \lvert \vec{a_2} \rvert t_2 & = \lvert \vec{v_t} - \vec{v_i} - \vec{a_1} t_1 \rvert \\
\iff a t_2 & = \lvert \vec{v_t} - \vec{v_i} - \vec{a_1} t_1 \rvert \tag{using \ref{eq1}} \\
\iff t_2 & = \frac{\lvert \vec{v_t} - \vec{v_i} - \vec{a_1} t_1 \rvert}a \\
\end{align}
... and then substitute for $t_2$ in our working equation to eliminate the unknown $t_2$.  However, since I'm unaware of any way to manipulate or extract values inside the magnitude expression (beside the manipulation I just used above, pulling out $t_2$ from the magnitude expression as a single scalar common factor), that leaves us with both $\vec{a_1}$ and $t_1$ trapped inside terms we can't extract them from, so we can't continue to rearrange our equation to get either variable by itself on one side of the equals symbol.  It thus doesn't seem to help us get to an analytic expression for either $\vec{a_1}$ or $t_1$.


text:
Q: Communicating dynamic port numbers I have a Visual Studio solution which consists of five executables, one in c++ and four in c.  They use UDP sockets on local host with fixed ports to communicate with each other.
Now I need to run multiple instances of this program so I believe dynamic ports are required.  How do I arrange it so both sides of a socket know the port number?

A: You will have to use some other means of communicating the actual port number. For example, save obtain the port number into shared memory or some sort of the file. However, if you are running it locally on the same Windows machine, you might want to use different IPC protocol. For example, Named Pipes.


text:
Q: Loop that uses try/except for input and loops until 'done' is entered I'm kind of new to coding in Python and I'm trying to write a loop that asks for numerical input and reads it until the user inputs "done", where it will then exit the loop and print the variables: number, count and average. (not trying to store anything in a list)
I also want it to print "invalid input" and continue the loop if the user enters anything that isn't an integer, unless its "done".
Unfortunately it returns "invalid input" and keeps looping even when I enter "done". What am I doing wrong? Could anyone point me in the right direction?
number = 0
count = 0
avg = 0
inp = 0
while True:
    try:
        inp = int(raw_input('Enter a number: '))
        if inp is 'done':
            number = number + inp
            count = count + 1
            avg = float(number/count)
            break
    except:
        print 'Invalid input'
print number
print count
print float(avg)

A: sum = 0.0
count = 0
while True:
    inp = raw_input('Enter a number: ')
    if inp == 'done':
        break
    try:
        sum += int(inp)
        count += 1
    except ValueError:
        print 'Invalid input'
print sum
print count
if count != 0:  # Avoid division by zero
    print sum / count


text:
Q: Joomla 3 component MVC model, adding article directly to the database I am a beginner both when it comes to using MVC and creating Joomla components. I need to create a component that reads an uploaded CSV-file that contains article data, and add them directly into the database.
So far I've only created a barebone component that uses the example of adding an article directly to the database that I found here, and I've tried to implement it using the MVC structure, but I'm not sure if I'm doing it correctly.
The component is based on the com_helloworld component from the tutorial on how to create a basic component, I will explain the structure, and then hopefully somebody can tell me whether what I'm doing seems reasonable or not.
So when I open the component from the adminstrator panel in Joomla, it goes to the default view in
com_helloworld/admin/views/helloworld

view.html.php loads nothing from the corresponding model, and simply opens the default.php in
com_helloworld/admin/views/helloworld/tmpl

default.php contains:
<?php?>
Add an article

So clicking the link opens the view jimport, which has the following view.html.php:
<?php
defined('_JEXEC') or die('Restricted access');
class HelloWorldViewJImport extends JViewLegacy
{
        function display($tpl = null)
        {
                // Get status from the model
                $this->status=$this->get('Status');
                parent::display($tpl);
        }
}

and the following default.php in the tmpl folder:
<?php echo($this->status);

The view jimport calls the function getStatus() from the corresponding model in com_helloworld/admin/models/jimport.php, which contains the following code:
class HelloWorldModelJImport extends JModelList {

    public function getStatus($type = 'JImport', $prefix = 'HelloWorldTable', $config = array()) {
        $table = JTable::getInstance($type, $prefix, $config);
        $title='Article';
        $alias=$title;
        $introtext='This article has been added automatically to the database through a component';
        $catid=2;
        if ($table->addArticle($title, $alias, $introtext, $catid)) {
            return "The article has been added.";
        } else {
            return "There was an error.";
        }
    }

}

In other words, getStatus tries to add the article to the database and returns a string telling whether it was succesful or not.
Now this function gets an instance from the JTable implementation in
com_helloworld/admin/tables

which contains jimport.php:
class HelloWorldTableJImport extends JTable {

    /**
     * Constructor
     *
     * @param   JDatabaseDriver  &$db  A database connector object
     */
    function __construct(&$db) {

    }

    public function addArticle($title, $alias, $introtext, $catid) {
        if (version_compare(JVERSION, '3.0', 'lt')) {
            addIncludePath(JPATH_PLATFORM . 'joomla/database/table');
        }

        $article = $this->createArticle($title, $alias, $introtext, $catid);

        // Check to make sure our data is valid, raise notice if it's not.
        if (!$article->check()) {
            JError::raiseNotice(500, $article->getError());
            return FALSE;
        }

        // Now store the article, raise notice if it doesn't get stored.
        if (!$article->store(TRUE)) {
            JError::raiseNotice(500, $article->getError());
            return FALSE;
        }
        return TRUE;
    }

    private function createArticle($title, $alias, $introtext, $catid) {
        $article = JTable::getInstance('content');

        $article->title = $title;
        $article->alias = JFilterOutput::stringURLSafe($alias);
        $article->introtext = $introtext;
        $article->catid = $catid;
        $article->created = JFactory::getDate()->toSQL();
        ;
        $article->created_by_alias = 'Super User';
        $article->state = 1;
        $article->access = 1;
        $article->metadata = '{"page_title":"","author":"","robots":""}';
        $article->language = '*';

        return $article;
    }

}

This is where the article is actually added to the database, and that pretty much explains the entire component.
I would like to know if this seems like a reasonable way to do this. I'm not really sure if this is something that I should do from the model, or if the article should be added through a controller.
This is probably a very basic question, and I have been trying to figure this out on my own, but I haven't really found an example for this particular case.


text:
Q: Does IE7 compatibility mode work the same on IE9 as it works on IE8? I know IE7 compatibility mode isn't the same as the IE7 standalone browser, but in terms of my current set-up, which is IE8, I see certain IE7 bugs that I have to fix for the web app I'm working on.
If I upgrade to IE9, (which I'm thinking about because it has the Network tab in the dev toolbar), will I continue to see the same IE7 bugs when I view the site in IE7 mode?

A: In most cases, yes. Microsoft makes only very minor changes in Internet Explorer's compatibility modes (like, support for HTML5 iframe sandboxing is not included in IE9 and below, but it is supported by all IE10's compatibility modes, including quirks mode). In general, we can say that IE8-as-IE7 mode is the same as IE9-as-IE7.


text:
Q: How does the Yearling badge now work over multi years? I've been on SE site X for two years and six months, call it thirty months, and haven't gotten a Yearling badge. No surprise, since my reputation is less than 200.
In month 31, I "get active" on the site and my reputation starts to climb. I get a first, and then a second Yearling badge within days of each other. Specifically, I get these badges on the days that my rep rises past 200, then 400.
So did I meet a "dual" requirement? That is, I got badges for the lesser of the following two numbers: 1) the (completed) years on the site and 2) the whole number representing the quotient of the increase in my reputation divided by 200?
And if my rep on site X is now over 600, does that mean I'll get my third Yearling badge on my third anniversary on the site?
(There have been several other questions on the Yearling badge, but the protocols regarding it appear to have changed over time, so I haven't seen an "up to date" answer.)

A: If you miss the badge for a previous year, you won't get awarded that year's badge until you "catch up" to where you are supposed to be. So if you sit at, say, 50 reputation and then come back in 4 years, you will have to get up to 800 reputation and you'll receive all four badges at the same time.
Keep in mind that the equation used is simply y * 200 + 1, where y represents the numbers of years as a decimal you've been on the site. So if it's exactly your two-year anniversary and you have 401 reputation, you get the badge. If you pass your two-year anniversary and only have, say, 391 reputation, you don't get it for hitting 401 half-way through the year, because half-way through the year the requirement would be 2.5 * 200 + 1 which would come out to 501 reputation.
Here's a simple way to think about it: run your current site age through the formula y * 200 + 1 (again don't round to the past year). If your reputation is greater than or equal, then the system will check your Yearling badges and make sure you have one badge for every full year you've participated on the site. If not, no new badges will be awarded.


text:
Q: Alternate for thread.sleep(9000) in every line in selenium I have been using thread.sleep(9000) almost after every line of code in selenium which is making me wait for long.Can anybody suggest me an alternate way to reduce this.As my application is taking time load a page it needs to wait until a particular page is loaded to perform any action.

WebElement un = driver.findElement(By.id("login_username_id"));
            un.sendKeys(username);
            WebElement pwd = driver.findElement(By.id("login_password_id"));
            pwd.sendKeys(password);

            try {
                Thread.sleep(25000);
            } catch (InterruptedException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }
            driver.findElement(By.id("login_submit_id")).click();
            try {
                Thread.sleep(9000);
            } catch (InterruptedException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }

I want to reduce the usage of thread.sleep after every line and use one common function so that it waits whenever required.

A: Hi please use universal wait in your script i.e implicit wait
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);

above line tell selenium to wait for maximum of 10 seconds for each and every webelement before throwing any error (note you can increase or decrease seconds it depends upon you)
explicit wait : when you want to wait for a specific webelement (use this when you think a particular element takes more then usual time to load then only)
WebDriverWait wait = new WebDriverWait(driver, timeout);
wait.until(ExpectedConditions.visibilityOfElementLocated(your element));

A: use the below example:
public class Main{

static WebDriver driver = new FirefoxDriver();

public static void main(String [] args) throws InterruptedException{

    WebElement un = driver.findElement(By.id("login_username_id"));
    un.sendKeys(username);
    WebElement pwd = driver.findElement(By.id("login_password_id"));
    pwd.sendKeys(password);

    waitForElement(By.id("ur id"),60);

    driver.findElement(By.id("login_submit_id")).click();

    waitForElement(By.id("ur id"),60);

}

/**
 * wait until expected element is visible
 *
 * @param   expectedElement     element to be expected
 * @param   timeout             Maximum timeout time
 */
public static void waitForElement(By expectedElement, int timeout) {
    try {
        WebDriverWait wait = new WebDriverWait(driver, timeout);
        wait.until(ExpectedConditions.visibilityOfElementLocated(expectedElement));

    } catch (Exception e) {
        e.printStackTrace();
        //System.out.println("print ur message here");
    }
}
}

if u have any confusion, let me know.

A: You can put assertion saying that "Whether particular element displayed or not" so that web driver will spend time to search that element which will create delay in execution.
Ex: A page may contain some button make it as target and tell web driver to find it.


text:
Q: Need two fields together to be unique Say I have a model like this:
class Book(models.Model):

    user = models.ForeignKey(User)
    book_isbn = models.CharField()

I would like the combination of the book and user fields to be unique. That is different users could have the same book, but a specific user could only have the book once in their list of books.
I thought unique_together would be the perfect solution, but them read it can't be used if any of the fields have a FK. What's the best way to achieve what I want?

A: I'm currently using multiple django models with unique_together clause which contained foreign keys and I never had any problems. I currently using django 1.2.


text:
Q: Routing guards in Framework 7 Vue When I do the following:
{
      path: '/chat/',
      async(routeTo, routeFrom, resolve, reject) {
        if (localStorage.getItem('token')) {
          resolve({
            component: require('./assets/vue/pages/chat.vue'),
          });
        } else {
          resolve({
            component: LoginPage
          });
        }
      },
    }

Everything works as expected, but if I do this:
{
      path: '/chat/',
      component: require('./assets/vue/pages/chat.vue'),
      async(routeTo, routeFrom, resolve, reject) {
        if (localStorage.getItem('token')) {
          resolve();
        } else {
          resolve({
            component: LoginPage
          });
        }
      },
    }

Then the component always resolves, regardless of the async. This is also the case when I try to use a beforeEnter function instead of async; if the component is defined at the top level of the route, it always resolves.
How could I put an authentication middleware on a route?

A: Maybe try this.
const checkAuth = (to, from, resolve, reject) => {
   if (localStorage.getItem('token')) {
     resolve({ component: routeComponentMap[to.name] })
   } else {
     resolve({ component: LoginPage })
   }
}

const routeComponentMap = {
  CHAT: require('./assets/vue/pages/chat.vue')
}

const routes = [{
  path: "/chat/",
  name: "CHAT",
  async: checkAuth
}]


text:
Q: How to effect to video in fabric.js I want use image-filters to video.
(http://fabricjs.com/image-filters)
but It's stops video.
How to effect to video in fabric.js?
For example, how do I change the color of a video?
https://codepen.io/html5andblog/pen/dmKJH
↑I do not use CSS filter.
Can someone explain please?
Thanks.
<!DOCTYPE html>
<html>
<head>
<meta charset="SHIFT-JIS">
<title>sample</title>
<script src="http://code.jquery.com/jquery-latest.min.js" type="text/javascript"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.2.3/fabric.min.js"></script>
<script>

$(document).ready(function() {

    canvas = new fabric.Canvas('c');
    canvas.setWidth(480);
    canvas.setHeight(360);

    var video1El = document.getElementById('video1');
    var video1 = new fabric.Image(video1El, {
      left: 0,
      top: 0
    });

    canvas.add(video1);
    video1.getElement().load();

    $(document.body).on('click', '#play' ,function(){
        video1.getElement().play();

        //↓It's stops video.
        /*
        var filter = new fabric.Image.filters.BlendColor({
            color:'red',
            mode: 'tint',
            alpha: 0.5
        });
            canvas.item(0).filters.push(filter);
        canvas.item(0).applyFilters();
        */

    });

    fabric.util.requestAnimFrame(function render() {
      canvas.renderAll();
      fabric.util.requestAnimFrame(render);
    });

});
</script>

</head>
<body>
<button id="play">play</button>
<canvas id="c" width="300" height="300"></canvas>

<video id="video1" style="display: none" class="canvas-img" width="480" height="360">
  <source id="video_src1" src="https://html5demos.com/assets/dizzy.mp4" type="video/mp4">
</video>

</body>
</html>

A: Ok so it can be done, the problem is that fabricJS to be faster cache textures and avoid pulling them in the video card every applyfilters to save time.
In this case i had to modify your code n 2 places:
1) applyFilters need to be run each animation frame
2) the cache for the texture must be deleted each time
The hardest part was finding a video with cors enabled.

$(document).ready(function() {

    canvas = new fabric.Canvas('c');
    canvas.setWidth(480);
    canvas.setHeight(360);

    var video1El = document.getElementById('video1');
    var video1 = new fabric.Image(video1El, {
      left: 0,
      top: 0
    });

    canvas.add(video1);
    video1El.load();

    $(document.body).on('click', '#play' ,function(){
        video1El.play();
        var filter = new fabric.Image.filters.BlendColor({
            color:'red',
            mode: 'tint',
            alpha: 0.5
        });
        video1.filters = [filter];
    });

    fabric.util.requestAnimFrame(function render() {
      var image = canvas.item(0);
      var backend = fabric.filterBackend;
      if (backend && backend.evictCachesForKey) {
        backend.evictCachesForKey(image.cacheKey);
        backend.evictCachesForKey(image.cacheKey + '_filtered');
      }
      canvas.item(0).applyFilters();
      canvas.renderAll();
      fabric.util.requestAnimFrame(render);
    });

});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/2.2.3/fabric.min.js"></script>
<button id="play">play</button>
<canvas id="c" width="300" height="300"></canvas>
<video crossorigin="anonymous" id="video1" style="display: none" class="canvas-img" width="480" height="360">
  <source id="video_src1" src="http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4" type="video/mp4">
</video>


text:
Q: Aurelia's require element includes external resource inline? When working through the beginning tutorial, there's a point when one "requires" the bootstrap libraries (CSS):
<require from="bootstrap/css/bootstrap.css"></require>
<require from="font-awesome/css/font-awesome.css"></require>

When I look in Chrome's inspector, I don't find these CSS files as sources. Instead it seems like it is all inlined in the page.
Is this true, or just something with the debugger? If it is - won't this affect caching in the browser (CSS needs to re-download)?

A: When a CSS resource is imported via the <require> tag, the ES6 module loader (polyfilled by SystemJS) is used to download the CSS.  This is a standard XMLHttpRequest and the request will be cached by the browser's standard caching mechanisms. Once the CSS (text) is downloaded Aurelia stuffs it into a <style> element and appends the <style> element to the DOM in the appropriate way, depending on whether the scoped attribute was used and whether the element is in the shadow DOM.
The relevant code is here.
The benefit of this approach is CSS imports have consistent behavior with other types of resources such as HTML and JS in terms of relative paths, bundling and caching.  It also enables Aurelia to handle the scoped-css and shadow DOM scenarios.


text:
Q: Oracle sort substitution variables I need to sort substitution variables so I can refer to them later like this:
WITH
vars AS (SELECT SORT(:var1,:var2, :var3) FROM DUAL)
SELECT least_var, greater_var, greatest_var FROM vars;

A: Since you have substitution variables, you obviously have some host language. So one approach is to order the three values in the host language before you call the SQL query.
Another approach is to use the following query (e.g. in combination with the WITH clause):
select
    least(:var1, :var2, :var3) as least_var,
    case
      when :var2 < :var1 and :var1 < :var3
        or :var2 > :var1 and :var1 > :var3 then :var1
      when :var1 < :var2 and :var2 < :var3
        or :var1 > :var2 and :var2 > :var3 then :var2
      else :var3
    end as greater_var,
    greatest(:var1, :var2, :var3) as greatest_var
from dual

Creating a SORT function as you propose won't really work as a function cannot return a construct that serves as three columns. If you want to use functions, then use three of them: the built-in functions LEAST and GREATEST as well as a user-defined one called GREATER.


text:
Q: Is there a general algorithm that can be implemented via a computer program that can identify the function being represented by a graph? It might help understanding my question to think of the hypothetical situation in which I draw a seemingly random function on a piece of paper (with an accurate coordinate axis already on the paper), and I scan my drawing into the computer.  Then I open an application that can "look" at the graph (as a set of data points, maybe?  I don't know how such an algorithm would work) and identify the function's corresponding equation.
I know there are polynomial curve fitting methods, but I was wondering if there was a more general algorithm for identify any type of function's equation in their most used form.

A: The Cornell Creative Machine Lab developed Eureqa to approach this problem. From their website:

Eureqa (pronounced "eureka") is a software tool for detecting equations and hidden mathematical relationships in your data. Its goal is to identify the simplest mathematical formulas which could describe the underlying mechanisms that produced the data.

As others have pointed out, there are many functions which can be fitted to a data set, Eureqa attempts to find the the "simplest" explanation and there is no guarantee that it will uncover the "true" function that generated the data set.

A: If your graph has a distance $0.01$ from the graph of the function $y=x^2$ and distance $0.00001$ to the graph of the function $y=x^2+0.009$ which of the two functions you would choose?