text:
Q: Sliding Panels in Java
+--+-------+-------------+        +-------+-------+--------+
|  |       |             |        |       |       |        |
|  | Zone  |             |        |       | Zone  |        |
|  |       |             |   ->   |       |       |        |
|  | show  |             |        |       | show  |        |
|  |       |             |        |       |       |        |
+--+-------+-------------+        +-------+-------+--------+

I got a UserControl in C#, based on this post. When an user clicks one of the buttons, i changed the Panel.Left property, so the zone showed changes, calculating it with the left edge. I want this functionality in java. This is the code i did in c#:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using TimeSheets.DataModels;
using System.Diagnostics;

namespace TimeSheets.UserControls
{
    public partial class Tab : UserControl, TabItemClickListener
    {
        public TabListener Listener { get; set; }
        private TabItem selectedItem;
        private DateTime startTime;

        public int ItemHeight { get; set; }
        public int ItemWidth { get; set; }

        public TabItem SelectedItem
        {
            get { return selectedItem; }
            set
            {
                if (value != null)
                {
                    selectedItem = value;
                    selectedIndex = panel.Controls.GetChildIndex(value, false);
                    CambiarSeleccion(selectedIndex);
                }

            }
        }

        private int selectedIndex;
        public int SelectedIndex
        {
            get { return selectedIndex; }
            set
            {
                selectedIndex = value;
                if (selectedIndex >= 0 && selectedIndex <= panel.Controls.Count && panel.Controls.Count != 0)
                    CambiarSeleccion(selectedIndex);
            }
        }

        public Tab()
        {
            InitializeComponent();
            panel.Height = this.Height;
        }

        public void AddTabItem(TabItem item)
        {
            item.SetWidth(ItemWidth);
            item.SetHeight(ItemHeight);
            item.handler = this;
            panel.Width += ItemWidth;
            panel.Width += 6;
            panel.Controls.Add(item);
        }

        public void LimpiarPaneles()
        {
            panel.Controls.Clear();
        }

        public TabItem GetTabItem(int position)
        {
            return (TabItem)panel.Controls[position];
        }

        public Object GetValueAt(int position)
        {
            if (selectedIndex >= 0 && selectedIndex <= panel.Controls.Count && panel.Controls.Count != 0)
                return ((TabItem)panel.Controls[position]).Value;
            else
                return null;
        }

        private void tLeft_Tick(object sender, EventArgs e)
        {
            if (panel.Left < 0)
            {
                panel.Left = panel.Left + 5;
            }
        }

        private void tRight_Tick(object sender, EventArgs e)
        {
            //Debug.WriteLine(panel.Width + "panel.Right" + panel.Right + "this.Left" + panel.Left + "panel1.Width" + panel1.Width);
            if (panel.Width >= Math.Abs(panel.Left) + panel1.Width)
            {
                panel.Left = panel.Left - 5;
            }
        }

        private void bRight_MouseUp(object sender, MouseEventArgs e)
        {
            tRight.Stop();
        }

        private void bRight_MouseDown(object sender, MouseEventArgs e)
        {
            startTime = DateTime.Now;
            tRight.Start();
        }

        private void bLeft_MouseUp(object sender, MouseEventArgs e)
        {
            tLeft.Stop();
        }

        private void bLeft_MouseDown(object sender, MouseEventArgs e)
        {
            startTime = DateTime.Now;
            tLeft.Start();
        }

        public new void Click(TabItem item)
        {
            selectedIndex = panel.Controls.GetChildIndex(item, false);
            panel.Left = -selectedIndex * (ItemWidth + 6);
            CambiarSeleccion(selectedIndex);
        }

        private void CallListener()
        {
            if (Listener != null)
                Listener.OnItemSelected(selectedIndex);
        }

        private void bRight_Click(object sender, EventArgs e)
        {
            if ((DateTime.Now - startTime).Milliseconds <= 150)
            {
                if (selectedIndex < panel.Controls.Count - 1)
                    selectedIndex++;
                CambiarSeleccion(selectedIndex);
            }
        }

        private void bLeft_Click(object sender, EventArgs e)
        {
            if ((DateTime.Now - startTime).Milliseconds <= 150)
            {
                if (selectedIndex > 0)
                    selectedIndex--;
                CambiarSeleccion(selectedIndex);
            }
        }

        private void CambiarSeleccion(int newIndex)
        {
            if (selectedIndex >= 0 && selectedIndex <= panel.Controls.Count || panel.Controls.Count != 0)
            {
                if (selectedItem != null)
                    selectedItem.Deseleccionar();

                CallListener();

                selectedItem = GetTabItem(selectedIndex);
                selectedItem.Seleccionar();
                panel.Left = -selectedIndex * (ItemWidth + 6) - 2;
            }
        }

        public void SetActivado(bool activo)
        {
            bLeft.Enabled = activo;
            bRight.Enabled = activo;
        }
    }

    public interface TabListener
    {
        void OnItemSelected(int selected);
    }
}

Now i want to translate it to Java. I got all done, but i cannot find something like the Left property to use it. Is there anything that i missed?

A: Finally i got it working, my custom Jpanel got two buttons on west and east, a null layout panel in center and a flow layout panel inside the first panel. When i press the mouse it start slide, to show the DataTabItems (Just another panel with a button). The objetive of this class is to select one item from the list and show something anywhere.
This is the code of DataTab:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.morethansimplycode.crud;

import com.morethansimplycode.data.Data;
import java.awt.Rectangle;
import java.util.List;
import javax.swing.Timer;

/**
 *
 * @author Oscar Date 21-may-2015 Time 22:15:09
 */
public class DataTab extends javax.swing.JPanel {

    private final Timer tLeft = new Timer(6, (e) -> {
        if (DataTab.this.tabContainer.getX() < 0)
            left(5);
        System.out.println("left" + DataTab.this.tabContainer.getX());

    });
    private final Timer tRight = new Timer(6, (e) -> {
        if (DataTab.this.tabContainer.getWidth() >= Math.abs(DataTab.this.tabContainer.getX()) + DataTab.this.panel.getWidth())
            left(-5);
        System.out.println("right" + DataTab.this.tabContainer.getX());
    });

    private Data[] data;

    /**
     * Creates new form DataTab
     */
    public DataTab() {

        initComponents();
    }

    public void setData(Data[] data) {

        this.data = data;
        generateTabItems();
    }

    public void setData(List<Data> data) {

        this.data = data.toArray(new Data[data.size()]);
        generateTabItems();
    }

    private void generateTabItems() {

        tabContainer.setBounds(tabContainer.getBounds().x, tabContainer.getBounds().y,tabContainer.getBounds().width + 10, panel.getBounds().height);

        for (Data d : data) {

            DataTabItem item = new DataTabItem(d, 275, 275);
            tabContainer.add(item);
            tabContainer.setSize(tabContainer.getWidth() + item.getPreferredSize().width + 10, tabContainer.getHeight());
            System.out.println(tabContainer.getComponentCount() + " " + item.getSize());
        }

        this.updateUI();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        bLeft = new javax.swing.JButton();
        bRight = new javax.swing.JButton();
        panel = new javax.swing.JPanel();
        tabContainer = new javax.swing.JPanel();

        setMinimumSize(new java.awt.Dimension(85, 40));
        setPreferredSize(new java.awt.Dimension(200, 20));
        addComponentListener(new java.awt.event.ComponentAdapter() {
            public void componentResized(java.awt.event.ComponentEvent evt) {
                resize(evt);
            }
        });
        setLayout(new java.awt.BorderLayout());

        bLeft.setText("<");
        bLeft.setMargin(new java.awt.Insets(0, 0, 0, 0));
        bLeft.setMaximumSize(new java.awt.Dimension(10, 19));
        bLeft.setMinimumSize(new java.awt.Dimension(10, 19));
        bLeft.setPreferredSize(new java.awt.Dimension(40, 10));
        bLeft.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                bLeftPressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                bLeftReleased(evt);
            }
        });
        bLeft.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bLeftActionPerformed(evt);
            }
        });
        add(bLeft, java.awt.BorderLayout.WEST);

        bRight.setText(">");
        bRight.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                bRightMousePressed(evt);
            }
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                bRightMouseReleased(evt);
            }
        });
        bRight.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bRightActionPerformed(evt);
            }
        });
        add(bRight, java.awt.BorderLayout.EAST);

        panel.setBackground(new java.awt.Color(255, 255, 255));
        panel.setLayout(null);

        tabContainer.setBackground(new java.awt.Color(102, 0, 204));
        tabContainer.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.CENTER, 10, 5));
        panel.add(tabContainer);
        tabContainer.setBounds(0, 0, 0, 40);

        add(panel, java.awt.BorderLayout.CENTER);
    }// </editor-fold>

    private void bRightActionPerformed(java.awt.event.ActionEvent evt) {

    }

    private void bLeftActionPerformed(java.awt.event.ActionEvent evt) {

    }

    private void resize(java.awt.event.ComponentEvent evt) {

        System.out.println(tabContainer.getBounds());
        tabContainer.setBounds(tabContainer.getBounds().x, tabContainer.getBounds().y,tabContainer.getBounds().width, panel.getBounds().height);
        System.out.println(tabContainer.getBounds());
        this.updateUI();
    }

    private void bLeftPressed(java.awt.event.MouseEvent evt) {

        tLeft.start();
    }

    private void bLeftReleased(java.awt.event.MouseEvent evt) {

        tLeft.stop();
    }

    private void bRightMousePressed(java.awt.event.MouseEvent evt) {

        tRight.start();
    }

    private void bRightMouseReleased(java.awt.event.MouseEvent evt) {

        tRight.stop();
    }

    private void left(int movePixels) {

        Rectangle r = tabContainer.getBounds();
        r.x += movePixels;
        tabContainer.setBounds(r);
    }

    // Variables declaration - do not modify
    private javax.swing.JButton bLeft;
    private javax.swing.JButton bRight;
    private javax.swing.JPanel panel;
    private javax.swing.JPanel tabContainer;
    // End of variables declaration

}

And this is the DataTabItem class:
package com.morethansimplycode.crud;

import com.morethansimplycode.data.Data;
import java.awt.Dimension;

/**
 *
 * @author Oscar
 * Date 21-may-2015
 * Time 22:26:21
 */
public class DataTabItem extends javax.swing.JPanel {

    Data value;

    /** Creates new form DataTabItem */
    public DataTabItem() {

        initComponents();
    }

    public DataTabItem(Data d, int height, int width) {

        initComponents();
        value = d;
        button.setPreferredSize(new Dimension(width, height));
        this.setPreferredSize(new Dimension(width, height));
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        button = new javax.swing.JButton();

        setBackground(new java.awt.Color(255, 255, 255));
        setLayout(new java.awt.BorderLayout());

        button.setBackground(new java.awt.Color(102, 102, 255));
        button.setText("PACO");
        button.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        button.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                buttonActionPerformed(evt);
            }
        });
        add(button, java.awt.BorderLayout.CENTER);
    }// </editor-fold>

    private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
        System.out.println("hola");
    }

    // Variables declaration - do not modify
    private javax.swing.JButton button;
    // End of variables declaration

}

Thanks for the other answers and hope that this code help anyone who want this.

A: Swing uses layout managers to place a JPanel in its containing component. Albeit discouraged, you can disable the use of layout managers in a component by setting it to null. If you do so, you can manually set the bounds of the JPanels.
JPanel movingPanel, containingPanel;
/* initialize movingPanel and containingPanel
... */
containingPanel.setLayout(null);
movingPanel.setBounds(yourPanelDotLeft, up, width, heigth);

Example with some arbitrary panels:
import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class SlidingControl {
    Frame frame = new Frame("Sliding Control");
    JPanel left = new JPanel(), right = new JPanel(), middle = new JPanel();

    public static void main(String[] args) {
        SlidingControl application = new SlidingControl();
        application.movePanels();
    }

    public SlidingControl() {
        frame.setSize(600, 200);
        frame.addWindowListener(new WindowAdapter() {
            @Override
            public void windowClosing(WindowEvent e) {
                System.exit(0);
            }
        });
        frame.setResizable(false);
        frame.setVisible(true);
        initializePanels();
    }

    private void initializePanels(){
        frame.setLayout(null);
        frame.add(left);
        frame.add(middle);
        frame.add(right);
        left.setBackground(new Color(1f, 0f, 0f));
        middle.setBackground(new Color(0f, 1f, 0f));
        right.setBackground(new Color(0f, 0f, 1f));
        left.setBounds(10, 10, 50, 100);
        middle.setBounds(400, 50, 50, 200);
        right.setBounds(500, 50, 50, 200);
    }

    public void movePanels(){
        while(true){
            left.setBounds(left.getBounds().x - 5, left.getBounds().y, left.getBounds().width, left.getBounds().height);
            middle.setBounds(middle.getBounds().x - 5, middle.getBounds().y, middle.getBounds().width, middle.getBounds().height);
            right.setBounds(right.getBounds().x - 5, right.getBounds().y, right.getBounds().width, right.getBounds().height);
            try{
                Thread.sleep(600);
            }catch (InterruptedException e){
                e.printStackTrace();
            }
        }
    }
}


text:
Q: Okta how to pass groups in assertion SAML Trying to integrate our organisation's web app with Okta's SSO.
Everything works smoothly except that I can't find a way to pass the native Okta groups which the user is part of in the assertion SAML (there's no such option in the 'Edit SAML Integration' form).
Any idea how to do that?

A: I came across this issue myself, and answered myself here
I added a very detailed explanation how it can be achieved
In short, you just need to specify a groups attribute statement to your Okta SAML 2.0 template specifying what groups you'd like to expose to your SP

A: To have Okta include group information into SAML assertions, you'll need to use the Okta Template SAML 2.0 App, in particular, you'll need to set the Group Name and Group filter options to configure which groups will be included in the SAML assertion.

redpajama_set_name: RedPajamaStackExchange


text:
Q: Which programs will receive auto updates on Ubunutu 16.04 LTS? I am trying to determine which programs will receive auto updates on my Ubunutu 16.04LTS PC.
I have installed these programs via the software center:

*

*filezilla

*gimp

*synaptic

*unetbootin

*virtualbox-qt

I have installed these from command line by adding a ppa and installed using apt:

*

*google-chrome-stable

*sublime-text

When I use Synaptic under the status tab and Installed (manually) if I sort by non-Ubuntu installed I can see all the programs listed above.
If I then click Installed (upgradeable) the only non-Ubuntu installed package is google-chrome-stable.

*

*Why is google-chrome-stable the only one listed as upgradeable?

*How does Synaptic determine a package as 'upgradeable'?

*I assume the software center updates will infact be updated as I think I have seen this in the software center itself, but would that happen through apt-get update?

I am trying to understand if programs installed using these methods are auto updated:

*

*Downloaded via Ubuntu Software Center

*Via command line by adding a PPA and installing

*By downloading a .deb and installing (e.g. Dropbox)

I am correct in thinking that apt-get update will update any software which was installed using an apt command originally?
So if it was a .deb it is installed via dkpg and therefore apt-get wont apply, if so is there anyway to automatically update these?

A: *

*google-chrome-stable is the only outdated package you have in your system (which is not installed by Ubuntu) at that time.

*A package is listed at Installed (upgradeable) means that there is a newer package available and you can upgrade the package. If you had the filter of non-Ubuntu installed, it will only show outdated packages YOU installed.

*Ubuntu Software Center will run apt-get update every time (I think) and detect whether you have software updates or not. Running apt-get update will only update your list of packages, it will not tell you anything about whether you have software updates or not. apt-get upgrade will upgrade packages, which is the same as updating packages from Ubuntu Software Center.

*Packages downloaded via Ubuntu Software Center will be auto-updated because it acts the same as installing with apt-get.

*Packages installed via command line by adding a PPA and installing will also be auto-updated because when running apt-get update, apt-get will also update the list of packages from the PPA.

*Packages installed by downloading a .deb and installing via dpkg -i may get auto-updated depending on whether the repository is added into the list of apt (i.e. /etc/apt/sources.list). Some packages like google-chrome-stable will do so, so they will get updated.
Edit: Ubuntu has a cronjob to run apt-get update everytime you boot up, so all lists of packages will be updated when you boot your computer.


text:
Q: SQL JOIN different tables and show NOT NULL values only I've been trying to show a specific type of result in SQL but haven't been able to. I guess it's possible, but can't figure out how.
I've read this article show only those columns which have data value but couldn't solve my problem.
I have 4 tables: sparametros (holds parameters codes and descriptions), sparametrosnumericos (holds numeric parameters values and their code), sparametrostexto (holds text parameters and their values), sparametrosmemo (holds memo type parameters)
All of them can be joined by their parameter code, however, a parameter code is unique in the sense that for example, given a code, let's say 1210, and let's suppose it's a text type parameter, then that code doesn't exist in numeric nor in memo parameters either. However it exists in the general sparametros table. In other words, sparametros holds all parameters, and the other tables represent sub sets of that main set.
I've tried using left join, but couldn't get results.
This is what I have so far:
SELECT P.SPar00Id, P.SPar00Descripcion,
IF NOT ISNULL(N.SPar00NumValor) THEN
        N.SPar00NumValor
ELSEIF NOT ISNULL(T.SPar00TextoValor) THEN
        T.SPar00TextoValor
ELSE
        M.SPar00MemoValor
FROM sparametros p
LEFT JOIN sparametrosnumericos N ON N.SPar00NumId = P.SPar00Id
LEFT JOIN sparametrostexto T ON T.SPar00TextoId = P.SPar00Id
LEFT JOIN sparametrosmemo M ON M.SPar00MemoId = P.SPar00Id
WHERE P.SIns00Id = 1 AND
            N.SIns00Id = 1 AND
            T.SIns00Id = 1 AND
            M.SIns00Id = 1;

I'm using MySQL now (with the Navicat client), but also need to be able to get the same results in SQL Server.
The response I'm getting when executing this request is:
"[Err] 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NOT ISNULL(N.SPar00NumValor) THEN "

A: Try this:
SELECT P.SPar00Id, P.SPar00Descripcion,
      (CASE WHEN N.SPar00NumValor IS NOT NULL THEN N.SPar00NumValor
            WHEN T.SPar00TextoValor IS NOT NULL THEN T.SPar00TextoValor
            ELSE M.SPar00MemoValor
       END) colName
FROM sparametros p
LEFT JOIN sparametrosnumericos N ON N.SPar00NumId = P.SPar00Id
LEFT JOIN sparametrostexto T ON T.SPar00TextoId = P.SPar00Id
LEFT JOIN sparametrosmemo M ON M.SPar00MemoId = P.SPar00Id
WHERE P.SIns00Id = 1 AND N.SIns00Id = 1 AND T.SIns00Id = 1 AND M.SIns00Id = 1;


text:
Q: ElasticSearch RestHighLevelClient search with wildcard not working I'm trying to search with wildcard "*" in Java application, using ElasticSearch's RestHighLevelClient API. But not getting any match.
Data on the index:
JEAN
JEAN CHRISTOPHER
JEAN SOMETHING ELSE

Searching using URL API:
http://mylocal-es-server.com/myindex/_search?q=firstName:JEAN*&pretty // 2 hits

JAVA code (updated):
public SearchResponse preciseSearch(PreciseSearchRequest req) throws IOException {
    // convert my req to org.elasticsearch.action.search.SearchRequest:
    SearchRequest searchReq = createSearchRequest(req);
    // print searchReq (see below)
    return restHighLevelClient.search(searchReq, RequestOptions.DEFAULT); // returns 0 hit
}

PRINT searchReq:
{"from":0,"size":1000,"query":{"query":"(firstName:(\"JEAN*\"))","fields:[],"type":"best_fields","default_operator":"or","max_determinzed_states":10000,"enable_position_increments":true,"fuzziness":"AUTO","fuzzy_prefix_length":0,"fuzzy_max_expansions":50,"phrase_slop":0,"escape":false,"auto_generate_synonyms_phrase_query":true,"fuzzy_transpositions":true,"boost":1.0}},"sort":[{"age":{"order":"desc"}}]}

Index mapping:
"firstName" : { "type": "keyword" }

I suspect it is due to type = keyword instead of text. But then how come searching using URL works fine?
Any pointers appreciated! I'm a ES beginner!
Thanks

A:
"firstName" : { "type": "keyword" }

In Elastic Search, Keyword fields are not analyzed and they are case sensitive.
a) Indexing Time: 'JEAN' will be indexed as 'JEAN' and not jean
b) Search Time: 'JEAN' will look for 'JEAN' and not 'jean' or 'Jean' or 'jEAN' etc
However, ES also provides support for keyword normalization. See this and play around with it.

... "query":{"query_string":{"query":"(firstName:("jean*"))" ... //
0 hit

0 hits as JEAN is not normalized & analyzed before storing (case-sensitivity).

... "query":{"query_string":{"query":"(firstName:("JEAN"))" ... // 1
hit

1 hit due to exact match with JEAN.

... "query":{"query_string":{"query":"(firstName:("JEAN*"))" ... //
0 hit

It is returning 3 hits for me as it should.

A: OK I found the issue..
There was a piece of code that wraps the value with double quote. The double quote works fine on its own, but when there's wildcard, it doesn't work.
I had:
"query":"(firstName:(\"JEAN*\"))"

It should be:
"query":"(firstName:(JEAN*))"


text:
Q: How to maintain the "content" source-code of a Nuget package? I am in process of setting up a whole series of NuGet packages for our framework. Beside the simple binary-packages (.dll's for modules of the framework) there are also packages that deliver source-code into the projects that are using them done with the \content directory in the NuGet package.
To develop this source-code I have a test-/sandbox project. I develop/debug/fix the code in this peoject and if its final for the next release, I copy it over to the package's content-folder where I replace things like $rootnamespace$ etc. This needs to be done for each and every version of the package.
Another way is to keep only the final source with the $rootnamespace$ tags in it and maintain that directly. But then testing/debugging would be done by re-adding the package to a test-project and debug it there, go pack to the package content, modify it, re-build and re-add and test it again.
So I see two ways to maintain the content-sourccode (none of them is really good):

*

*Keep source-code in \content as small as possible and deploy as much as possible as binaries.

*Generate the \content using some transformation engine (eg. T4) from the sandbox/dev-project. What engine would be best to use for this?
In short: I didn't find a good workflow yet to maintain the "content" source-code of NuGet packages. How are you guys doing this? Any ideas for that workflow?

A: Check the http://github.com/maartenba/MvcSiteMapProvider build. It is customized quite a bit but basically does a find/replace on several namespaces and replaces them with replacement tokens right before packaging.


text:
Q: Using tidyeval's braces with a dplyr::group_by I wanted to pass a vector of strings to purrr::map to generate a list of tables.
library(tidyverse)
library(magrittr)

names(mtcars) %>%
  extract(8:10) %>%
  map(
   function(i)

     mtcars %>%
     group_by({{i}}) %>%
     tally
   )

but this returns objects grouped on a character string, not the variable name.
This works
names(mtcars) %>%
  extract(8:10) %>%
  map(
    function(i)

      mtcars %>%
      group_by(get(i)) %>%
      tally
    )

but I was hoping for a solution with a more idiomatically tidy approach.

A: Use !!sym(i) instead. I don't fully understand why this works, but I guess you need to create a symbol from your string first and then have to quasi-quote it in order to be able to replace it with your placeholder in the function. If this makes sense.

library(tidyverse)

names(mtcars)[8:10] %>%
  map(
    function(i)

      mtcars %>%
      group_by(!!sym(i)) %>%
      tally
  )
#> [[1]]
#> # A tibble: 2 x 2
#>      vs     n
#>   <dbl> <int>
#> 1     0    18
#> 2     1    14
#>
#> [[2]]
#> # A tibble: 2 x 2
#>      am     n
#>   <dbl> <int>
#> 1     0    19
#> 2     1    13
#>
#> [[3]]
#> # A tibble: 3 x 2
#>    gear     n
#>   <dbl> <int>
#> 1     3    15
#> 2     4    12
#> 3     5     5

Created on 2019-11-25 by the reprex package (v0.2.1)


text:
Q: If js disabled, how to show php-generated site? I have a full js/jquery based WebSite!
Today i become an E-mail, "i have js disabled..."
How can i check at start, if js is disabled, so locate from index.html to some.php?
for google robot too!
Thx in ahead!

A: Well, php has no way of checking if Javascript is disabled or not. But what you could is starting the page on a index.php and putting in a js script that redirects you to the 'real' website. so if javascript is disabled you wont be redirected and you stay on the php page and otherwise you go to the js website


text:
Q: "type mismatch: cannot convert from int to byte" new to Java and so far struggling a lot.. tried all day to fix this error yesterday and to no avail... any help will be appreciated.
import java.util.Random;
import java.util.Date;
class Proj06{
  public static void main(String[] args){
    Random generator = null;
    if(args.length != 0){
      generator = new Random(Long.parseLong(args[0]));
    }else{
      generator = new Random(new Date().getTime());
    };

    //Get and save positive random number of type int.
    int valA = Math.abs((generator.nextInt()))/67000 + 1024;

    Proj06Runner obj = new Proj06Runner();

    String valB = obj.run("certificaton");
    String valC = obj.run(1,"name");
    byte valD =   obj.run(valA);

    //Print the original random integer
    System.out.println(valA);

    //Print the three values returned from the three calls
    // to the run method.
    System.out.println(valB);
    System.out.println(valC);
    System.out.println(valD);

    //Print the original random integer after casting it
    // down to type byte.
    //System.out.println((byte)valA);

  }//end main

public class Proj06Runner extends Proj06{
  public int run(int valA){
    return valA;
  }
  public String run(String valB){
    return "this works";
  }
  public String run(int i, String valC){
    return "this also works";
  }
//this does not work
  public byte run(byte valD){
    return valD;
  }

}

I can't change anything in main..i know there's an error with how valA is an int but i'm assigning it to a byte variable

A: Your Proj06Runner class has these two methods:
  public int run(int valA){
    return valA;
  }
  public byte run(byte valD){
    return valD;
  }

First one takes an int and returns an int. The second one takes a byte and returns a byte. You are calling the first one. I suspect you expected to call the second one, but that will not work because the main method is passing an int as the parameter.
One way to fix the compiler error is to "merge" these two methods into one method that takes an int and returns a byte. For example:
  public byte run(int valD){
    return (byte) valD;
  }


text:
Q: Error with friend non-member function which gives a segmentation fault For this project we are suppose to cover the topic of dynamic memory allocation and deallocation. The functionality of the 'operator<<; is to output(to terminal or file depending on the type of ostream& os object passed as a parameter to it) the MyString data (the C-string representation held within m_buffer). Right after my program prints to the Terminal "Access Successful." I receive a Segmentation fault (core dumped) I am quite sure that it have something to do with the operator << but I do not know how to fix this. Hence, it fails to print "Testing Operator <<()". Any Suggestions? Thank you!
//int main
int main(){
std::cout << "Testing operator[]()" << std::endl;
MyString ms_access("Access successful (NOT)");
ms_access[17] = 0;

std::cout << "Testing operator<<()" << std::endl;
cout << ms_access << endl;
}

class MyString{

 public:
MyString();
MyString(const char * str);
MyString(const MyString & other_myStr);
~MyString();

size_t size() const;
size_t length() const;
const char * c_str() const;

bool operator== (const MyString & other_myStr) const;
MyString & operator= (const MyString & other_myStr);
MyString operator+ (const MyString & other_myStr) const;
char & operator[] (size_t index);
const char & operator[] (size_t index) const;

friend std::ostream & operator<<(std::ostream & os, const MyString & myStr);

  private:
   void buffer_deallocate();
   void buffer_allocate(size_t size);

   char * m_buffer;
   size_t m_size;
};

//definition
std::ostream& operator<<(std::ostream& os, const MyString& myStr){
//if(os == std::cout){
os << myStr.m_buffer << std::endl;
//}
}

//will allow by-reference accessing of a specific character at index size_tindexwithin the allocated m_bufferchar arrayof a non-constqualified object.
char& MyString::operator[](size_t index){
size_t counter = 0;
while(counter != index){
    counter++;
}
return m_buffer[counter];
}

//will allow by-reference accessing of a specific character at index size_tindexwithin the allocated m_bufferchar array of a constqualified object.
const char& MyString::operator[](size_t index)const{
size_t counter = 0;
while(counter != index){
    counter++;
}
return m_buffer[counter];
}

void MyString::buffer_deallocate(){
if(m_buffer != NULL){
delete [] m_buffer;
}
}
void MyString::buffer_allocate(size_t size){
if(m_buffer != NULL){
    buffer_deallocate();
}
m_size = size;
m_buffer = new char[m_size];

}
MyString::MyString(){
m_size = 0;
m_buffer = NULL;
 }
MyString::MyString(const char *str){
m_buffer = NULL;
m_size = strlen(str);
buffer_allocate(m_size);
strcpy(m_buffer,str);
}
 MyString::MyString(const MyString &other){
m_buffer = NULL;
m_size = other.m_size;
buffer_allocate(m_size);
strcpy(m_buffer,other.m_buffer);
}

size_t MyString::size()const{
return m_size;
}
size_t MyString::length(){
return strlen(m_buffer)-1;
 }
 const char* MyString::c_str() const {
char *str = NULL;

    str = new char[m_size];
    for(size_t i = 0; i < m_size;i++){
        str[i] = *(m_buffer+i);
    }
    return str;
    delete [] str;
    str = NULL;

}
bool MyString::operator==(const MyString & other)const{
if(strcmp(m_buffer,other.m_buffer) == 0){
    return true;
}else if (strcmp(m_buffer,other.m_buffer) != 0){
    return false;
}
}
MyString & MyString::operator=(const MyString & str1){
buffer_deallocate();
m_buffer = new char[str1.m_size];
strcpy(m_buffer,str1.m_buffer);

}
MyString MyString::operator+(const MyString & other_myStr)const{
MyString myStr(strcat(m_buffer,other_myStr.m_buffer));
return myStr;

}


text:
Q: EPERM Error using fs.rename() Here is my code:
exports.post_handler = function(req, res) {
    var photo = req.files.image;
    console.log(photo);
    console.log(__dirname);

    fs.readFile(photo.path, function(err, data) { //I use the path module to join the image path strings
        fs.rename(path.join(__dirname, "public/temp"), path.join(__dirname,"public/images"), function(err) {
            if (err) {
                console.log(err);
                res.redirect("/");
            }
            else {
                console.log("file " + photo.name + "written to uploads folder");
                res.redirect("/home");
            }
        });
    });
}

I'm trying to move an uploaded image file from  my temp folder to my uploads folder. I'm using the fs module to do this. After granting full permissions to both files to all users on my PC, I'm getting the following error:
{ [Error: EPERM, rename 'dir\public\temp']
  errno: 50,
  code: 'EPERM',
  path: 'dir\\public\\temp' }

I'm not sure what's going wrong here. Anyone have any ideas?

A: What your code is trying to do is rename the public/temp directory to public/images. public/images presumably already exists, so you're getting that error. In other words, nowhere in there are you moving the image, you're instead 'moving' (renaming) the directory public/temp to public/images.
You have to use photo.path instead. Use it as the first parameter and then perhaps the second parameter should path.join images directory to path.basename(photos.path).


text:
Q: Update build properties on page refresh I'm trying to set up behavior, if new file appeared in folder, Buildbot updates choices in it's web GUI(e.g. on page refresh)
scheduler section in master.cfg looks as follows:
c['schedulers'].append(
    ForceScheduler(name = name, builderNames = builderNames
        properties=[
        ChoiceStringParameter(name="version",
            choices = os.listdir(r"\path\to\folder"),
            label="Version of validator")
    ]))
The problem with code, that buildbot doesn't pull updates after page reload.
Please, share any advice how this behavior can be achived
Thanks in advance


text:
Q: How to get a simple plot with pyqtgraph I have this code:
plot = pg.PlotItem()
plot.plot([1,2,3,4], [3,4,5,6], symbol='o')
viewer = pg.ImageView(view=plot)
self.tabLOs["Server"].addWidget(viewer)

to do a quick proof-of-concept for making a few simple graphs to display system data.  I want a very simple graph that I can update as the data comes in.  The code above gives me a graph but with an interactive area to the right.  I've found other classes that give me just graphs, but they aren't able to be used with addWidget and/or have the plot() method.  Is there a PlotItem equivalent that doesn't have all the extra stuff that I can just add to an existing layout with addWidget?
EDIT: pg is from "import pyqtgraph as pg" and tabLOs["Server"] is just a VBox layout.

A: I think you want to create a pg.PlotWidget which can be added to your QVBoxLayout. You can then get the plot item using my_plot_widget.getPlotItem() (this method negates the need to create your own PlotItem).


text:
Q: Python Basemap plots text or annotate at lower left only the problem is basemap/matplotlib plots a given text always on the lower left corner...
i tried many ways but that doesnt work:
# Set up plot
fig, ax = plt.subplots(figsize=(15,15))

m1 = Basemap(projection='merc',
             llcrnrlat=8.3,
             urcrnrlat=53.9,
             llcrnrlon=94.0,
             urcrnrlon=147.6,
             lat_ts=0,
             resolution='c')

m1.fillcontinents(color='#191919',lake_color='#000000') # dark grey land, black lakes
m1.drawmapboundary(fill_color='#000000')                # black background
m1.drawcountries(linewidth=0.1, color="w")              # thin white line for country borders
m1.drawstates(linewidth=0.1, color="w")

# Plot the data
mxy = m1(new_results["Longitude"].tolist(), new_results["Latitude"].tolist())
m1.scatter(mxy[0], mxy[1], s=300,c=np.divide(new_results["SumVolume"],100000000), lw=0, alpha=1, zorder=5,cmap='Reds')
ax.annotate("blablabla", (121.597366,25.105497),color='green')

#colorbar
plt.colorbar(label=r'24H Trading-Volume in MillionK$')
plt.clim(1, 21)
plt.title("Cryptocurrency capital movement - Asia")

The Plot:

Whats the problem?
    ax.annotate("blablabla", (121.597366,25.105497),color='green')

doesnt work like i want. the coordinates (121.597366,25.105497) is one point on the map. By the way, it does not matter which X, Y. He always writes it in the bottom left corner

A: As my comment has been confirmed, I should conclude that the fix to the problem is concerning coordinate transformation. And the new code for the troubled part is:
ax.annotate("blablabla", m1(121.597366,25.105497),color='green')


text:
Q: Expandable List view with different children I am trying to make the last child of every group and edit text and a button. I am using a custom ExpandableListViewAdapter. This is what I have so far.
  public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
    {
        if (convertView == null)
        {
            LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
            convertView = inflater.Inflate(Resource.Layout.Children, null);
        }
        if (isLastChild==true)
        {
            EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
            Button button = convertView.FindViewById<Button>(Resource.Id.Button);
            TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
            textViewItem.Visibility = ViewStates.Gone;
        }

        else {
            TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
            EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
            Button button = convertView.FindViewById<Button>(Resource.Id.Button);
            button.Visibility = ViewStates.Gone;
            Submit.Visibility = ViewStates.Gone;
            string content = (string)GetChild(groupPosition, childPosition);
            textViewItem.Text = content;
        }
        return convertView;
    }

This helps put a EditText and Button but only in the first group while also cutting off some of the children in the first group.

A:
This helps put a EditText and Button but only in the first group while also cutting off some of the children in the first group.

ExpandableListView reuses the childview, so if you want the last line to be your button and edittext, you need to set it to visible explicitly. Just add three lines of codes to your GetChildView method:
public override View GetChildView(int groupPosition, int childPosition, bool isLastChild, View convertView, ViewGroup parent)
{
    if (convertView == null)
    {
        LayoutInflater inflater = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
        convertView = inflater.Inflate(Resource.Layout.Children, null);
    }
    if (isLastChild == true)
    {
        EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
        Button button = convertView.FindViewById<Button>(Resource.Id.Button);

        //add below two lines to your codes
        Submit.Visibility = ViewStates.Visible;
        button.Visibility = ViewStates.Visible;

        TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
        textViewItem.Visibility = ViewStates.Gone;
    }
    else
    {
        TextView textViewItem = convertView.FindViewById<TextView>(Resource.Id.DataValue);
        EditText Submit = convertView.FindViewById<EditText>(Resource.Id.Submit);
        Button button = convertView.FindViewById<Button>(Resource.Id.Button);
        button.Visibility = ViewStates.Gone;
        Submit.Visibility = ViewStates.Gone;
        //also add below line of codes
        textViewItem.Visibility = ViewStates.Visible;

        string content = (string)GetChild(groupPosition, childPosition);
        textViewItem.Text = content;
    }
    return convertView;
}


text:
Q: Find missing days in R Date sequence let's say I have a series of dates in R, like so:
d <- as.Date(c('2001-01-01', '2001-01-02', '2001-01-04', '2001-01-05'))

The date 2001-01-03 is missing. Is there a quick way to identify this? In reality I have a much longer series than just 4 observations.

A: You could create a range of dates based on the min and max dates in your vector and check with %in% which dates are missing.
d <- c('2001-01-01', '2001-01-02', '2001-01-04', '2001-01-05')
d <- as.Date(d)
date_range <- seq(min(d), max(d), by = 1)
date_range[!date_range %in% d]
[1] "2001-01-03"


text:
Q: Managing channels using a HTTP request context I have a basic HTTP server that accepts a request and returns data from a data store.
Each HTTP request does the following things:

*

*Create a context with timeout

*Create a read request (custom type)

*Push read request onto channel

*Wait for response and serve data

Here's the basic pseudo code:
package main

import (
    "context"
    "net/http"
    "time"
)

type dataRequest struct {
    data chan string
    ctx  context.Context
}

func handler(reqStream chan dataRequest) http.HandlerFunc {
    return func(w http.ResponseWriter, r *http.Request) {
        ctx, cancel := context.WithTimeout(r.Context(), 5*time.Second)
        defer cancel()

        req := dataRequest{
            data: make(chan string),
            ctx:  ctx,
        }

        select {
        case reqStream <- req:
            // request pushed to que
        case <-ctx.Done():
            // don't push onto reqStream if ctx done
        }

        select {
        case <-ctx.Done():
            // don't try and serve content if ctx done
        case data := <-req.data:
            // return data to client
        }

    }
}

func main() {
    dataReqs := make(chan dataRequest)
    go func() {
        for {
            select {
            case req := <-dataReqs:
                select {
                case <-req.ctx.Done():
                    // don't push onto data channel if ctx done
                case req.data <- "some data":
                    // get data from store
                }
            }
        }
    }()
    http.HandleFunc("/", handler(dataReqs))
    http.ListenAndServe(":8080", nil)
}

My question is, because the context could finish at any time due to the deadline being exceeded or the client cancelling the request, is my current approach correct for handling this in multiple places or is there a more elegant solution?

A: seems to me that it'll work.
few comments -

*

*you can return in the first case of <- ctx.Done()

*you're already waiting for req.ctx.Done() in the data store handler so you can completely remove the first select {} statement and just publish to the data requests channel. not sure about performance hits for the rare cases when the context is done so early before the request is even published...


text:
Q: Google prettify not showing colors I cant seem to find whats wrong. I have this html file used with google prettify. Both prettify.css and  prettify.js are in the same directory as the html file

<link rel=StyleSheet href="prettify.css" type="text/css">

//Some sample text
for(int i = 0; i<10; i++){
    //Do something
}

And this is what it looks like

What am I missing to have the colors showing?
Thanks

A: Add onload="prettyPrint()" to your document's body tag.

A: Here's the code that will do the proper syntax highlighting

   //Some sample text
   for(int i = 0; i<10; i++){
     //Do something
   }

See the code live here


text:
Q: Dirac's equation, boosts and rotations If we consider Dirac's equation in two different frames of reference $$\left(i\gamma^{\mu} \partial_{\mu}-m c\right) \psi(x)=0,$$ $$\left(i\gamma^{\mu} \partial_{\mu}^{\prime}-m c\right) \psi^{\prime}\left(x^{\prime}\right)=0,$$ $S$ should be the matrix such that $$\psi^{\prime}\left(x^{\prime}\right)=\psi^{\prime}(a x)=S(a) \psi(x)=S(a) \psi\left(a^{-1} x^{\prime}\right),$$ and it should depend only on relative speeds and/or rotations between referentials $O$ and $O'$.
So if we have a generic $S=e^{-\frac{i}{4} \sigma_{\mu v} \omega^{\mu v}}$, we should have two distinct cases $S_L$ exclusively for the case of Lorentz transformations, and $S_R$ exclusively for the case of rotations. Note that both $\sigma_{\mu\nu}$ and $\omega^{\mu\nu}$ are $\textit{anti}$-symmetric, and $\sigma_{\mu\nu}$ is the commutator $\sigma_{\mu\nu} = \frac{i}{2}[\gamma_{\mu},\gamma_{\nu}]$.
For the case of boosts alone, one of the indices has to be zero. In this case $$\sigma_{0,i} = \frac{i}{2}[\gamma_0,\gamma_i] = i\gamma_0\gamma_i = i\alpha_i.$$
Now, if we develop $S$ in order for it to be $S_L$, i.e., have one index be zero, we get, $$S_L = e^{-\frac{i}{4}(\sigma_{01}\omega^{01} + \sigma_{02}\omega^{02} + \sigma_{03}\omega^{03} + \sigma_{10}\omega^{10} + \sigma_{20}\omega^{20} + \sigma_{30}\omega^{30})},$$ which, because of anti-symmetry, is just $$e^{-\frac{i}{2}(\sigma_{01}\omega^{01} + \sigma_{02}\omega^{02} + \sigma_{03}\omega^{03})} = e^{-\frac{i}{2}\vec{\sigma}\cdot\vec{\omega}} = e^{\frac{1}{2}\vec{\alpha}\cdot\vec{\omega}}.$$
I am, however, supposed to prove that $S_{L}=e^{-\frac{1}{2} \vec{\omega} \cdot \vec{\alpha}}$. How do I do this?. Do I have to calculate a commutator or anything of that sort? Or have I made a mistake  anywhere in this calculation? I am also not entirely sure what $\omega^{\mu\nu}$ is, since it is defined as such in an infinitesimal transformation: $a^{\mu\nu}=g^{\mu\nu}+\omega^{\mu\nu}+\cdots$.

A: I hope this will help, but I am only familiar with a simpler argument.
The Dirac gamma matrices are not a vector, and do not define a direction in space, but they have properties under Lorentz transform which enable them to be treated as vectors. Specifically, if $f$ is a Dirac spinor, then $\gamma^a f$ transforms as a vector multiplied by a Dirac spinor. This is because, under a Lorentz transform, $k^{m'}_a$, the transformed gamma matrices also obey the defining relations, $$\{k^{m'}_a\gamma^a, k^{n'}_b\gamma^b\} = k^{m'}_ak^{n'}_b\{\gamma^a, \gamma^b\} = 2k^{m'}_ak^{n'}_b g^{ab} = 2g^{m'n'}  .$$ Thus, the transformed gamma matrices are simply another representation of the
gamma matrices. Since the representation has no meaning, the Dirac equation is
covariant (alternatively, we may regard this as a proof from covariance that the
specific representation is meaningless).


text:
Q: Could not find a version that satisfies the requirement search (from versions: ) No matching distribution found for search pip install search gives error like that:

Could not find a version that satisfies the requirement search (from versions: )
  No matching distribution found for search

A: You are getting that error because PyPi cannot provide any compatible installation files.
There is a search package on PyPi: https://pypi.org/project/search/. It seems it's a dead package, as it does not contain a description, provide downloadable source codes, or link to a code repository. Its only version was released in 2012 and the homepage link leads to MailQQ login page.
Maybe you are looking for some other search-* package.

A: I assume you are experiencing issues with launching codimension:
https://github.com/SergeySatskiy/codimension
Issue appears because pip installer does not copy "search" folder from this project, you need to manually copy it from git to fix the issue.


text:
Q: Show multiple images from Strapi API in NextJS Frontend I want to add a carousel to a dynamic [slug.js] page in NextJS. I am using Tailwind to style my pages and Strapi in my API. I am able to get one picture with           src={http://localhost:1337${activity.titlePicture[0].formats.large.url}}, but I do not know how I can get more than 1 picture. In the database titlePicture has multiple images. How can I get all the pictures of my API into the carousel?

A: You will have to use map function , as titlePicture is an array. Since map calls a function once for each element in an array. So I guess it goes as follows:
{activity.titlePicture.map((category) => (<img src={http://localhost:1337${category.formats.large.url})}

Here I have used category , you can use any other word instead of category. So map function will ensure and call each element.
I hope this answers your queries.

A: All you need to do is to configure the rewrites in your next app to forward all requests to the Strapi server.
To do this you need to update your next.config.js file and add the following:

module.exports = {
  ...
  async rewrites() {
    return [{
      source: "/uploads/:slug",
      destination: "http://127.0.0.1:1337/uploads/:slug",
    }, ];
  },
  ...
}

Your NextJS app will redirect all requests that will start with /uploads/* to your Strapi server that will return the image from static assets folder, which is strapiApp/public/uploads
Then you can just use the data from your Strapi API like this:

<Image
  src = {data.img.url}
  ...
/>


text:
Q: How to show Chinese characters in Matplotlib graphs? I want to make a graph based on a data frame that has a column with Chinese characters. But the characters won't show on the graph, and I received this error.
C:\Users\march\anaconda3\lib\site-packages\matplotlib\backends\backend_agg.py:238: RuntimeWarning: Glyph 19996 missing from current font.
  font.set_text(s, 0.0, flags=flags

this is the picture of the graph.
Thanks in advance!

A: You will need to ensure that you are using a font that has the glyphs you want to use. Take a look at text with non-latin glyphs
From the above link:

As of v2.0 the default font, DejaVu, contains glyphs for many western alphabets, but not other scripts, such as Chinese, Korean, or Japanese.
To set the default font to be one that supports the code points you need, prepend the font name to 'font.family' or the desired alias lists

import matplotlib
matplotlib.rcParams['font.sans-serif'] = ['Source Han Sans TW', 'sans-serif']


text:
Q: Connectivity of Hive and Hdinsight with python on Azure I want to connect the hive with hdinsight cluster with python script, but due to access issue not able to  access cluster dashboard which will give me JDBC url information which helps in making the connection with hive.
Can anyone please help/recommend me the ways to connect hive with hdinsight cluster with help of python.
import jaydebeapi
conn = jaydebeapi.connect("org.apache.hive.jdbc.HiveDriver",
       "jdbc:hive2://16.4.5.492:451/default/;ssl=true;transportMode=http;httpPath=/hive2",
       ['Username', 'Password'],
       ["/jdbc/hive-jdbc-1.2.1-standalone.jar",
        "/jdbc/httpclient-4.4.jar",
        "/jdbc/httpcore-4.4.4.jar"])

A: WebHCat is a REST API for HCatalog, a table, and storage management layer for Apache Hadoop. WebHCat is enabled by default on HDInsight clusters, and is used by various tools to submit jobs, get job status, etc. without logging in to the cluster. So in a nutshell you can use WebHCat to run the Hive QL in Python.
Additional reference:
https://cwiki.apache.org/confluence/display/Hive/WebHCat
https://social.msdn.microsoft.com/Forums/en-US/b8026143-975f-46c9-b937-99f604e3b757/connect-to-hive-in-hdinsight-using-python-app-on-remote-linuxbased-server?forum=hdinsight
Additionally you can refer below documentation for making it work with JDBC driver:
https://github.com/uglide/azure-content/blob/master/articles/hdinsight/hdinsight-connect-hive-jdbc-driver.md
I haven't tried this but once the configuration is completed, you should be able to use below code for querying .
import jaydebeapi
conn = jaydebeapi.connect("org.apache.hive.jdbc.HiveDriver",
       "jdbc:hive2://my_ip_or_url:443/;ssl=true;transportMode=http;httpPath=/hive2",
       [username, password],
       "/jdbc/hive-jdbc-1.2.1.jar")

Hope it helps.


text:
Q: Steam achievements not unlocking on all devices I have Steam account on multiple PC devices. Through my Steam client i installed a game on these devices. My game code is trying to unlock some achievements. These are getting unlocked on one device but not on the other. I made sure I am in online mode when unlocking the achievements. Also the achievements in question are straightforward gameplay and dont read stored stats (which are particular to the device). So technically if a gameplay code is triggered, the achievements should be unlocked. Why are these achievements getting unlocked on one device and not the other, although they are installed from the same account?
My unity code is:
if (SteamManager.Initialized) {
    SteamUserStats.GetAchievement (achievementId, out isAchievementUnlocked);
    if (!isAchievementUnlocked) {
        SteamUserStats.SetAchievement (achievementId);
        SteamUserStats.StoreStats ();
    }
}


text:
Q: How is the connection to a Faye server working on Heroku? I've understood that Heroku does not offer support for websockets, and still one can run a Faye server, and have realtime notifications on the client side.
How is this working, more specifically from a client's browser point of view? Is it supported across all major browsers? Is it falling back to another "protocol" different than the websocket one?

A: You can disable Faye's websocket support client-side with:
client.disable('websocket');

As discussed in their docs: http://faye.jcoglan.com/browser.html In that case it falls back to long-polling as the protocol.
This is a common fallback approach and is used by other real-time messaging libraries such as Socket.io.
Hope that helps!


text:
Q: Xcode 5 compilation I've got a project which is going to be a c++ library for use in other c++ code.
It's made of a single .cpp implementation file and a single .h file for the interface. Normally I'd just compile the .cpp implementation file and then link it with other files with g++ in something like Ubuntu, however in Xcode 5 there's the Option Product>Build, Product>Build for... Running,testing, profiling and then there are the Perform action options to compile analyse, pre-process and assemble individual files. So with Xcode 5 how exactly do I complete my c++ library project in that I can then include it in other programs? And what happens when I use the options mentioned above like build and compile, because I see no new output files even though the build is successful - I'm guessing they go somewhere else I don't know about. I've googled this but I mostly find Xcode 4 stuff.
Thanks,
Ben.


text:
Q: Android Internal File Storage or SQLite? I am developing an Android application. This app deals with contact information (name, number, photo), which I need to store locally for later processing. This data also needs to be modified frequently.
What would be a good way to achieve this? I was thinking of "File input stream Internal file storage(achieved by serialized)" and SQLite, but am confused about both of them.
Can anyone tell me the difference between these two in terms of performance, speed, memory consumption etc.?
(Besides, what is SQLite3?)

A: (My personal opinion)
Database is slow compare to File but it help you in getting data in arranging formats and easily you can perform any aggregate function on it. I suggest you to use Database in your requirements. As you can store particular record in arranged format.
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.

A: as your data is like contact information name, number, photo for any people so prefer  SQlite it will be easy and effiecent  to add update and delete
Consider the point native Contact also uses the SQlite for same type of data set


text:
Q: API Limit Issue We are getting API Limit exception and I am not able to see which job/application is creating this issue. I am not able to see any debug log or scheduled jobs/Apex Jobs/Background Jobs/Bulk Data Load jobs.
Can anyone help me out how to check this issue. I searched some blogs but not able to get correct information. I don't have much information to share on this issue.

A: There is a built-in report that breaks down your API usage over the last 7 days.  You can find it and save it by going to this url:
https://#####.salesforce.com/00O?rt=104&retURL=%2F00O&c=UN&c=FULL_NAME&c=EM&c=CID&c=TS&c=CC&duel0=FULL_NAME%2CUN%2CEM&scope=organization&details=yes

You'll need to replace ##### with your Salesforce instance or MyDomain.  It's a pretty limited report and will only break down the usage by day, but it will show you which user and application is using the API most.

A: I've written about this in Monitoring your Salesforce API usage.
In addition to the API Usage Last 7 Days report the Drew pointed out there are a few other options.
You can get real time usage data directly via the API from both the REST API and the SOAP API.
If you really want detailed information you can use the Event Monitoring API (which will be a paid feature). This will give details right down to every request being made.


text:
Q: Use application.properties to initialize an object I use @Autowired in my spring boot application to initialize some properties.
I know how i can initialize primitive datatypes but i don't know how to initialize objects.
That's my Component:
@Component
@ConfigurationProperties(prefix = "bitmovin.bitmovin")
public class BitmovinConfig {

    private S3InputConfig S3InputConfig = new S3InputConfig();
    private int threadPoolSize;
    private ArrayList<String> testFiles;

    public BitmovinConfig() {
    }

    public S3InputConfig getS3InputConfig() {
        return S3InputConfig;
    }

    public void setS3InputConfig(S3InputConfig s3InputConfig) {
        S3InputConfig = s3InputConfig;
    }

    public int getThreadPoolSize() {
        return threadPoolSize;
    }

    public void setThreadPoolSize(int threadPoolSize) {
        this.threadPoolSize = threadPoolSize;
    }

    public ArrayList<String> getTestFiles() {
        return testFiles;
    }

    public void setTestFiles(ArrayList<String> testFiles) {
        this.testFiles = testFiles;
    }
}

And that's my application.propertiesfile:
bitmovin.bitmovin.threadPoolSize = 30
bitmovin.bitmovin.S3InputConfig = ??
bitmovin.bitmovin.testFiles= ??

How can i initialize an object or a list in application.properties?

UPDATE

The Object, which i didn't create myself, i want to initialize:
public class S3OutputConfig {
    @Expose
    public String name;
    @Expose
    public S3Region region;
    @Expose
    public String accessKey;
    @Expose
    public String secretKey;
    @Expose
    public String bucket;
    @Expose
    public String prefix;
    @Expose
    public boolean makePublic;
}

A: For the list, you have a couple of ways:
bitmovin.bitmovin.testFiles=foo,bar,biz

will set 3 items in testFiles. You can also control things via an index. The code above can be rewritten as
bitmovin.bitmovin.testFiles[0]=foo
bitmovin.bitmovin.testFiles[1]=bar
bitmovin.bitmovin.testFiles[2]=biz

For the object, if you don't create it yourself in the code, you need to make sure it has a public default constructor. Then you navigate your object like any other object, using . to navigate. Assume your S3InputConfig has a name property (with getName and setName):
bitmovin.bitmovin.s3InputConfig.name=the name

You've seen use of lower-case hyphen a lot in Boot's documentation. We support the original format as well as hyphen lower case and others (see relaxed binding). The canonical representation for your config would be as follows:
bitmovin.bitmovin.test-files[0]=foo
bitmovin.bitmovin.test-files[1]=bar
bitmovin.bitmovin.test-files[2]=biz
bitmovin.bitmovin.s3-input-config.name=the name

A: Normally when working with classes from libraries you are not in control of you can create a bean by doing something like this:
@Bean
S3OutputConfig s3OutputConfig(BitmovinConfig bitmovinConfig) {
    S3OutputConfig s3OutputConfig = new S3OutputConfig();

    // Do whatever else you want to setup the bean

    return s3OutputConfig;
}

This allows the flexibility to include other beans / configuration (they are autowired) that is needed to initialize the bean.

A: Another option is to use the @CondtionalOnProperty when constructing the @Bean. This way you can limit which beans are added to the context.

A: It pretty simply to create and initialize embedded objects for properties bean.
E.g. if you have such class:
@Component
@ConfigurationProperties(prefix = "bitmovin.bitmovin")
public class BitmovinConfig {

    private S3OutputConfig outputConfig = new S3OutputConfig();

    public S3OutputConfig getOutputConfig() {
        return outputConfig;
    }
}

where S3OutputConfig structure:
public class S3OutputConfig {

    public String name;

    public S3Region region;

    public String accessKey;

    public String secretKey;

    public String bucket;

    public String prefix;

    public boolean makePublic;
}

You can initialize fields of outputConfig in this way:
bitmovin.bitmovin.output-config.name=Config Name
bitmovin.bitmovin.output-config.access-key=XAKJGSDIUGASASD
bitmovin.bitmovin.output-config.region=us-east-1


text:
Q: How can I display pixel by pixel the calculation of a circle? Few days before, I asked you to help me because I couldn't show the drawing of a circle pixel by pixel (the drawing got stuck). @James_D found the solution and told me it was because a background-thread was trying to modify the UI. Indeed, I have a GraphicEngine class that extends Service : this class is this background-thread and its aim was to calculate and modify the image (now its aim is just to calculate the circle's pixels).
Well, finally, thanks to @James_D, I have now some classes :

*

*GraphicEngine,

*ImageAnimation which contains the animation of drawing,

*DialogCreationOfCircularGradation, which is a dialog containing a button "OK, draw circle !" and which handles this event.

The below source contains the answer of my program to the user-event "Draw a circle". It gets several Textfield's input and give it to the GraphicsEngine. Moreover it asks the latter to do the calculation of the circle's pixels and asks the ImageAnimation to display the calculation pixel by pixel, during the calculation done by the GraphicsEngine.
CLASS DialogCreationOfCircularGradation
public void dialogHandleEvents() {
    Optional r = this.showAndWait();
    if(r.isPresent() && r.get() == ButtonType.OK) { // The user clicks on "OK, draw the circle !"
        int radius = Integer.parseInt(this.dialog_field_radius.getText());
        [...]

        this.gui.getImageLoader().loadImageFromUsersPreferences(x0 + thickness + 2*radius, y0 + thickness + 2*radius);
        this.gui.getGraphicEngine().setOperationToDo("Circle");
        this.gui.getGraphicEngine().setRadius(radius);
        [...]
        this.gui.getGraphicEngine().restart();
        this.gui.getImageAnimation().start();
    }
}

The below code is GraphicsEngine's one. As you can see, there is in particular one important variable which is incremented during the circle algorithm : its name is counter_max. Why this variable is important ? Because it's necessary used in the class ImageAnimation. Look at its source after GraphicsEngine's one.
CLASS GraphicEngine
public class GraphicEngine extends Service<Void> {
    private int image_width, image_height;
    private PixelReader pixel_reader;
    private BlockingQueue<Pixel> updates;

    private String operation_to_do;
    private int radius; [...]

    public void setOperationToDo(String operation_to_do) {
        this.operation_to_do = operation_to_do;
    }

    public Task<Void> createTask() {
        return new Task<Void>() {

            protected Void call() {
                switch(operation_to_do) {
                    [...]
                    case "Circle" :
                        traceCircularGradation();
                        break;
                }

                return null;
            }
        };
    }

private void traceCircularGradation() {
    double w = 2 * 3.141, precision = 0.001;

    long counter_max = 0;
    int x, y;
    this.gui.getImageAnimation().setMax(counter_max);
    double[] rgb_gradation;
    for (double current_thickness = 0; current_thickness <= this.thickness; current_thickness++) {
        for (double angle = 0; angle <= w; angle += precision) {
            x = (int) ((current_thickness + radius) * Math.cos(angle) + x0);
            y = (int) ((current_thickness + radius) * Math.sin(angle) + y0);
            if(x >= 0 && y >= 0) {
                counter_max++;
                rgb_gradation = PhotoRetouchingFormulas.chromatic_gradation(angle, w);
                updates.add(new Pixel(x, y, Color.color(rgb_gradation[0], rgb_gradation[1], rgb_gradation[2])));
            }
        }
    }
    this.gui.getImageAnimation().setMax(counter_max);
}

The variable counter_max is used in ImageAnimation (its name has changed, its called : max). It's useful in the last if : if (count >= max).
max/counter_max represent the number of modified pixels. I can't replace it with image_width * image_height because in the circle algorithm, only the circle's pixels are drawn/modified. The other pixels of the image are not.
So I have either to compute counter_max as I did here in the for loops and then give it to ImageAnimation, or find a mathematical formula to determine it before the for. In the first case, the display of the circle doesn't work.
It would be really perfect if a formula existed.
CLASS ImageAnimation
public class ImageAnimation extends AnimationTimer {
    private Gui gui;
    private long max;
    private long count, start;

    ImageAnimation (Gui gui) {
        this.gui = gui;
        this.count = 0;
        this.start = -1;
    }

    public void setMax(long max) {
        this.max = max;
    }

    @Override
    public void handle(long timestamp) {
        if (start < 0) {
            start = timestamp ;
            return ;
        }

        WritableImage writable_image = this.gui.getWritableImage();
        BlockingQueue<Pixel> updates = this.gui.getUpdates();
        while (timestamp - start > (count* 5_000_000) / (writable_image.getWidth()) && ! updates.isEmpty()) {
            Pixel update = updates.remove();
            count++;
            writable_image.getPixelWriter().setColor(update.getX(), update.getY(), update.getColor());
        }

        if (count >= max) {
            this.count = 0;
            this.start = -1;
            stop();
        }
    }

    public void startAnimation() {
        this.start();
    }
}

A: If you need to compute max later, then you can't initialize it to zero (because if you do any updates before it is set to its "correct" value, then count will exceed max and you will stop the animation). So just initialize it to something it will never reach, e.g. Long.MAX_VALUE.
Relatedly, since you are accessing max from multiple threads, you should either synchronize access to it, or (better) use an AtomicLong. I.e.
public class ImageAnimation extends AnimationTimer {
    private Gui gui;
    private AtomicLong max;
    private long count, start;

    ImageAnimation (Gui gui) {
        this.gui = gui;
        this.count = 0;
        this.start = -1;
        this.max = new AtomicLong(Long.MAX_VALUE);
    }

    public void setMax(long max) {
        this.max.set(max);
    }

    @Override
    public void handle(long timestamp) {
        if (start < 0) {
            start = timestamp ;
            return ;
        }

        WritableImage writable_image = this.gui.getWritableImage();
        BlockingQueue<Pixel> updates = this.gui.getUpdates();
        while (timestamp - start > (count* 5_000_000) / (writable_image.getWidth()) && ! updates.isEmpty()) {
            Pixel update = updates.remove();
            count++;
            writable_image.getPixelWriter().setColor(update.getX(), update.getY(), update.getColor());
        }

        if (count >= max.get()) {
            this.count = 0;
            this.start = -1;
            this.max.set(Long.MAX_VALUE);
            stop();
        }
    }

    public void startAnimation() {
        this.start();
    }
}


text:
Q: Trending Search Help My site acts like a search engine where people enter search queries on the main page. I wanted to make a trending / recent feature where each query gets recorded into a mysql database, then from that data, calculates which searches are being searched the most, and then displayed back on the page labeled as trending searches. Also, under that, I would like "recent searches" which simply displays the last 5 or so searches.
Honestly, I have no experience with mysql. I don't even know how to move data from my site to mysql. Any help would be appreciated. I searched and searched these questions and google, but didn't find anything. Thanks!

A: First of all, you need to CREATE a DATABASE, in which you want a table with a timestamp and the keyword that's been searched. (CREATE TABLE)
Then you want to store each keyword access into this table (INSERT INTO ... VALUES ...)
Then you can select the top key words by creating a SELECT query with a "GROUP BY keyword", ORDER ing by COUNT(*) (the number of occurrences of a keyword)
This is a bit vague, but you'll need to go through a number of steps so I've uppercased the terms you'd need to google for each step. Do come back if you run into complications in any of those steps!


text:
Q: How can I use my existing array like a list? I have an array which hold controls my UI inventory list. When I add a GameObject to the array, the function also adds the same GameObject to my inventory UI.
In my script I also have a remove function that removes the GameObject from the array and removes the GameObject from the UI.
My issue is that I need to change this array to a list so that it can work dynamically, as a list has built in functionality to move the the elements of the array to the front of the array (that is move them left in the array index).
For example, currently when using an array, when I choose items 1,2,3,4, and 5. I then proceed to remove item 3. What is left in my array is 1,2,null,4, and 5. As well, what is left in my inventory UI are GameObjects in slots 1,2,null,4,5. The null in this case is a UI image with nothing on it.
By converting this array to a list I believe I can avoid having gaps in the inventory UI. As well, I know my array and or list will always be 16 items.
I have tried converting the existing array to a list and using all methods that correspond to the list methods.
The original array usage:
public class Inventory : MonoBehaviour
{
    public GameObject[] inventory = new GameObject[16];
    public List<GameObject> inventory2 = new List<GameObject>();

    public void AddItem(GameObject item)
    {
        bool itemAdded = false;

        //find the first open slot in inventory
        for (int i = 0; i < inventory.Length; i++)
        {
            if (inventory[i] == null)
            {
                inventory[i] = item;

                //Update UI
                InventoryButtons[i].image.overrideSprite =
    item.GetComponentInChildren<SpriteRenderer>().sprite;
        }
    }
}

My attempt to convert this to a list and use it as such:
public class Inventory : MonoBehaviour
{
    public List<GameObject> inventory = new List<GameObject>();

    public void AddItem(GameObject item)
    {
        bool itemAdded = false;

        //find the first open slot in inventory
        for (int i = 0; i < inventory.Count; i++)
        {
            if (inventory[i] == null)
            {
                inventory[i] = item;

                //Update UI
                InventoryButtons[i].image.overrideSprite =
     item.GetComponentInChildren<SpriteRenderer>().sprite;
            }
        }
    }
}

As I thought lists and arrays work the same, I thought my method would work, but the list is still acting as an array, that is, it is not dynamically moving items in the array to the front after items have been deleted from the array.

A: If the array version works out and you always want 16 items why not just do this to remove an item:
//remove item at index 5
for (int i = 5; i < inventory.Count - 1; i++)
  inventory[i] = inventory[i+1];

inventory[inventory.Length - 1] = null;

We start at index 5, the one to be removed, and proceed to the end of the array-1 copying each next item over the top of the current one. Then we finish the loop and make the last item null


text:
Q: Install AppDynamics in OpenShift 4.X I am looking for a way to install AppDynamics in a OpenShift Cluster.
Unable to find proper documentation on how to install and what tools need to be installed.
Should My Application Docker file also include any images related to AppDynamics
If anyone familiar with this please share some steps or provide reference to documents.

A: Old docs: https://docs.appdynamics.com/22.2/en/infrastructure-visibility/monitor-containers-with-docker-visibility/use-docker-visibility-with-red-hat-openshift
New Docs: https://docs.appdynamics.com/22.2/en/infrastructure-visibility/monitor-kubernetes-with-the-cluster-agent
Note that there is not a prescribed way to instrument as such, you need to make some decisions.
i.e. (from the second doc link):

*

*The first decision is to use the officially released pre-built
Appdynamics Operator images published on DockerHub and Redhat
Registry or If you want to build a custom Appdynamics Operator image.
See Build the Custom Cluster Agent Image.

*The second decision is whether to use the officially released
pre-built Cluster Agent images published on DockerHub and Redhat
Registry or If you want to build a custom Cluster Agent image. See
Cluster Agent Container Image.

*The third decision is whether to install the Cluster Agent using the
Kubernetes CLI or the Cluster Agent Helm Chart. See Install the
Cluster Agent with the Kubernetes CLI and Install the Cluster Agent
with Helm Charts.


text:
Q: Couchdb filtering results using reduce function and startkey/endkey I have documents that set up like this:
{ _id: 1, name: "A", timestamp: 1478115739, type: "report" }
{ _id: 2, name: "B", timestamp: 1478103721, type: "transmission" }
{ _id: 3, name: "C", timestamp: 1473114714, type: "report" }

I am trying to create a view that only returns the documents within a specific timestamp range. And I would love to be able to filter by type as well.
Here is my javascript call for the the data:
db.query('filters/timestamp_type', { startKey: 1378115739, endKey: 1478115740  })
.then(function(resp) {
    //do stuff
})

I only know where to put the starting and ending timestamps. I'm having a hard time figuring out where I would say I only want the report's returned.
In addition, this is my map function for my filter, which is obviously not even close to being complete. I'm not sure how I even access the start and end key.
function (doc) {
  if(type == "report" && startKey >= doc.timestamp && endKey <= doc.timestamp)
    emit(doc._id, doc.name);
}

My question remains:

*

*Where do I retrieve the start and end key's in my map function?

*How can I add an addition type filter for only getting a specific type of report.

I know I might need to use a reduce function but it's going over my head. Here is the default reduce function but I'm not sure how it would work with the map function.
function (keys, values, rereduce) {
  if (rereduce) {
    return sum(values);
  } else {
    return values.length;
  }
}

Thank you, any help or guidance would be appreciated.

A: Use a map function to get reports by a specific type-

function(doc) {
   if(doc.type == "report") {
     emit(doc.timestamp, doc);
   }
}

when the view is queried, only documents with the type 'report' will be returned. If you need to support multiple types, you will have to create a new view for each type.
To query this view and specify the start & end timestamps, just add them to your query-
curl -XGET http://localhost:5984/<your-database>/_design/docs/_view/<your-view-name>?startkey="1478115739"&endkey="1478103721"

Reference


text:
Q: Cisco ASA 5510 VPN Dropping RDP Sessions We have a Cisco ASA 5510 (47-7523-01 Rev A0) that we are using so that users can connect to the VPN from home.
I use this connection myself to do late night backups on our old database systems that don't quiesce.
It worked fine until this week, but now it seems everyone is getting kicked off at once, probably about 12 people on at the same time.
I'm told by my fellow IT guy who's been here six months longer than me that the VPN connection is 10MB down and 10MB up.
I also recorded some logs when I was having trouble staying connected myself, and I took notes that corresponded to the log number and what was happening. I don't know enough about VPNs to see if they are safe to post or not.
That said I have found a couple of articles on your site about how to configure and setup a VPN with an ASA, and I'm going to take a look at them.
I read somewhere else that the connection speed might be the problem, but I don't know it for a fact...

A: We found out that it was expecting a DNS server that wasn't there.  So the DNS was set to one of Google's DNS servers, and that fixed the problem.


text:
Q: Sorting the keys of dictionary according to the common value I have the dictionary values as follows in python:
X = {7: [0, 2], 9: [2, 3], 11: [1, 10], 13: [10, 4], 15: [8, 12], 16: [12, 14, 2], 20: [21, 22] , 32:[13]}

Now I want to take the key values in a list,  which has at least one value common in the dictionary.
example:
list of  common keys with at least one common value:  (7, 9, 16),  (11, 13), (15, 16)
also
group of keys that does not share any common value with others.
Example:
(20,32)
What will be the best way to do this?

A: You can first build an inverted dict matching each possible value to the list of keys that contain it. The rest is then fairly easy:
from collections import defaultdict

X= {7: [0, 2], 9: [2, 3], 11: [1, 10], 13: [10, 4], 15: [8, 12], 16: [12, 14,2], 20:[21,22] , 32:[13] }

out = defaultdict(list)
for key, values in X.items():
    for val in values:
        out[val].append(key)

# You get defaultdict(<class 'list'>, {0: [7], 2: [7, 9, 16], 3: [9], 1: [11], 10: [11, 13],
#  4: [13], 8: [15], 12: [15, 16], 14: [16], 21: [20], 22: [20], 13: [32]})

common = {key:values for key, values in out.items() if len(values) > 1}
print(common)
# {2: [7, 9, 16], 10: [11, 13], 12: [15, 16]}

# if you don't care about the keys:
print(list(common.values()))
# [[7, 9, 16], [11, 13], [15, 16]]

uniques = set(X) - set(k for keys in common.values() for k in keys)

print(uniques)
# {20, 32}


text:
Q: Compare goodness of two estimations I have performed two estimations with the following results:

*

*Blue line: Result of a simple linear regression on the displayed data points ($\approx$ the truth).

*Red line: Result of an estimation with different data.

How can I assess the goodness of the red estimation (in comparison to the blue)?

A: One way to measure the goodness of fit of both lines is using the Mean Squared Error (MSE) and Root Mean Squared Error (RMSE):
$$MSE = \frac{1}{n} \centerdot \sum \left( \hat{y}_i - y_i \right)^2$$
$$RMSE = \sqrt{MSE}$$
RMSE indicates the average error and equals $0$ in the best case. Furthermore, it is suitable to compare the precision of the red and the blue line by comparing their RMSE values.


text:
Q: How to implement/perform DFT on a segment in python? I am trying to write a simple program in python that will calculate and display DFT output of 1 segment.
My signal is 3 seconds long, I want to calculate DFT for every 10ms long segment. Sampling rate is 44100. So one segment is 441 samples long.
Since I am in the phase of testing this and original program is much larger(speech recognition) here is an isolated part for testing purposes that unfortunately behaves odd. Either that or my lack of knowledge on the subject.

*

*I read somewhere that DFT input should be rounded to power of 2 so I arranged my array to 512 instead 441. Is this true?

*If I am sampling at a rate of 44100, at most I can reach frequency of 22050Hz and for sample of length 512(~441) at least 100Hz ?

*If 2. is true, then I can have all frequencies between 100hz and 22050hz in that 10ms segments, but the length of segment is 512(441) samples only, output of fft returns array of 256(220) values, they cannot contain all 21950 frequencies in there, can they?

*My first guess is that the values in output of fft should be multiplied by 100, since 10ms is 100th of a second. Is this good reasoning?
The following program for two given frequencies 1000 and 2000 returns two spikes on graph at positions 24 and 48 in the output array and ~2071 and ~4156 on the graph. Since ratio of numbers is okay (2000:1000 = 48:24) I wonder if I should ignore some starting part of the fft output?
import matplotlib.pyplot as plt
import numpy as np

t = np.arange(0, 1, 1/512.0)  # We create 512 long array

# We calculate here two sinusoids together at 1000hz and 2000hz
y = np.sin(2*np.pi*1000*t) + np.sin(2*np.pi*2000*t)
n = len(y)
k = np.arange(n)

# Problematic part is around here, I am not quite sure what
# should be on the horizontal line
T = n/44100.0
frq = k/T
frq = frq[range(n/2)]

Y = fft(y)
Y = Y[range(n/2)]
# Convert from complex numbers to magnitudes
iY = []
for f in Y:
    iY.append(np.sqrt(f.imag * f.imag + f.real * f.real))

plt.plot(frq, iY,  'r')
plt.xlabel('freq (HZ)')
plt.show()

A:

*

*I read somewhere that the DFT input should be rounded to power of 2 so I arranged my array to 512 instead 441. Is this true?

The DFT is defined for all sizes. However, implementations of the DFT such as the FFT are generally much more efficient for sizes which can be factored in small primes. Some library implementations have limitations and do not support sizes other than powers of 2, but that isn't the case with numpy.

*If I am sampling at a rate of 44100, at most I can reach frequency of 22050Hz and for sample of length 512(~441) at least 100Hz?

The highest frequency for even sized DFT will be 44100/2 = 22050Hz as you've correctly pointed out. Note that for odd sized DFT the highest frequency bin will correspond to a frequency slightly less than the Nyquist frequency. As for the minimum frequency, it will always be 0Hz. The next non-zero frequency will be 44100.0/N where N is the DFT length in samples (which gives 100Hz if you are using a DFT length of 441 samples and ~86Hz with a DFT length of 512 samples).

*If 2) is true, then I can have all frequencies between 100Hz and 22050Hz in that 10ms segments, but the length of segment is 512(441) samples only, output of fft returns array of 256(220) values, they cannot contain all 21950 frequencies in there, can they?

First there aren't 21950 frequencies between 100Hz and 22050Hz since frequencies are continuous and not limited to integer frequencies. That said, you are correct in your realization that the output of the DFT will be limited to a much smaller set of frequencies. More specifically the DFT represents the frequency spectrum at discrete frequency step: 0, 44100/N, 2*44100/N, ...

*My first guess is that the values in output of FFT should be multiplied by 100, since 10ms is 100th of a second. Is this good reasoning?

There is no need to multiply the FFT output by 100. But if you meant multiples of 100Hz with a DFT of length 441 and a sampling rate of 44100Hz, then your guess would be correct.

The following program for two given frequencies 1000 and 2000 returns two spikes on graph at positions 24 and 48 in the output array and ~2071 and ~4156 on the graph. Since ratio of numbers is okay (2000:1000 = 48:24) I wonder if I should ignore some starting part of the fft output?

Here the problem is more significant. As you declare the array
t = np.arange(0, 1, 1/512.0)  # We create 512 long array

you are in fact representing a signal with a sampling rate of 512Hz instead of 44100Hz. As a result the tones you are generating are severely aliased (to 24Hz and 48Hz respectively). This is further compounded by the fact that you then use a sampling rate of 44100Hz for the frequency axis conversion. This is why the peaks are not appearing at the expected 1000Hz and 2000Hz frequencies.
To represent 512 samples of a signal sampled at a rate of 44100Hz, you should instead use
t = np.arange(0, 511.0/44100, 1/44100.0)

at which point the formula you used for the frequency axis would be correct (since it is based of the same 44100Hz sampling rate). You should then be able to see peaks near the expected 1000Hz and 2000Hz (the closest frequency bins of the peaks being at ~1033Hz and 1981Hz).

A:
1) I read somewhere that DFT input should be rounded to power of 2 so
  I aranged my array to 512 instead 441. Is this true?

Yes, DFT length should be a power of two. Just pad the input with zero to match 512.

2) If I am sampling at a rate of 44100, at most I can reach frequency
  of 22050hz and for sample of length 512(~441) at least 100hz ?

Yes, the highest frequency you can get is half the the sampling rate, It's called the Nyquist frequency.
No, the lowest frequency bin you get (the first bin of the DFT) is called the DC component and marks the average of the signal. The next lowest frequency bin in your case is 22050 / 256 = 86Hz, and then 172Hz, 258Hz, and so on until 22050Hz.
You can get this freqs with the numpy.fftfreq() function.

3) If 2) is true, then I can have all frequencies between 100hz and
  22050hz in that 10ms segments, but the length of segment is 512(441)
  samples only, output of fft returns array of 256(220) values, they
  cannot contain all 21950 frequencies in there, can they?

DFT doesn't lose the original signal's data, but it lacks accuracy when the DFT size is small. You may zero-pad it to make the DFT size larger, such as 1024 or 2048.
The DFT bin refers to a frequency range centered at each of the N output
points. The width of the bin is sample rate/2,
and it extends from: center frequency -(sample rate/N)/2 to center
frequency +(sample rate/N)/2. In other words, half of the bin extends
below each of the N output points, and half above it.

4) My first guess is that the values in output of fft should be
  multiplied by 100, since 10ms is 100th of a second. Is this good
  reasoning?

No, The value should not be multiplied if you want to preserve the magnitude.

The following program for two given frequencies 1000 and 2000 returns
  two spikes on graph at positions 24 and 48 in the output array and
  ~2071 and ~4156 on the graph. Since ratio of numbers is okay
  (2000:1000 = 48:24) I wonder if I should ignore some starting part of
  the fft output?

The DFT result is mirrored in real input. In other words, your frequencies will be like this:
n  0   1   2   3    4   ... 255   256   257   ... 511 512
Hz DC  86  172 258  344 ... 21964 22050 21964 ... 86  0


text:
Q: How to Load Custom Listview with a List from SQLite I have created the Adapter class which extends the BaseAdapter and i also the class to query the DB. Now i am stock at connecting both result and the custom layout i Just don't know how to achieve it. If anybody could kindly help
Adapter Class
public class DrugAdapter extends BaseAdapter{
    private static LayoutInflater lf = null;
    private Activity activity;
    private ArrayList<HashMap<String, String>> data;

    public DrugAdapter(Activity a, ArrayList<HashMap<String, String>> d){
        activity = a;
        data = d;
        lf = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View vi=convertView;
        if(convertView==null)
            vi = lf.inflate(R.layout.single_list_item, null);

        TextView title = (TextView)vi.findViewById(R.id.drug_title); // title
        TextView description = (TextView)vi.findViewById(R.id.drug_description); // description

        HashMap<String, String> drug = new HashMap<String, String>();
        drug = data.get(position);

        // Setting all values in list view
        //title.setText());
        //description.setText(song.get(CustomizedListView.KEY_ARTIST));

        return vi;
    }

}

the method in the DBHandler Class that returns the Result as a list from the DB
//Get all drugs from the DB
public List<Drug> getAllDrugs(){
    List<Drug> drugList = new ArrayList<Drug>();

    String selectQuery = "SELECT  * FROM " + TABLE_DRUGS;
    SQLiteDatabase db = this.getWritableDatabase();
    Cursor cursor = db.rawQuery(selectQuery, null);

    // looping through all rows and adding to list
    if (cursor.moveToFirst()) {
        do {
            Drug drug = new Drug();
            drug.setID(Integer.parseInt(cursor.getString(0)));
            drug.setName(cursor.getString(1));
            drug.setDesc(cursor.getString(2));
            // Adding contact to list
            drugList.add(drug);
        } while (cursor.moveToNext());
    }

    return drugList;
}

Drug Object Class
public class Drug {
    int id;
    String name;
    String descri;

    public Drug(int id, String name, String desc) {
        // TODO Auto-generated constructor stub
        this.id = id;
        this.name = name;
        descri = desc;
    }

    public Drug(String name, String desc){
        this.name = name;
        descri = desc;
    }

    public Drug() {
        // TODO Auto-generated constructor stub
    }

    public int getID() {
        // TODO Auto-generated method stub
        return this.id;
    }

    public String getName() {
        // TODO Auto-generated method stub
        return this.name;
    }

    public String get_desc() {
        // TODO Auto-generated method stub
        return descri;
    }

    public void setID(int newId) {
        // TODO Auto-generated method stub
        this.id = newId;
    }

    public void setName(String newName) {
        // TODO Auto-generated method stub
        this.name = newName;
    }

    public void setDesc(String newDesc) {
        descri = newDesc;
    }

}

Please any idea how i am suppose to set the ListView Adapter..
i Have tried some few tricks like this
List k =db.getAllDrugs();
    ArrayAdapter<String> adap = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, k);
    ls.setAdapter(adap);

just show that the data is being read from the table.. that's where i get stuck
Code for the getView Method
public View getView(int position, View convertView, ViewGroup parent) {
    // TODO Auto-generated method stub
    View vi=convertView;

    if(convertView==null)
        vi = lf.inflate(R.layout.single_list_item, null);

    TextView title = (TextView)vi.findViewById(R.id.drug_title); // title
    TextView description = (TextView)vi.findViewById(R.id.drug_description); // description
    TextView id = (TextView) vi.findViewById(R.id.drug_id);

    Drug drug = data.get(position);

    // Setting all values in list view
    title.setText(drug.getName());
    description.setText(drug.get_desc());
    id.setText("h");

    return vi;
}

The last setText is flagging the error..

A: Start by replacing List k =db.getAllDrugs(); by List<Drug> k =db.getAllDrugs();
Then, your compiler will complain about your adapter being a String adapter. At this point replace
ArrayAdapter<String> adap = new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1, k);

with
 DrugAdapter adap = new DrugAdapter(this, k);

Compiler will now complain that your list is not the right type. Change references to ArrayList<HashMap<String, String>> data in DrugAdapter with List<Drug> data.
Then properly implement getItem :
public Drug getItem(int position) {
    return data.get(position);
}

In getView declare drug like so:
Drug drug = data.get(position);

Then do whatever you have to do to put the content of drug in the view.

A: It's not usually necessary for your custom adapter to inherit from BaseAdapter. There are many Adapter implementations in the framework that take care of a bunch of boilerplate. In your case, you should be using a CursorAdapter for performance reasons. Cursors are optimized for the platform and dumping them to arrays is wasteful for any non-tiny result.
public class DrugAdapter extends CursorAdapter {
    public DrugAdapter(Context context, Cursor c) {
        super(context, c);
    }

    @Override
    public Object getItem(int position) {
        // This allows us to get proper Drug objects from the adapter
        Drug drug = new Drug();
        drug.setID(Integer.parseInt(cursor.getString(0)));
        drug.setName(cursor.getString(1));
        drug.setDesc(cursor.getString(2));
        return drug;
    }

    @Override
    public View newView(Context context, Cursor cursor, ViewGroup parent) {
        // We only need to create the new view here
        final LayoutInflater inflater = LayoutInflater.from(context);
        return inflater.inflate(R.layout.single_list_item, parent);
    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {
        // This is where we populate the list item data
        ((TextView) view.findViewById(R.id.drug_title)).setText(cursor.getString(1));
        ((TextView) view.findViewById(R.id.drug_description)).setText(cursor.getString(2));
    }
}

A: You should study a bit more of ArrayList, you are missing something very simple.
You must set an adapter for your ListView, like this:
myListView.setAdapter(new DrugAdapter(getActivity(), getAllDrugs()));

Also, the second argument on your DrugAdapter class is wrong, if your getAllDrugs() returns List<Drug> object, your DrugAdapter constructor must be as the following:
public DrugAdapter(Activity a, ArrayList<Drug> drugList);

Your DrugAdapter class must be something like this:
public class DrugAdapter extends BaseAdapter{
    private LayoutInflater lf = null;
    private Activity activity;
    private ArrayList<Drug> dl;

    public DrugAdapter(Activity a, ArrayList<Drug> drugList){
        activity = a;
        dl = drugList;
        lf = (LayoutInflater) activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public int getCount() {
        // TODO Auto-generated method stub
        return dl.size();
    }

    @Override
    public Object getItem(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public long getItemId(int position) {
        // TODO Auto-generated method stub
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        // TODO Auto-generated method stub
        View vi=convertView;

        if(convertView==null)
            vi = lf.inflate(R.layout.single_list_item, null);

        TextView title = (TextView)vi.findViewById(R.id.drug_title); // title
        TextView description = (TextView)vi.findViewById(R.id.drug_description); //   description

        title.setText(dl.get(position).getName());

        //use dl.get(position).yourMethodName() to get its value accordingly to your needs

    }
}

Remember: this code is not performance enhanced, I didn't enhanced it because it is not what you're asking, try to figure out what you may do to improve its performance later, but first, try to understand about ArrayList.

A: You'll need to pass the List which contains the data from the database to the Adapter. Then use the data from the list inside your getView() method. You can get rid of the HashMap I think.