text:
Q: Scraping algorithm for open graph in nodejs I'm trying to get open graph metadata from an URL using nodejs (with cheerio),
using the code bellow.
I have this thing to fill:    var result={};
  for (var ogCounter = 0; ogCounter < metalist.length; ogCounter++) {
    if (!utils.isEmpty(metalist[ogCounter].attribs.property) && !utils.isEmpty(metalist[ogCounter].attribs.content)) {
        if (metalist[ogCounter].attribs.property.indexOf('og') == 0) {
            var ogname = metalist[ogCounter].attribs.property.split(':');
            var property = ogname[1];
            var content = metalist[ogCounter].attribs.content;

            if (utils.isEmpty(result[property])) {
                result[property] = content;
            } else {
                if (result[property].push) {
                    result[property].push(content);
                } else {
                   result[property] = [result[property], content];
                }
            }

        }
    }
}

After I populate the result I converted in a JSon and with this code I get something like:
type: "video",
image: "http://i3.ytimg.com/vi/fWNaR-rxAic/mqdefault.jpg",
video: [
"http://www.youtube.com/v/fWNaR-rxAic?version=3&autohide=1",
"application/x-shockwave-flash",
"1920",
"1080"
]

But the thing I want is something like:
type: "video",
image: "http://i3.ytimg.com/vi/fWNaR-rxAic/mqdefault.jpg",
video: {
"http://www.youtube.com/v/fWNaR-rxAic?version=3&autohide=1",
{
type:"application/x-shockwave-flash",
width:"1920",
height:"1080"
}
}

I'm trying this "if" but it doesn't work:
 if (utils.isEmpty(result[property])) {
                    result[property] = content;
                } else {
                    if (result[property].push) {
                        result[property].push(content);
                    } else {
                        var subresult={};
                        subresult[name[2]]=content;
                        subresult[property]=result[property] ;

                        result[property] = subresult;
                    }
                }

I don't want to cycle all the meta 2 times and I'm not good with javascript and nodejs function... Any suggestion? Thanks

A: This is tricky because of how you want to display og:video. I don't think you can do it that way. The easiest thing to do would be to assign it an identifier for example name and have it at the same level as og:video:width
Example result
{
  "type": "video.other",
  "url": "http://philippeharewood.com/facebook/video.html",
  "title": "Simple Plan",
  "video": {
    "name": "http://www.youtube.com/v/Y4MnpzG5Sqc?version=3&autohide=1",
    "type": "application/x-shockwave-flash",
    "width": "398",
    "height": "224",
    "release_date": "2012-05-29T21:30"
  }
}

How it could be done,
var cheerio = require('cheerio')
var request = require('request')

var url = 'http://philippeharewood.com/facebook/video.html';
var result = {};

request(url, function(error, response, body) {
  var $ = cheerio.load(body);

  var meta = $('meta')
  var keys = Object.keys(meta)

  keys.forEach(function(key){
    if ( meta[key].attribs
         && meta[key].attribs.property
         && meta[key].attribs.property.indexOf('og') == 0
       )
    {
      var og = meta[key].attribs.property.split(':');

      if(og.length > 2) {
        if(result[og[1]]) {
          if (typeof result[og[1]] == 'string'
             || result[og[1]] instanceof String
             )
          {
            var set = {};
            set['name'] = result[og[1]];
            set[og[2]] = meta[key].attribs.content;
            result[og[1]] = set;
          }
          else {
            ex_set = result[og[1]];
            ex_set[og[2]] = meta[key].attribs.content;
            result[og[1]] = ex_set;
          }
        }
        else {
          var set = {};
          set[og[2]] = meta[key].attribs.content;
          result[og[1]] = set;
        }
      }
      else {
        result[og[1]] = meta[key].attribs.content;
      }
    }
  });

  console.log(JSON.stringify(result, undefined, 2));

});

A: Here's my answer. @phwd totally answered the question, but I thought it'd be nice to make a more general solution that parsed all meta tags to n levels.
var cheerio = require('cheerio'),
  request = require('request'),
  url = 'http://philippeharewood.com/facebook/video.html',
  result = {},
  attr = function( tag, prop ){ return tag.attribs && tag.attribs[prop] || ""; }

request( url, function( err, res, body ) {

  var metas = cheerio.load(body)('meta')
  var keys = Object.keys(metas)

  keys.forEach(function(i){
    var meta = metas[i],
      property = attr(meta,'property'),
      parts = property.split(":");

    if ( property ) {
      var og = property.split(':'),
        parent = result;

      for ( var j = 0; j < og.length; j++ ){
        var token = og[j],
          current = parent[token],
          name;

        if ( j+1 == og.length ) { // leaf node

          // expected leaf is already a branch so append a name attr
          if ( current instanceof Object ) name = token;
          // leaf should take the value given
          else parent[token] = attr(meta,'content');

        } else { // branch node

          // if no such branch exists, make one
          if ( !(current instanceof Object) ) {
            // if the branch is already a leaf, move value to name attr
            if ( typeof current == "string" ) name = current;
            current = {};
            parent[token] = current;
          }
        }
        if ( name ) current["name"] = name;
        name = undefined
        parent = current;
      }
    }
  });

  console.log(JSON.stringify( result.og, undefined, 2));

});


text:
Q: Mongodb 2.6 drop collection locking I am planning to drop a collection which has a storage space of
42gb with indeces, 2x 22gb with indeces and 3.6gb with indeces.
will it take a long time to drop each?
and will it lock a long time or just a few minutes?
when dropping these. I know it wont reclaim space. right now our disk space is on 90%. so when we drop these, will it still increment disk space?
or just take up the dropped collections space?
Using monbodb 2.6.12

redpajama_set_name: RedPajamaStackExchange


text:
Q: The status bar is white above toolbar I am doing an app and the status bar is now white.  I'm not doing anything fancy with the layout.  How can I get the status bar to show as "normal" (which would be dark with white icons).  .
Here is my layout:
 <?xml version="1.0" encoding="utf-8"?>
 <LinearLayout
   android:id="@+id/container_toolbar"
   android:layout_width="match_parent"
   android:layout_height="wrap_content"
   android:orientation="vertical"
   xmlns:android="http://schemas.android.com/apk/res/android">

<include
    android:id="@+id/toolbar"
    layout="@layout/toolbar" />

 <include layout="@layout/content_movie_detail" />

</LinearLayout>

Toolbar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.Toolbar
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:local="http://schemas.android.com/apk/res-auto"
  android:id="@+id/toolbar"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:minHeight="?attr/actionBarSize"
  android:background="@color/colorPrimary"
  local:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
  local:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

Activity:
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_movie_detail);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    actionBar = getSupportActionBar();

    try {
        assert actionBar != null;
        actionBar.setDisplayHomeAsUpEnabled(true);
        actionBar.setHomeButtonEnabled(true);
        actionBar.setDisplayShowTitleEnabled(true);
    } catch (Exception ignored) {
        Log.e(TAG,ignored.toString());
    }

}

What am I missing?

A: I found the answer here:
Status bar is white
<item name="android:statusBarColor">@android:color/transparent</item>

You'll see that line of code in values/styles/styles.xml(v21) . Remove it and that solves the issue

A: The colour of the status bar depends on the value of colorPrimaryDark which can be found in your styles.xml file.
Alternatively you can set the color like this: setStatusBarColor().
Here you can find more information.

A: There are two ways to set your statusbar color as said before. The first one is changing the colorPrimaryDark on the colors.xml in values folder.
The other way to set the status bar color is programmatically by the Window class:

Android Lollipop brought with it the ability to change the color of status bar in your app for a more immersive user experience and in tune with Google's Material Design Guidelines. Here is how you can change the color of the status bar using the new window.setStatusBarColor method introduced in API level 21. Changing the color of status bar also requires setting two additional flags on the Window; you need to add the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag and clear the FLAG_TRANSLUCENT_STATUS flag.

Window window = activity.getWindow();

// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);

// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);

// finally change the color
window.setStatusBarColor(activity.getResources().getColor(R.color.my_statusbar_color));

P.S.: The setStatusBarColor method works on android API 5.0 or above. To change the status bar color from KitKat to above, this block of code will work:
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
    {
        Window w = context.getWindow();
        w.setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS, WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
        //status bar height
        int statusBarHeight = Utilities.getStatusBarHeight(context);

        View view = new View(context);
        view.setLayoutParams(new FrameLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT));
        view.getLayoutParams().height = statusBarHeight;
        ((ViewGroup) w.getDecorView()).addView(view);
        view.setBackgroundColor(context.getResources().getColor(R.color.colorPrimaryTaskBar));
    }

As you can see, it creates a View object and set it backgroundColor.
Refference:
How to change the status bar color in android
http://www.dynamicguru.com/android/change-color-of-status-bar-in-android-apps-programmatically/

A: I guess your colorPrimaryDark is white/transparent in style.xml .Change colorPrimaryDark in style.xml file from white to any other color which you want.


text:
Q: target this childs spesific parent sibling Found this question which takes me about as far I was able to get on my own. However in my case I got multiple element with the same class and It currently selects all of them, can I somehow point it to the only one hovered on?

$(function(){
    $('.hover').live('mouseover', function(){
       $(this).parent().siblings('.target').css('color','red');
    });
    $('.hover').live('mouseout', function(){
       $(this).parent().siblings('.target').css('color','black');
    });
});

target

    Hover

target

    Hover

target

    Hover

A: Use .prev instead of .siblings to get to just the one previous element:

$('.hover').hover(
  function() {
    $(this).parent().prev().css('color', 'red');
  },
  function() {
    $(this).parent().prev().css('color', 'black');
  }
);

target

  Hover

target

  Hover

target

  Hover

(if you want the next element instead, use .next())


text:
Q: Way to show wide table neatly I am making a basic screen which simply shows a grid of data, but the grid can have more columns than the screen can cope with. I plan to use Bootstrap, but just for it's controls, look and feel. The page, however, does not need to scale for mobile.
A very basic example of the data I am showing looks like this:
https://jsfiddle.net/bunwt5cy/1/
So, first column is just an incrementing number, followed by a date, and then the data. The number of columns can range from 1 account, to 20. Each column (cell) then has 3 financial values (2 shown in demo) ranging from 0.00 to 99,999.99 (To show sizes required).
I'm currently using <TABLE>, but is there a better way, using bootstrap, to do this? Can it be done better with DIVs? And if I do, am I limited to 12 Divs per row? If so, that's not an option then, as my grid may have > 12 columns.
Here is an example of some rows. I'm trying to make it neater, and use 'as best as possible' best practice, but also, make pretty.

A: As a best practice, you should continue to use table element for such spreadsheet-like, tabular data, while using CSS to make it "pretty".
The div element according to the HTML5 specs:

The div element has no special meaning at all ...
Authors are strongly encouraged to view the div element as an element of last resort, for when no other element is suitable. Use of more appropriate elements instead of the div element leads to better accessibility for readers and easier maintainability for authors.

In this case table is available, it is appropriate for tabular data, so in terms of best practice, you should continue using table element for such tabular data rather than div.


text:
Q: Is int() a standalone function or it is actually an _init_ constructor method of the int class under covers? (a) I am trying to figure out whether int(), float(), tuple() and similar functions are standalone functons or they work like constructors for user classes (i.e. invoking class __init__() method under covers.)
(b) I wanted to find available  signatures of these methods, like int(str), int(str, base).
(c) I tried peeking into the source code on github, but it seems to be implemented on the c-layer, not on Python-layer. There is even no header-like stub Python code for this.

A: If you use help(int) you'll see that it's the name of a class:
Help on class int in module builtins:

class int(object)
 |  int(x=0) -> integer
 |  int(x, base=10) -> integer

However, if you scan further down, you won't see an __init__ method. Instances are initialized by internal C code in the __new__ method of the class.

A: Yes, all of those are classes, they are class objects. Their type is type (which itself, is a class, a metaclass):
>>> type(int)
<class 'type'>

Same as a custom class:
>>> class Foo: pass
...
>>> type(Foo)
<class 'type'>

And seemingly paradoxically:
>>> type(type)
<class 'type'>

NOTE: None of these objects are the __init__. That is a special method that gets called by the constructor to run custom initialization. IOW:
>>> Foo.__init__ is Foo
False


text:
Q: syncdb cannot create tables all tables When I run sqlall,I can see the SQL for all tables,but with syncdb,two tables are not created in the database.
The two tables are defined as
class Event(models.Model):
    event_id=models.IntegerField(primary_key=True)
    OS_CHOICE=(('Win 2003','windows 2003'),
        ('Win 2008','Windows 2008'),
        ('Win XP','Windows XP'),
        ('Win VISTA','Win VISTA'),
        ('Win 2007','Windows 2007'),
        )
    windows=models.CharField(max_length=10,choices=OS_CHOICE,default='Win 2003')

    def __unicode__(self):
        return " %s, event_id :%s" \
            % (self.windows, self.event_id)
    class Meta:
        db_table= 'event'
        verbose_name_plural='events'
class Eventgroups(models.Model):
    event=models.ManyToManyField(Event)
    group_name=models.CharField(max_length=100)

    def __unicode__(self):
        return "%s,  %s" \
            % (self.group_name, self.event)
    class Meta:
        db_table= 'eventgroup'
        verbose_name_plural='eventgroups'

Can anyone please give me an insight over this?


text:
Q: Laravel variable to where clause I am trying to extend one app to use my new Laravel app. In this scenario I am getting an unknown number of filters and I would like to forward them all to where() clause.
I have made something like this:
private function filterConverter($filter)
{
    $f = [];
    foreach ($filter as $singleFilter) {
        $operator = $this->filterValues[$singleFilter['operator']];
        $value = $operator == 'like' ? '%' . $singleFilter['value'] . '%' : $singleFilter['value'];

        $f[] = $singleFilter['field'] . ',' . $operator . ',' . $value;
    }

    return $f;
}

The thing is that I am getting operators like EQUALS and CONTAINS so I need to convert them to = and LIKE.
With this code I am trying to do this:
return response(MyModel::where($filter)->get());

But it doesn't work. Is there any elegant way to resolve this?
EDIT/SOLUTION
Sorry to @HCK as I couldn't quite accept the answer since it doesn't answer my question, but it pointed me on the right track. The solution was to use key, operator, value keys in the array instead of what I had "keyless".
private function filterConverter($filters)
{
    $filter = [];
    foreach ($filters as $singleFilter) {
        $operator = $this->filterMap[$singleFilter['operator']];
        $value = $operator == 'LIKE' ? '%' . $singleFilter['value'] . '%' : $singleFilter['value'];

        $filter[] = [
            'key'      => $singleFilter['field'],
            'operator' => $operator,
            'value'    => $value
        ];
    }

    return $filter;
}

A: You may follow this way
DB::table('users')
        ->where(function($query) use ($filter)
        {
            // You able to access $filter here
            // You may able to to generate this block by loop
            $query->where('votes', '>', 100)
                  ->where('title', '<>', 'Admin');
        })
        ->get();

Laravel Doc | Advanced Wheres
Exp-1
    $filters = [
        ['key' => 'votes', 'operator' => '>', 'value' => 100]
    ];

    DB::table('users')
        ->where(function ($query) use ($filters) {
            foreach ($filters as $filter) {
                if (@$filter['key'] && @$filter['operator'] && @$filter['value']) {
                    $query->where($filter['key'], $filter['operator'], $filter['value']);
                }
            }
        })->get();

Exp-2
    $filters = [
        ['key' => 'votes', 'operator' => '>', 'value' => 100]
    ];

    DB::table('users')
        ->where(function ($query) use ($filters) {
            foreach ($filters as $filter) {
                if (@$filter['key'] && @$filter['operator'] && @$filter['value']) {
                    $query->whereRaw("{$filter['key']} {$filter['operator']} '{$filter['value']}'");
                }
            }
        })->get();

You may also use scope function Ref

Exp-3 Laravel Scope
class User extends Model
{
    public function scopeFilter($query, $filters)
    {
        foreach ($filters as $filter) {
            if (@$filter['key'] && @$filter['value']) {
                $query->where($filter['key'], @$filter['operator']?:"=", $filter['value']);
            }
        }

        return $query;
    }
}

// Use
User::filter($filters)->get();

A: Not the nicest way to solve it, but this should work:
private function filterConverter($filters)
{
    return collect($filters)->map(function ($filter) {  // <---
        if($filter['operator'] == 'CONTAINS')
        {
            $filter['value'] = '%' . $filter['value'] . '%';
            $filter['operator'] = 'LIKE';
        }
        else if ($filter['operator'] == 'EQUALS')
        {
            $filter['operator'] = '=';
        }

        return collect($filter)->flatten(); // <---
    })->toArray(); // <---
}

Here I'm using the Map() function of the Collection class. there is a lot of useful methods provided by this class.


text:
Q: Proving a uniformly convergent series is discontinuous over a dense set. Let $(x)=x-n$, where $n$ is the unique integer such that $n\leq x<n+1$. I need to prove that $f(x)=\sum_{n=1}^\infty \frac{(nx)}{n^2}$ is discontinuous at all rational numbers.
Here is my approach: Let $x=\frac pq$ be a rational where $p$ and $q$ are relatively prime. Let us rearrange the sum as follows: Let $n=kq+r$, where $0\leq r<q$. Then $f(x)=\sum_{r=0}^{q-1}\sum_{k=0}^\infty \frac {((kq+r)x)}{(kq+r)^2}$. Now it is easy to see that $\sum_{k=0}^\infty \frac {((kq+r)x)}{(kq+r)^2}$ is continuous at $x=\frac pq$ for $1\leq r<q$ since $((kq+r)\frac pq)$ is continuous at $x=\frac pq$ because $(kq+r)\frac pq=kp + \frac {rp}q$ where $\frac {rp}q$ is clearly not an integer as $p$ and $q$ are coprime. Since the series converges uniformly, the limit is continuous at each point where all the terms are continuous. In particular, $\sum_{k=0}^\infty \frac {((kq+r)x)}{(kq+r)^2}$ is continuous at $x=\frac pq$ for $1\leq r<q$.
Now all I need to show is that $\sum_{k=0}^\infty \frac {((kq+r)x)}{(kq+r)^2}$ is discontinuous at $x=\frac pq$ for $r=0$. I have no idea how to prove it.


text:
Q: Change Android CalendarView arrow color/icon and replace selected circle shape Is it possible to change color of prev/next arrows in CalendarView or replace with a different icon image (set a different drawable somehow)?
Also is it possible to change selected shape (also set a different drawable)?

A: this works for me:
    new DatePickerBuilder(this, listener).previousButtonSrc(R.drawable.drawable) // for drawable of the previous arrow
    .forwardButtonSrc(R.drawable.drawable) // for drawable of the forward arrow

and also check these :
Is possible to hide arrows and put some imageView between title of calendar and weekdays?
and
Material Calendar View
there are open source calendars which are more flexible.


text:
Q: undefined method current_page for array kaminari I'm trying to do pagination for products details(images), but I'm getting this error.
NoMethodError in Home#index
Showing /home/aws002/webpage/app/views/home/index.html.erb where line #6 raised:
undefined method `current_page' for #
Here is my products controler code:
def index
    @rroducts = Product.order(:name)
    Kaminari.paginate_array(@products).page(params[:page]).per(3)
    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @products }
    end
end

and I'm trying to display in home page. view file code is:
<% @products=Product.all %>
  <%= paginate @products %>
  <% @products.each do |p|%>
    <%= image_tag("Images/#{p.id}.jpeg",:alt => p.name) %>
    <p> Price: </p>
    <%= p.price %>
    <p> Discount: </p>
    <%= p.discount %>
  <br/>
  <% end %>

Please help me to fix this. Thanks in advance.

A: Try this
def index
 @products = Product.order(:name).page(params[:page]).per(3)
 respond_to do |format|
  format.html # index.html.erb
  format.json { render json: @products }
 end
end

A: I got the answer.
Since I'm retrieving images which are saved in public directory and not using any controller or model to retrieve the images I've to include that kaminari part in view file only.
Kaminari.paginate_array(@products).page(params[:page]).per(3)
this should be added in view file.

A: i think the error came from your index method as you declared instance variable called @rroducts since you actually using another for Kaminari called @products


text:
Q: How to select records testing bits in BINARY column? I have 2 tables: one of them contains column binary(128), where every bit is some flag. Also I have other table contains list of bit positions which need to check in query.
This is example how I do the query for one bit.
How to do it universally, i.e. to select records testing bits in positions from the second table?
Should it be a function? what?
DECLARE @nByteNum      integer
DECLARE @nBitNumInByte integer
DECLARE @nMask         integer
DECLARE @nBigBitNum    integer

declare @t table(id int not null identity, id1 int, banner binary(128))
declare @bitpositions table(id int not null identity, position int)

insert into @bitpositions(position) values(8)
insert into @bitpositions(position) values(24)
insert into @bitpositions(position) values(30)

insert into @t(id1, banner)
select 1, 0x0
union all
select 1, 0x000100FF
union all
select 1, 0x010200FF
union all
select 10, 0x010208
union all
select 10, 0x000100
union all
select 10, 0x040000

select * from @t

-- This is for one bit
SET @nBigBitNum= 24
SET @nByteNum= @nBigBitNum/8
SET @nBitNumInByte= @nBigBitNum % 8      -- 0,1...6,7
SET @nMask = POWER(2, @nBitNumInByte ) -- 128,64,... 2,1
SET @nByteNum= @nByteNum +1

select * from @t where SUBSTRING(banner, @nByteNum,1)&@nMask=@nMask

A: Bitwise operations in SQL Server do not work on BINARY data in the way that you are expecting.  They work on integer datatypes only as noted on the MSDN page for & (Bitwise AND).
The general syntax for checking bitmasked values in a query is: WHERE {Column} & {BitMaskedValue} = {BitMaskedValue}.
Look at the following examples using your desired scenario of trying to find records that have bit positions 8 and 16 turned on.
-- 24 = 16 + 8
SELECT 24 & 16 -- 16
SELECT 24 & 8 -- 8
SELECT 24 & 17 -- 16
SELECT 24 & 32 -- 0
SELECT 24 & 26 -- 24


text:
Q: How can I implement the input of multiple regression in LSTM using keras? here is my code
def create_dataset(signal_data, look_back=1):
    dataX, dataY = [], []
    for i in range(len(signal_data) - look_back):
        dataX.append(signal_data[i:(i + look_back), 0])
        dataY.append(signal_data[i + look_back, 0])
    return np.array(dataX), np.array(dataY)

df = pd.read_csv('time_series.csv')
signal_data = df.Close.values.astype('float32')
signal_data = signal_data.reshape(len(df), 1)

scaler = MinMaxScaler(feature_range=(0, 1))
signal_data = scaler.fit_transform(signal_data)

train_size = int(len(signal_data) * 0.80)
test_size = len(signal_data) - train_size)
# val_size = len(signal_data) - train_size - test_size
train = signal_data[0:train_size]
# val = signal_data[train_size:train_size+val_size]
test = signal_data[train_size+val_size:len(signal_data)]

x_train, y_train = create_dataset(train, look_back)
# x_val, y_val = create_dataset(val, look_back)
x_test, y_test = create_dataset(test, look_back)

x_train = np.reshape(x_train, (x_train.shape[0], x_train.shape[1], 1))
# x_val = np.reshape(x_val, (x_val.shape[0], x_val.shape[1], 1))
x_test = np.reshape(x_test, (x_test.shape[0], x_test.shape[1], 1))

now I want to add df.Open and df.High and  df.Low and df.Volume
how can I implement this code?
Should I just add to the signal data? I'm wondering how to add data so that I can train multiple features in the signal data.
I don't know where and how to implement it. I need your help.
Your valuable opinions and thoughts will be very much appreciated.

A: I made several modifications to your code. This should work. In summary:

*

*I got fixed the lines of code where you were barcoding the selection of the variable 0. Now, the target variable stands on the last position and the others in the previous ones

*I fixed the reshapes some of them were not needed and the others were fixed to keep all the dimensions

*I fixed the model input shape, now you have 5 variables instead of 1

My general recommendations:

*

*I would not use MinMaxScaler, it is dangerous because a single outlier can disturb all your distribution. Instead, use StandardScaler. More info here: http://scikit-learn.org/stable/modules/generated/sklearn.preprocessing.StandardScaler.html

*I would scale the data afterwards, when the train_x, test_x and their y respective counterparts are built. The reason why is because you are computing the statistics for scaling the data using the train and test set, i.e. future information. This is by all the means different to what you'll find when you try to run your code in a real situation. I.e. you'll have to scale the new data with past statistics. It is better to build a test set as close to the reality as possible.

*How do you know that your model is big enough to model your data? I would get rid of the dropouts and run the model to see if it can overfit the data. If the model can overfit to the train data, it means that the model is big enough and you can start regularising your model to enhance generalisation. More info in this book: https://www.deeplearning.ai/machine-learning-yearning/

*In the model metrics you choose accuracy, which is a classification metric. I would use one according to my type of problem (regression): for example "Mean Absolute Error".

I hope I managed to help you :D

import numpy as np
import pandas as pd
from keras.models import Sequential
from keras.layers import Dense, LSTM, Dropout, Conv2D, Reshape, TimeDistributed, Flatten, Conv1D,ConvLSTM2D, MaxPooling1D
from keras.layers.core import Dense, Activation, Dropout
from sklearn.preprocessing import MinMaxScaler
from sklearn.metrics import mean_squared_error
import tensorflow as tf
import matplotlib.pyplot as plt

config = tf.ConfigProto()
config.gpu_options.allow_growth=True

sess = tf.Session(config=config)
def create_dataset(signal_data, look_back=1):
    dataX, dataY = [], []
    for i in range(len(signal_data) - look_back):
        dataX.append(signal_data[i:(i + look_back), :])
        dataY.append(signal_data[i + look_back, -1])
    return np.array(dataX), np.array(dataY)

look_back = 20

df = pd.read_csv('kospi.csv')
signal_data = df[["Open", "Low", "High", "Volume", "Close"]].values.astype('float32')

scaler = MinMaxScaler(feature_range=(0, 1))
signal_data = scaler.fit_transform(signal_data)

train_size = int(len(signal_data) * 0.80)
test_size = len(signal_data) - train_size - int(len(signal_data) * 0.05)
val_size = len(signal_data) - train_size - test_size
train = signal_data[0:train_size]
val = signal_data[train_size:train_size+val_size]
test = signal_data[train_size+val_size:len(signal_data)]

x_train, y_train = create_dataset(train, look_back)
x_val, y_val = create_dataset(val, look_back)
x_test, y_test = create_dataset(test, look_back)

model = Sequential()
model.add(LSTM(128, input_shape=(None, 5),return_sequences=True))
model.add(Dropout(0.3))

model.add(LSTM(128, input_shape=(None, 5)))
model.add(Dropout(0.3))

model.add(Dense(128))
model.add(Dropout(0.3))

model.add(Dense(1))

model.compile(loss='mean_squared_error', optimizer='adam', metrics=['accuracy'])

model.summary()
hist = model.fit(x_train, y_train, epochs=20, batch_size=32, verbose=2, validation_data=(x_val, y_val))

trainScore = model.evaluate(x_train, y_train, verbose=0)
model.reset_states()
print('Train Score: ', trainScore)
valScore = model.evaluate(x_val, y_val, verbose=0)
model.reset_states()
print('Validataion Score: ', valScore)
testScore = model.evaluate(x_test, y_test, verbose=0)
model.reset_states()
print('Test Score: ', testScore)

p = model.predict(x_test)

print(mean_squared_error(y_test, p))

import matplotlib.pyplot as pplt

pplt.plot(y_test)
pplt.plot(p)
pplt.legend(['testY', 'p'], loc='upper right')
pplt.show()


text:
Q: Spring boot docker testcontainers keep starting new containers on VDS So i have issued with very strange problem, I use testcontainers to start app and database instance while testing. On my pc (Mac), on my second pc which has Windows and even on computer with Ubuntu everything works as expected.
Then I started to use github actions to initiate tests every time someone tries to make merge request to master branch. And here I have problem.
I will skip github actions code part because It won't pass tests even with basic gradlew test clean command.
So behavior I expect:

*

*I write gradlew test clean

*Spring starts application container and database container. (And it works everywhere except my VDS, where it must work)

What behavior I get on VDS:

*

*I write gradlew test clean

*Spring starts application container and database container.

*Spring for some reason can't connect to database container and starts another database container (timeout 2 minutes)

*During tests Spring creates 4-5 database containers and without any success to connect with them fails all tests (as expected without working DB)

Every test file has following database configuration:
@SpringBootTest
@AutoConfigureMockMvc
@Testcontainers
@ContextConfiguration(initializers = {UserDataControllerTest.Initializer.class})
@TestMethodOrder(MethodOrderer.OrderAnnotation.class)
class UserDataControllerTest {

    @Autowired
    private MockMvc mockMvc;

    @Autowired
    private ObjectMapper objectMapper;

    @ClassRule
    @Container
    public final static MySQLContainer mysqlContainer = new MySQLContainer("mysql:8.0");

... some tests

    static class Initializer
            implements ApplicationContextInitializer<ConfigurableApplicationContext> {
        public void initialize(ConfigurableApplicationContext configurableApplicationContext) {
            TestPropertyValues.of(
                    "spring.datasource.url=" + mysqlContainer.getJdbcUrl(),
                    "spring.datasource.username=" + mysqlContainer.getUsername(),
                    "spring.datasource.password=" + mysqlContainer.getPassword(),
                    "spring.jpa.generate-ddl=true",
                    "spring.jpa.hibernate.ddl-auto=create-drop"
            ).applyTo(configurableApplicationContext.getEnvironment());
        }
    }
}

Stacktrace I get after command finishes:
org.testcontainers.containers.ContainerLaunchException: Container startup failed
    at app//org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:336)
    at app//org.testcontainers.containers.GenericContainer.start(GenericContainer.java:317)
    at app//org.testcontainers.junit.jupiter.TestcontainersExtension$StoreAdapter.start(TestcontainersExtension.java:242)
    at app//org.testcontainers.junit.jupiter.TestcontainersExtension$StoreAdapter.access$200(TestcontainersExtension.java:229)
    at app//org.testcontainers.junit.jupiter.TestcontainersExtension.lambda$null$1(TestcontainersExtension.java:59)
    at app//org.junit.jupiter.engine.execution.ExtensionValuesStore.lambda$getOrComputeIfAbsent$4(ExtensionValuesStore.java:86)
    at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$MemoizingSupplier.computeValue(ExtensionValuesStore.java:223)
    at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$MemoizingSupplier.get(ExtensionValuesStore.java:211)
    at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$StoredValue.evaluate(ExtensionValuesStore.java:191)
    at app//org.junit.jupiter.engine.execution.ExtensionValuesStore$StoredValue.access$100(ExtensionValuesStore.java:171)
    at app//org.junit.jupiter.engine.execution.ExtensionValuesStore.getOrComputeIfAbsent(ExtensionValuesStore.java:89)
    at app//org.junit.jupiter.engine.execution.NamespaceAwareStore.getOrComputeIfAbsent(NamespaceAwareStore.java:53)
    at app//org.testcontainers.junit.jupiter.TestcontainersExtension.lambda$beforeAll$2(TestcontainersExtension.java:59)
    at java.base@17.0.4/java.util.ArrayList.forEach(ArrayList.java:1511)
    at app//org.testcontainers.junit.jupiter.TestcontainersExtension.beforeAll(TestcontainersExtension.java:59)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.lambda$invokeBeforeAllCallbacks$10(ClassBasedTestDescriptor.java:381)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.invokeBeforeAllCallbacks(ClassBasedTestDescriptor.java:381)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:205)
    at app//org.junit.jupiter.engine.descriptor.ClassBasedTestDescriptor.before(ClassBasedTestDescriptor.java:80)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:148)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at java.base@17.0.4/java.util.ArrayList.forEach(ArrayList.java:1511)
    at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.invokeAll(SameThreadHierarchicalTestExecutorService.java:41)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$6(NodeTestTask.java:155)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$8(NodeTestTask.java:141)
    at app//org.junit.platform.engine.support.hierarchical.Node.around(Node.java:137)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.lambda$executeRecursively$9(NodeTestTask.java:139)
    at app//org.junit.platform.engine.support.hierarchical.ThrowableCollector.execute(ThrowableCollector.java:73)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.executeRecursively(NodeTestTask.java:138)
    at app//org.junit.platform.engine.support.hierarchical.NodeTestTask.execute(NodeTestTask.java:95)
    at app//org.junit.platform.engine.support.hierarchical.SameThreadHierarchicalTestExecutorService.submit(SameThreadHierarchicalTestExecutorService.java:35)
    at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestExecutor.execute(HierarchicalTestExecutor.java:57)
    at app//org.junit.platform.engine.support.hierarchical.HierarchicalTestEngine.execute(HierarchicalTestEngine.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:108)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:88)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.lambda$execute$0(EngineExecutionOrchestrator.java:54)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.withInterceptedStreams(EngineExecutionOrchestrator.java:67)
    at org.junit.platform.launcher.core.EngineExecutionOrchestrator.execute(EngineExecutionOrchestrator.java:52)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:96)
    at org.junit.platform.launcher.core.DefaultLauncher.execute(DefaultLauncher.java:75)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.processAllTestClasses(JUnitPlatformTestClassProcessor.java:99)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor$CollectAllTestClassesExecutor.access$000(JUnitPlatformTestClassProcessor.java:79)
    at org.gradle.api.internal.tasks.testing.junitplatform.JUnitPlatformTestClassProcessor.stop(JUnitPlatformTestClassProcessor.java:75)
    at org.gradle.api.internal.tasks.testing.SuiteTestClassProcessor.stop(SuiteTestClassProcessor.java:61)
    at java.base@17.0.4/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base@17.0.4/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77)
    at java.base@17.0.4/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base@17.0.4/java.lang.reflect.Method.invoke(Method.java:568)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:36)
    at org.gradle.internal.dispatch.ReflectionDispatch.dispatch(ReflectionDispatch.java:24)
    at org.gradle.internal.dispatch.ContextClassLoaderDispatch.dispatch(ContextClassLoaderDispatch.java:33)
    at org.gradle.internal.dispatch.ProxyDispatchAdapter$DispatchingInvocationHandler.invoke(ProxyDispatchAdapter.java:94)
    at jdk.proxy1/jdk.proxy1.$Proxy2.stop(Unknown Source)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker$3.run(TestWorker.java:193)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.executeAndMaintainThreadName(TestWorker.java:129)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:100)
    at org.gradle.api.internal.tasks.testing.worker.TestWorker.execute(TestWorker.java:60)
    at org.gradle.process.internal.worker.child.ActionExecutionWorker.execute(ActionExecutionWorker.java:56)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:133)
    at org.gradle.process.internal.worker.child.SystemApplicationClassLoaderWorker.call(SystemApplicationClassLoaderWorker.java:71)
    at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.run(GradleWorkerMain.java:69)
    at app//worker.org.gradle.process.internal.worker.GradleWorkerMain.main(GradleWorkerMain.java:74)
Caused by: org.rnorth.ducttape.RetryCountExceededException: Retry limit hit with exception
    at app//org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:88)
    at app//org.testcontainers.containers.GenericContainer.doStart(GenericContainer.java:329)
    ... 69 more
Caused by: org.testcontainers.containers.ContainerLaunchException: Could not create/start container
    at app//org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:525)
    at app//org.testcontainers.containers.GenericContainer.lambda$doStart$0(GenericContainer.java:331)
    at app//org.rnorth.ducttape.unreliables.Unreliables.retryUntilSuccess(Unreliables.java:81)
    ... 70 more
Caused by: java.lang.IllegalStateException: Container is started, but cannot be accessed by (JDBC URL: jdbc:mysql://localhost:49156/test), please check container logs
    at org.testcontainers.containers.JdbcDatabaseContainer.waitUntilContainerStarted(JdbcDatabaseContainer.java:165)
    at org.testcontainers.containers.GenericContainer.tryStart(GenericContainer.java:468)
    ... 72 more

PS. I multiple times reinstalled OS on VDS, there was Debian and now Ubuntu. Docker was installed by the instruction on the official website, user which starts github actions added to docker group (it actually doesn't matter because it won't start even from root user)


text:
Q: What MySQL data types REQUIRE a max length (size) declaration in a create table statement? I am converting a SQL Server table structure to a MySQL table structure, and I need to know how to properly declare the column data types within the CREATE TABLE statement.
I have a CSV file where each row gives me column info like so:
columnName,sqlServDataType,maxLength,precision,scale,isNullable,isPrimaryKey
idYear,int,4,10,0,0,1
...

I have a file / information on how I will programmatically map the SQL Server data type to the MySQL data type, but I need to know what MySQL data types require the max length declaration in a CREATE TABLE statement.
So for instance, in MySQL you can declare columnName INT or columnName INT(4) though there's really no point, from what I've read. However, doing something like VARCHAR(40) is important for both performance and data insertion concerns. Make a column too big for small data, it's inefficient. Make a column's max length too small for a given chunk of data, and the insertion will fail.
Ultimately for a given MySQL data type, I need to know if the max length e.g. VARCHAR(40) is required or not. I couldn't find much in the documentation.
Any pointers?

A: MySQL Perspective
@DerickDowney discussed this in his post INT(5) vs SMALLINT(5). He quoted from the MySQL Docs:

The display width does not constrain the range of values that can be stored in the column. Nor does it prevent values wider than the column display width from being displayed correctly. For example, a column specified as SMALLINT(3) has the usual SMALLINT range of -32768 to 32767, and values outside the range permitted by three digits are displayed in full using more than three digits.

Given this statement, if you create a table with a column type INT it will appear as INT(11). Why 11 ? INT has a range of -2147483648 and 2147483647. It takes 11 spaces to display the smallest signed INT -2147483648. Nothing more, nothing less.
Character data is entirely different story. Defining a VARCHAR requires the table header knowing the maximum length in advance. Rather than go into a lengthy explanation, please read the following posts:

*

*Fine Tuning The Table Definition (Percona)

*InnoDB Physical Row Structure (MySQL Documentation)
From the information in these posts, I would confidently say that you have no choice but to define a length for a VARCHAR. If you not sure, just define all VARCHARs as VARCHAR(255). No wasted is there. Alter loading data you could always run the following
SELECT varcharcolumnname FROM yourtable PROCEDURE ANALYSE();

and let it tell you the proper VARCHAR size.


text:
Q: How can I connect to API securely? I've been exposed to mostly API to browser or server. But not API to API.
I want to create API through which server 1 and 2 can talk. But I want them to be authenticated. Meaning it has to sure that connection is coming via authorized place.
I can use SSL request and then send long unique id. which seems easiest.
I could use some complicated OAuth... but since both sides are me why bother with scope.
I could make domain API url very long and not guessable and keep that a secret which only my main server would know and will use to connect. Similar to step 1, even easier.
All will needs SSL..

A: For a good balance of low-but-not-absent security but much-lower-than-oauth complexity, you could use a simple API key as an authentication token.

*

*tokens should be pseudorandom and generated with an appropriate crypto library. For example: require("rand-token").generator({source: "crypto"}).generate(20);

*tokens must obviously be kept secure and secret (tight filesystem permissions on the servers, don't check them into git, don't send them over plaintext HTTP, etc)

*each server should be able to validate a token (like from it's own database), and delete/revoke them if they are compromised.

*other than that the tokens function similarly to username/password credentials in a traditional web app sense, although you probably want to include them in every request header and not need sessions nor session cookies. I have used a header such as Authorization: key abababababababa....

I'd start with that. There's a lot more stuff you could gradually add over time as warranted by the status of your project, ending up with all the additional bells and whistles oauth2 and other high-grade systems provide such as temporary expiring tokens, replay protection, rate limiting, hashed and signed parameters, refresh mechanisms, granular permissions, etc.


text:
Q: stringstream and french locale (French_France.1252) std::stringstream stream_french;
stream_french.imbue(std::locale("")); // French_France.1252
stream_french << 1000;
std::string value_french = stream_french.str();

This code will convert 1000 to string "1 000" but the value of value_french[1] is -96 and not 32, why is that ?
value_french[0] = 49
value_french[1] = -96
value_french[2] = 48
value_french[3] = 48
value_french[3] = 48

If I do
stream_french << "1 000";

The value of value_french[1] is 32. The error seems to be related to the signedess of char, but why is it only affecting white spaces when doing conversions ?

A: That -96 is the signed equivalent of 160, i.e. 0xA0; if you go and check the Windows 1252 codepage table, you'll see that such character is

A0 = U+00A0 : NO-BREAK SPACE

which is a space that don't allow an automatic line break:

Text-processing software typically assumes that an automatic line break may be inserted anywhere a space character occurs; a non-breaking space prevents this happening (provided the software recognises the character, of course). For example, if the text "100 km" will not quite fit at the end of a line, the software may insert a line break between "100" and "km". To avoid this undesirable behaviour, the editor may choose to use a non-breaking space between "100" and "km". This guarantees that the text "100 km" will not be broken: if it does not fit at the end of a line it is moved in its entirety to the next line.

As with "100 km", also with "1 000" it's clear that it's not desirable to have a line break between the 1 and the three 0, so a non-breaking space is used; quite clever indeed.
To make it definitely clear: with a "normal" space:
1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000
with a non-breaking space:
1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000 1 000
(if you don't see any difference, try to zoom in/out with the font size of the browser)


text:
Q: How can i prevent my draggable menu go outside a div in Polymer 2? I have a draggable menu that i want it to be restricted within parent in Polymer 2

Here is my draggable function, i saw that there is a way to fix my problem using javascript vanilla but i tried with polymer and it doesnt work
    dragElement: function(elmnt) {
  var pos1 = 0, pos2 = 0, pos3 = 0, pos4 = 0;
  if (Polymer.dom(this.root).querySelector("#" + elmnt.id + "header")) {
    // if present, the header is where you move the DIV from:
       Polymer.dom(this.root).querySelector("#" + elmnt.id + "header").addEventListener("mousedown", dragMouseDown);
  } else {
    // otherwise, move the DIV from anywhere inside the DIV:
    elmnt.onmousedown = dragMouseDown;
  }

  function dragMouseDown(e) {
    e = e || window.event;
    e.preventDefault();
    // get the mouse cursor position at startup:
    pos3 = e.clientX;
    pos4 = e.clientY;
    document.onmouseup = closeDragElement;
    // call a function whenever the cursor moves:
    document.onmousemove = elementDrag;
  }

  function elementDrag(e) {
    e = e || window.event;
    e.preventDefault();
    // calculate the new cursor position:
    pos1 = pos3 - e.clientX;
    pos2 = pos4 - e.clientY;
    pos3 = e.clientX;
    pos4 = e.clientY;
    // set the element's new position:
    elmnt.style.top = (elmnt.offsetTop - pos2) + "px";
    elmnt.style.left = (elmnt.offsetLeft - pos1) + "px";
  }

  function closeDragElement() {
    // stop moving when mouse button is released:
    document.onmouseup = null;
    document.onmousemove = null;
  }
}

Here is the HTML of the menu
<menu id="controls">

            <iron-icon class="show-button special-button arrow-img"  icon="image:adjust" style="color:[[eyeColor]];"></iron-icon>

            <paper-button on-click="hideShowOptions" id="arrow-operation" toggles >
                <iron-icon class="show-button arrow-img"  icon="icons:chevron-right" style="color:[[eyeColor]];"></iron-icon>
            </paper-button>

                <paper-button onclick="test1click()" toggles >
                    <iron-icon class="show-button"  icon="social:public" style="color:[[eyeColor]];"></iron-icon>
                </paper-button>
                <paper-button id="show" on-click="setOpacityTo">
                    <iron-icon class="show-button"  icon="image:remove-red-eye"></iron-icon>
                </paper-button>

</menu>


text:
Q: 'OpenFileDialog' is a type and cannot be used as an expression Hi I'm getting an error as the OpenFileDialog and SaveFileDialog  is a type and cannot be used as an expression could you please help me out in fixing those errors
     Private Sub btnEncode_Click(sender As Object, e As EventArgs)

        Using (SaveFileDialog sfd = New SaveFileDialog() {Filter() = "JPEG|*.jpg", ValidateNames = True})

            If (sfd.ShowDialog() = DialogResult.OK) Then

                MessagingToolkit.QRCode.Codec().QRCodeEncodere(encoder) = New
                MessagingToolkit.QRCode.Codec.QRCodeEncoder()
                encoder.QRCodeScale = 8
                Bitmap(bmp) = encoder.Encode(txt.Encode.Text)
                PictureBox.Image = bmp
                bmp.Save(sfd.FileName, ImageFormat.Jpeg)
            End If
        End Using
    End Sub

    Private Sub btnDecode_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPEG|*.jpg", ValidateNames = true, Multiselct - False})

            If (ofd.ShowDialog() = DialogResult.OK) Then

                PictureBox.Image = Image.FromeFile(ofd.FileName)
                MessagingToolkit.QRCode.Codec.QRCodeDecoder(Decoder) = New
                MessagingToolkit.QRCode.Codec.QRCodeDecoder()
                txtDecode.Text = decoder.Decode(New QRCodeBitmapImage = (PictureBox.ImageBitmap))
            End If
        End Using
    End Sub

A: You seem to have mixed up C# and VB.NET completely. If you were to write fully in  VB.NET, the code would be:
 Private Sub btnEncode_Click(sender As Object, e As EventArgs)

        Using sfd As SaveFileDialog = New SaveFileDialog() With {.Filter = "JPEG|*.jpg", .ValidateNames = True})

            If sfd.ShowDialog() = DialogResult.OK Then

                Dim encoder As MessagingToolkit.QRCode.Codec().QRCodeEncoder = New MessagingToolkit.QRCode.Codec.QRCodeEncoder()
                encoder.QRCodeScale = 8
                Dim bmp As Bitmap = encoder.Encode(txtEncode.Text)
                PictureBox.Image = bmp
                bmp.Save(sfd.FileName, ImageFormat.Jpeg)
            End If
        End Using
    End Sub

    Private Sub btnDecode_Click(sender As Object, e As EventArgs) Handles Button2.Click

        Using ofd As OpenFileDialog = new OpenFileDialog() With {.Filter = "JPEG|*.jpg", .ValidateNames = True, .Multiselect = False})

            If ofd.ShowDialog() = DialogResult.OK Then
                PictureBox.Image = Image.FromeFile(ofd.FileName)
                Dim decoder As MessagingToolkit.QRCode.Codec.QRCodeDecoder = New MessagingToolkit.QRCode.Codec.QRCodeDecoder()
                txtDecode.Text = decoder.Decode(New QRCodeBitmapImage(PictureBox.ImageBitmap))
            End If
        End Using
    End Sub

and if you wanted to write it fully in C#, the code would be:
 private void btnEncode_Click(object sender, EventArgs e)
{
        using (SaveFileDialog sfd = new SaveFileDialog() {Filter = "JPEG|*.jpg", ValidateNames = True})
        {
            if(sfd.ShowDialog() == DialogResult.OK)
            {
                MessagingToolkit.QRCode.Codec().QRCodeEncoder encoder = new MessagingToolkit.QRCode.Codec.QRCodeEncoder();
                encoder.QRCodeScale = 8;
                Bitmap bmp = encoder.Encode(txtEncode.Text);
                PictureBox.Image = bmp;
                bmp.Save(sfd.FileName, ImageFormat.Jpeg);
            }
        }
}

private void btnDecode_Click(object sender, EventArgs e)
{
        using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPEG|*.jpg", ValidateNames = true, Multiselect = False})
        {
            if (ofd.ShowDialog() == DialogResult.OK)
            {
                PictureBox.Image = Image.FromeFile(ofd.FileName);
                MessagingToolkit.QRCode.Codec.QRCodeDecoder decoder = New
                MessagingToolkit.QRCode.Codec.QRCodeDecoder();
                txtDecode.Text = decoder.Decode(New QRCodeBitmapImage(PictureBox.ImageBitmap));
            }
       }
}

The PictureBox control doesn't have an attribute named "ImageBitmap", so I'm not sure if you meant "Image"


text:
Q: How to use user input in Cluster(Node JavaScript ) Am trying to get an input in the main thread than use it in the working threads
so I have this code
Multi_processing = async() => {
if (cluster. IsMaster) {
    const name = await prompt(' input ');

    console.log(`Master ${process.pid} is running`);
    for (let i = 0; i <2; i++) {
      cluster.fork();
    }
    cluster.on('exit', (worker, code, signal) => {
      console.log(`worker ${worker.process.pid} finished`);
    });
  }
    else {

    console.log(name)

    console.log(`Worker ${process.pid} started`);
  }
}

when I try to get the input from outside the function it get the input as many the as the process which I don't want to input once to save up time and effort

A: By using Thomas Sablik Previous answer you can  get the input in this way
Multi_processing = (() => {
  return async () => {
    if (cluster.isMaster) {
      let name = prompt("ask")

      console.log(`Master ${process.pid} is running`);
      for (let i = 0; i < 2; i++) {
        cluster.fork({  name : name  });
      }
      cluster.on("exit", (worker, code, signal) => {
        console.log(`worker ${worker.process.pid} finished`);
      });
    } else {

      console.log(process.env.name);

    }
  };
})();


text:
Q: Local GIT server authentication I just setup a VM (Ubuntu Server 20.04.2), I setup GIT server on it which is working.
When I run git clone git@VM-IP:repos/repo it is cloning repo from repos dir in git's account home dir (or basically /home/git/repos/repo).
After I run the clone it is asking for password. If I use the git's account password it clones successfully. If I use passwordA (also tried with user@VM-IP.. as well) it is failing. I created .ssh/authorized_keys in /home/git in which I put the result of execution of ssh-keygen -t rsa from user in which I enter passwordA.
After browsing this issue for a while I've found a couple of url formats:
1) git@VM-IP:repo-path
2) git@VM-IP:user/repo-path
3) user@VM-IP:repo-path

Which of those is correct if I want to use user's password to clone the repo from /home/git/repo?
Also am I missing something with the keys or is it just URL issue?

A: Two things that were holding me back.

*

*git had password. If that is your case run sudo passwd -d git from your main user.

*There was one invalid key in the file so it was not reading it. For successful authentication you need user to generate rsa pair with ssh-keygen -t rsa and it should be in /home/user/.ssh, keep it there. Copy the content from id_rsa.pub into /home/git/.ssh/authorized_keys (Note that one line = one record!). Now if you do sudo su user; git clone git@localhost:repos/repo it will ask you for password of user and will clone /home/git/repos/repo into /home/user/repo.

With those two things everything is working now. Thanks for the replies!


text:
Q: Dotnet build in Azure DevOps with private package source cannot restore from private nuget feed Our project references packages in our private artifact source in Azure DevOps. When building the project in Azure DevOps the dotnet restore completes fine but dotnet build also tries to restore the packages and fails with
Unable to load the service index for source https://myazdevops.pkgs.visualstudio.com/_packaging/OurPackages/nuget/v3/index.json

The work around is adding --no-restore to both the dotnet build and dotnet publish tasks.
Is there some way to have the build and publish start working without there parameters?

A: I had similar issues with our internal NuGet feed.
I resolved it by adding nuget.config file in repository that contains both NuGet.org and our internal NuGet repository.
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="internal" value="URL_TO_INTERNAL_FEED" />
  </packageSources>
</configuration>

Then just specify in your Restore step Path to NuGet.config to this file.
Hope it will help.

A: I think your workaround is the solution, in the official docs written:

Starting with .NET Core 2.0 SDK, dotnet restore runs implicitly when
  you run dotnet build. If you want to disable implicit restore when
  running the build command, you can pass the --no-restore option.

You can't disable this behavior unless you add --no-restore.
See also this question & answer.

A: We have opened the source code in Github, you can refer to the code of dotnet build command. This is a compile command, so we did not make script in the task to set the authinfo additionally. Also, as you know, the dotnet restore runs implicitly while the dotnet build running only after .net core 2.0. In fact, this dotnet restore which runs implicitly is not a necessary part if you have been run dotnet restore before the dotnet build. That's why we offered the workaround - add --no-restore - to avoid this implicitly command.
This is a very convenient method which can make your compile process very concise. But if you still don't want this argument, you need do another configuration job to authorized with credential.
Configure the Azure Artifacts Credential Provider, then pass in the credentials with the VSS_NUGET_EXTERNAL_FEED_ENDPOINTS environment variable. VSS_NUGET_EXTERNAL_FEED_ENDPOINTS contain the endpoint credentials for any feed that you need to authenticate against with a JSON Format.


text:
Q: dropdown list wont populate values from database Hello everyone i need help. Ive been having this problem for almost a day now. dropdown list won't populate from database
Below is the code i am using:
<%@ Page Title="" Language="VB" MasterPageFile="~/Site.master" AutoEventWireup="false" CodeFile="PhotoAlbum.aspx.vb" Inherits="PhotoAlbum" %>

                Members Of Ephesians 5:10 Photo Album!

<asp:SqlDataSource ID="categoriesDataSource" runat="server"
    ConnectionString="<%$ ConnectionStrings:ConnectionString %>"

    SelectCommand="SELECT [CategoryID], [Name] FROM [Categories] WHERE ([UserId] = @UserId) ORDER BY [Name]">
    <SelectParameters>
        <asp:QueryStringParameter Name="UserId" QueryStringField="ID"/>
    </SelectParameters>
</asp:SqlDataSource>

Filter Pictures By Category:
   <asp:DropDownList ID="categories" runat="server"
                    AppendDataBoundItems="True"
              DataSourceID="categoriesDataSource" AutoPostBack="True"

DataTextField="Name" DataValueField="CategoryID">

</asp:Content>

i need help pls

A: set AutoEventWireup="true"  in page directive

A: I quickly created a test page with following code, it works for me:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="testddl.aspx.cs" Inherits="testddl" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <title></title>

    <form id="form1" runat="server">

        <asp:DropDownList ID="DropDownList1" runat="server"
            DataSourceID="SqlDataSource1" DataTextField="CategoryName"
            DataValueField="CategoryID">
        </asp:DropDownList>

    <asp:SqlDataSource ID="SqlDataSource1" runat="server"
        ConnectionString="<%$ ConnectionStrings:TESTDBConnectionString %>"
        SelectCommand="SELECT [CategoryID], [CategoryName] FROM [Categories] WHERE ([UserID] = @UserID)">
        <SelectParameters>
            <asp:QueryStringParameter DefaultValue="1" Name="UserID" QueryStringField="ID"
                Type="Int32" />
        </SelectParameters>
    </asp:SqlDataSource>
    </form>

dbo.Categories:

Screenshot:


text:
Q: Hadoop: unsupported major.minor version 52.0 Before you read my question, you should know that it's not a duplicate to all other similar questions on Stackoverflow that I already read!
I've developed (and built and compiled) a Hadoop program on Windows 10 (development machine) using Eclipse. The program reads WARC files and rewrite them in JSON format. It uses these classes to override the Writable format:
WarcFileInputFormat.java
WarcFileRecordReader.java
WritableWarcRecord.java

I added hadoop- 2.6.0 jars files to my project.
This is the java version of development machine:
$java -version
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

I tested my code on Ubuntu 14 machine (testing machine) and it just worked perfectly. this machine has hadoop- 2.6.0:
Hadoop 2.6.0
Subversion https://git-wip-us.apache.org/repos/asf/hadoop.git -r e3496499ecb8d220fba99dc5ed4c99c8f9e33bb1
Compiled by jenkins on 2014-11-13T21:10Z
Compiled with protoc 2.5.0
From source with checksum 18e43357c8f927c0695f1e9522859d6a
This command was run using /home/username/hadoop-2.6.0/share/hadoop/common/hadoop-common-2.6.0.jar

This is the java version of testing machine:
java version "1.8.0_91"
Java(TM) SE Runtime Environment (build 1.8.0_91-b14)
Java HotSpot(TM) 64-Bit Server VM (build 25.91-b14, mixed mode)

I moved to a CentOS oracle server and ran my program. This server has the same java version as my development machine:
java version "1.8.0_151"
Java(TM) SE Runtime Environment (build 1.8.0_151-b12)
Java HotSpot(TM) 64-Bit Server VM (build 25.151-b12, mixed mode)

and it had this Hadoop version:
Hadoop 2.6.0-cdh5.13.1
Subversion http://github.com/cloudera/hadoop -r 0061e3eb8ab164e415630bca11d299a7c2ec74fd
Compiled by jenkins on 2017-11-09T16:37Z
Compiled with protoc 2.5.0
From source with checksum 16d5272b34af2d8a4b4b7ee8f7c4cbe
This command was run using /opt/cloudera/parcels/CDH-5.13.1-1.cdh5.13.1.p0.2/jars/hadoop-common-2.6.0-cdh5.13.1.jar

On this server I got the following error for each job:
18/02/23 11:59:45 INFO mapreduce.Job: Task Id : attempt_1517308433710_0012_m_000003_0, Status : FAILED
Error: data/warc/WarcFileInputFormat : Unsupported major.minor version 52.0

Here are the things I tried and they didn't work:

*

*Adding the WARC readers' classes to my project as classes not as a jar to build them using the correct java version.

*Changing Hadoop jar files version from hadoop- 2.6.0 to hadoop- 2.6.0-cdh5.13.1

*Using mapred instead of mapreduce as the reader classes are using mapred
I'm not sure what exactly causes this issue especially that it points to the class WarcFileInputFormat.java that I didn't write but added to my project from the link I provided above. What surprised me is that the program worked perfectly on Ubuntu machine that has a lower java version, but didn't work on the CentOS server that has the same java version as the Windows development machine!
Any hints?

A: The problem was that Cloudera uses a lower version of JAVA:
/usr/java/jdk1.7.0_67-cloudera/bin/java

A: I had the same error message as yours, it occurred to me when I was implementing a Hive UDF.
I saw your answer and I tried Java 1.7 instead of 1.8 to build the JAR file of the UDF, and it worked.
I was using Cloudera Quickstart VM and it has JAVA_HOME set to Java 1.7


text:
Q: is not equal to the symbols(java) Sorry for my English. I want to find out for yourself one point, but I did not get. I want that line of output used in the case of the word. But I have prints like this: if I want to find a word - one in line is the application - ones entered the convent home. It is still output the line. And in this situation do not want displayed.
public static void main(String[] args) throws FileNotFoundException {
    String line = "line number ones";
    String word = "num";
    String myWord = "";
    int startWord = 0;

    for(int i = 0; i < line.length()-1; i++) {
        if(line.charAt(i) == word.charAt(startWord)) {
            startWord++;
            myWord += line.charAt(i);

            if(myWord.equals(word)) {
                if(startWord == word.length()) {
                    System.out.println(line);
                }
                startWord = 0;
            }
        }
    }
}

As need to make additional checks. something like:
if(Character.toString(line.charAt(i+1)) != any characters except space) {
output line
}

Turn out like this:
if(startWord == word.length() && Character.toString(line.charAt(i+1)) == " ") {
                        System.out.println(line);
                    }

But it does not work. And we must also take into account that can be a point, a comma, just the end of the line. How to do it?

A: Are you trying to check if a character is equal to space?If so, you cannot use == on a String because it is an object. But you can use it on a char.
So two ways are like this:
String space = " ";
if (space.equals (" ")) // true

Or
char space = ' ';
if (space == ' ') // true

In your example, you would do this:
Character.toString(line.charAt(i+1)).equals (" ")


text:
Q: Error reading from BufReader in nested loops I am been working on a program in Rust to read individual lines from a local text file, divide the line into a character vector and do some other operations. This is the snippet of my code:
use std::io::{BufRead, BufReader};
use std::fs::File;

fn main() {

   // ----<code snippet>-----

    let input_file = File::open("--<text file location>--").unwrap();
    let input_file = BufReader::new(input_file);
    let mut temp2 = String::new();
    let mut counter = 0;

    while counter < 12 {
        for line in input_file.lines() {
            let input_line = line.expect("Failed to read line");
            let temp: Vec<char> = input_line.chars().collect::<Vec<_>>();
            temp2.push(temp[counter]);
        }

      //-----<program continues without any issues>-------

Here is the error message as shown up in Cargo:
error[E0382]: use of moved value: `input_file`
    --> src\main.rs:48:21
     |
42   |     let input_file = BufReader::new(input_file);
     |         ---------- move occurs because `input_file` has type `BufReader<File>`, which does not implement the `Copy` trait
...
48   |         for line in input_file.lines() {
     |                     ^^^^^^^^^^ ------- `input_file` moved due to this method call, in previous iteration of loop
     |
note: this function takes ownership of the receiver `self`, which moves `input_file`
    --> C:\Users\Gumbi\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib/rustlib/src/rust\library\std\src\io\mod.rs:2258:14
     |
2258 |     fn lines(self) -> Lines<Self>
     |              ^^^^

error[E0382]: borrow of moved value: `temp2`
  --> src\main.rs:51:13
   |
44 |     let mut temp2 = String::new();
   |         --------- move occurs because `temp2` has type `String`, which does not implement the `Copy` trait
...
51 |             temp2.push(temp[counter]);
   |             ^^^^^ value borrowed here after move
...
54 |         let temp3 = most_common_digit(temp2);
   |                                       ----- value moved here, in previous iteration of loop

I know the basics of ownership and borrowing, but I am not able to grasp what is the problem in this code. Could anyone please help me in knowing where I am going wrong?

A: The problem is that input_file is moved inside the while loop scope. Instead use an intermediary &mut that can be dropped in each iteration:
use std::fs::File;
use std::io::{BufRead, BufReader};

fn main() {
    // ----<code snippet>-----

    let input_file = File::open("--<text file location>--").unwrap();
    let mut input_file = BufReader::new(input_file);
    let mut temp2 = String::new();
    let mut counter = 0;

    while counter < 12 {
        let mut input_file_ref = &mut input_file;

        for line in input_file_ref.lines() {
            let input_line = line.expect("Failed to read line");
            let temp: Vec<char> = input_line.chars().collect::<Vec<_>>();
            temp2.push(temp[counter]);
        }
    }
}

Playground


text:
Q: if $0 \notin \overline{T(S_X)}$ then $T(X)$ is closed Let X banach space and $T:X \to X$ compact operator with rank not finite. I want to show that $0 \in \overline{T(S_{X})}$. my idea is to suppose that  $0 \notin  \overline{T(S_{X})}$ then if I can show that $T(X)$ is closed ended, because i can use this result.
My problem now is to show that if $0 \notin \overline{T(S_X)}$ then $T(X)$ is closed, Can someone help me show this?

A: If $0\notin\overline{T(S_X)}$, then there exists $\varepsilon>0$ such that $T(S_X)\cap B_\varepsilon(0)=\varnothing$.  Hence $\lVert T(x)\rVert\geq\varepsilon\lVert x\rVert$ for all $x\in X$, so $T$ is left-invertible.  But that means $T(X)$ is closed and complemented in $X$.


text:
Q: Iterate through array and select every 2 elements Here's my code below:
array = [1, 2, 3, 4, 5, 6]
multiplie_array = [array[0]*2, array[1], array[2]*2, array[3], array[4]*2, array[5]]
=> [2, 2, 6, 4, 10, 6]

So the result is good, but imagine this code for an array composed of 1 million element.
My question : How do you iterate through an array according to a specific index and then multiply ?

A: You can achieve this by mapping your array, with an index:
[1, 2, 3, 4, 5, 6].map.with_index { |el,i| i.even? ? el * 2 : el }
#  => [2, 2, 6, 4, 10, 6]

Every element at an even index will get multiplied by 2, every odd element will be left untouched.

A: Here are two ways you could do that without an index.
arr = [1, 2, 3, 4, 5, 6]

#1
tf = [2, 1].cycle
  #=> #<Enumerator: [2, 1]:cycle>
arr.map { |el| el*tf.next }
  #=> [2, 2, 6, 4, 10, 6]

See Array#cycle.
#2
n = 1
arr.map { |el| (n = 3-n)*el }
  #=> [2, 2, 6, 4, 10, 6]


text:
Q: C Struct - field has incomplete type In my header file I have this
    typedef struct _client_value
{
    int client_id;
    struct timeval t;
    size_t size;
    char value[0];
} client_value;

I already included <time.h> but when I compiled, it said: field 't' has incomplete type struct timeval t.
I don't understand how this could happen.

A: Its #include <sys/time.h>


text:
Q: Convert sql data to Json Array [java spark] I have dataframe , wanted to convert into JSON ARRAY Please find the example below
Dataframe
+------------+--------------------+----------+----------------+------------------+--------------
|     Name|                  id|request_id|create_timestamp|deadline_timestamp|
+------------+--------------------+----------+----------------+------------------+--------------
|    Freeform|59bbe3ad-f487-44| htvjiwmfe|   1589155200000|   1591272659556
|         D23|59bbe3ad-f487-44| htvjiwmfe|   1589155200000|   1591272659556
|      Stores|59bbe3ad-f487-44| htvjiwmfe|   1589155200000|   1591272659556
|VacationClub|59bbe3ad-f487-44| htvjiwmfe|   1589155200000|   1591272659556

Wanted in Json Like below:

[
   {
      "testname":"xyz",
      "systemResponse":[
         {
            "name":"FGH",
            "id":"59bbe3ad-f487-44",
            "request_id":1590791280,
            "create_timestamp":1590799280

         },
         {
           "name":"FGH",
            "id":"59bbe3ad-f487-44",
            "request_id":1590791280,
            "create_timestamp":1590799280,
         }
      ]
   }
]

A: *

*You can define 2 beans

*Create Array from the 1st DF as Array of inner Beans

*Define a parent bean with testname and requestDetailArray as Array

Please also find code inline comments
object DataToJsonArray {

  def main(args: Array[String]): Unit = {

    val spark = Constant.getSparkSess

    import spark.implicits._

    //Load you dataframe
    val requestDetailArray = List(
      ("Freeform", "59bbe3ad-f487-44", "htvjiwmfe", "1589155200000", "1591272659556"),
      ("D23", "59bbe3ad-f487-44", "htvjiwmfe", "1589155200000", "1591272659556"),
      ("Stores", "59bbe3ad-f487-44", "htvjiwmfe", "1589155200000", "1591272659556"),
      ("VacationClub", "59bbe3ad-f487-44", "htvjiwmfe", "1589155200000", "1591272659556")
    ).toDF
      //Map your Dataframe to RequestDetails bean
      .map(row => RequestDetails(row.getString(0), row.getString(1), row.getString(2), row.getString(3), row.getString(4)))
      //Collect it as Array
      .collect()

    //Create another data frme with List[BaseClass] and set the (testname,Array[RequestDetails])
    List(BaseClass("xyz", requestDetailArray)).toDF()
      .write
      //Output your Dataframe as JSON
      .json("/json/output/path")
  }

}

case class RequestDetails(Name: String, id: String, request_id: String, create_timestamp: String, deadline_timestamp: String)

case class BaseClass(testname: String = "xyz", systemResponse: Array[RequestDetails])

A: Check below code.
import org.apache.spark.sql.functions._

df.withColumn("systemResponse",
     array(
           struct("id","request_id","create_timestamp","deadline_timestamp").as("data")
         )
)
.select("systemResponse")
.toJSON
.select(col("value").as("json_data"))
.show(false)

+-----------------------------------------------------------------------------------------------------------------------------------------------+
|json_data                                                                                |
+-----------------------------------------------------------------------------------------------------------------------------------------------+
|{"systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
|{"systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
|{"systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
|{"systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
+-----------------------------------------------------------------------------------------------------------------------------------------------+

Updated
scala> :paste
// Entering paste mode (ctrl-D to finish)

df.withColumn("systemResponse",
     array(
           struct("id","request_id","create_timestamp","deadline_timestamp").as("data")
         )
)
.withColumn("testname",lit("xyz"))
.select("testname","systemResponse")
.toJSON
.select(col("value").as("json_data"))
.show(false)

// Exiting paste mode, now interpreting.

+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
|json_data                                                                                |
+----------------------------------------------------------------------------------------------------------------------------------------------------------------+
|{"testname":"xyz","systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
|{"testname":"xyz","systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
|{"testname":"xyz","systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
|{"testname":"xyz","systemResponse":[{"id":"59bbe3ad-f487-44","request_id":"htvjiwmfe","create_timestamp":"1589155200000","deadline_timestamp":"1591272659556"}]}|
+----------------------------------------------------------------------------------------------------------------------------------------------------------------+


text:
Q: MySQL locking in Duplicate Key Error From the docs:

If a duplicate-key error occurs, a shared lock on the duplicate index
  record is set. This use of a shared lock can result in deadlock should
  there be multiple sessions trying to insert the same row if another
  session already has an exclusive lock. This can occur if another
  session deletes the row.

Going  with the example in the docs,
Suppose that an InnoDB table t1 has the following structure:
CREATE TABLE t1 (i INT, PRIMARY KEY (i)) ENGINE = InnoDB;

Now suppose that three sessions perform the following operations in order:
Session 1:
START TRANSACTION;
INSERT INTO t1 VALUES(1);

Session 2:
START TRANSACTION;
INSERT INTO t1 VALUES(1);

Session 3:
START TRANSACTION;
INSERT INTO t1 VALUES(1);

Session 1:
ROLLBACK;

The first operation by session 1 acquires an exclusive lock for the
  row. The operations by sessions 2 and 3 both result in a duplicate-key
  error and they both request a shared lock for the row. When session 1
  rolls back, it releases its exclusive lock on the row and the queued
  shared lock requests for sessions 2 and 3 are granted. At this point,
  sessions 2 and 3 deadlock: Neither can acquire an exclusive lock for
  the row because of the shared lock held by the other.

I have some questions :
1) The insert query takes an exclusive lock on the row it is inserting. So, suppose T1 is inserting on row 1, it will lock row 1. Now when T2 comes to write, will INNODB evaluate the query before executing it and find out that it is going to write the same PK (row with i = 1) and make T2 wait? Or will it start execution of T2 and find that it gives duplicate key error or PK violation.
2) Why are T2 and T3 taking shared locks? How do shared locks come into picture during insert?

A:
1) The insert query takes an exclusive lock on the row it is
  inserting. So, suppose T1 is inserting on row 1, it will lock row 1.
  Now when T2 comes to write, will INNODB evaluate the query before
  executing it and find out that it is going to write the same PK (row
  with i = 1) and make T2 wait? Or will it start execution of T2 and
  find that it gives duplicate key error or PK violation.

I think you are simplifying the terminology/process. After the query is parsed and before it is executed, it needs to acquire necessary locks. It is at this point that it is determined that:

*

*session 1 gets the exclusive lock, because it is inserting and there are no other locks

*session 2 and 3 get queued for the shared lock because the exclusive lock is already held by session 1, and session 2 and 3 are in a duplicate key error

2) Why are T2 and T3 taking shared locks? How do shared locks come
  into picture during insert?

Per above, sessions 2 and 3 get queued for shared locks because they are in duplicate key error. However, when session 1 deletes the key and releases the exclusive lock, now both session 2 and 3 get granted shared locks. At this point both try to acquire an exclusive lock to complete the insert. Neither one can, though, because the other is already holding the shared lock. So exclusive lock is not granted to either and they deadlock.

A: *

*For the sessions 2 and 3: INNODB evaluate the query before executing and determine if the row has locked (row with i = 1), the transactions will wait for unlock the implied row.
When you execute SHOW ENGINE INNODB STATUS after insert in first session and after run the inserts in sessions 2 and 3:
------------
TRANSACTIONS
------------
Trx id counter 2079155
Purge done for trx's n:o < 2079150 undo n:o < 0 state: running but idle
History list length 594
LIST OF TRANSACTIONS FOR EACH SESSION:
---TRANSACTION 2079154, ACTIVE 21 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 540, OS thread handle 0x7ff989386700, query id 1683 localhost root update
INSERT INTO t1 VALUES(1)
------- TRX HAS BEEN WAITING 21 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 4190 page no 3 n bits 72 index `PRIMARY` of table `temp`.`t1` trx id 2079154 lock mode S locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000001fb9af; asc       ;;
 2: len 7; hex 9c000001d30110; asc        ;;

------------------
---TRANSACTION 2079153, ACTIVE 43 sec inserting
mysql tables in use 1, locked 1
LOCK WAIT 2 lock struct(s), heap size 360, 1 row lock(s)
MySQL thread id 541, OS thread handle 0x7ff989355700, query id 1680 localhost root update
INSERT INTO t1 VALUES(1)
------- TRX HAS BEEN WAITING 43 SEC FOR THIS LOCK TO BE GRANTED:
RECORD LOCKS space id 4190 page no 3 n bits 72 index `PRIMARY` of table `temp`.`t1` trx id 2079153 lock mode S locks rec but not gap waiting
Record lock, heap no 2 PHYSICAL RECORD: n_fields 3; compact format; info bits 0
 0: len 4; hex 80000001; asc     ;;
 1: len 6; hex 0000001fb9af; asc       ;;
 2: len 7; hex 9c000001d30110; asc        ;;

After unlock the row (rollback from session 1) the sessions 2 will get the error: ERROR 1213 (40001): Deadlock found when trying to get lock; try restarting transaction, the session 3: Query OK, 1 row affected

*The sessions 2 and 3 doesn't have a shared lock, they are in queue to get one, because the lock of first session are exclusive, needs to wait. In this case the session 3 will get one and insert the record.

Shared lock:  A kind of lock that allows other transactions to read the locked object, and to also acquire other shared locks on it, but
  not to write to it. The opposite of exclusive lock.
Exclusive lock: A kind of lock that prevents any other transaction from locking the same row. Depending on the transaction isolation
  level, this kind of lock might block other transactions from writing
  to the same row, or might also block other transactions from reading
  the same row. The default InnoDB isolation level, REPEATABLE READ,
  enables higher concurrency by allowing transactions to read rows that
  have exclusive locks, a technique known as consistent read.

A: Question 2:
2) Why are T2 and T3 taking shared locks? How do shared locks come into picture during insert?

It requires a lock on the existing entry so that subsequent attempts to insert a duplicate record fail consistently。


text:
Q: How do I solve a 500 internal server error on a cgi file trying to run python I want to run a python script on a website which is hosted by Strato (.nl), and I'm trying to do this with a CGI file.
My code: cgi file, python file and a dependencies file to add something to the PATH
This is what the folders look like in the server from the website I have. I also changed all the permissions to 755
I followed this German guy's explanation step-by-step: https://www.youtube.com/watch?v=dCCSGR9CVk8. Everything went well except for the very final step, where he loads the page in his browser and gets a "Hello, World!" while I get a 500 Internal server error. The thing is, I have no idea at all what caused this error. The guy from the video and I have the same hosting and the video is not even a year old so it's not like a lot could have changed. I guess the first step to finding a solution would be figuring out what exactly causes this error, but it doesn't give any more information than the generic "500 internal server error". Thank you!

A: I found the solution, apperently my code was fine but the text editor I used added the wrong line endings. If you have this same problem, try changing the line endings in all your files from windows to unix.


text:
Q: What to test in this project? Every developer advocates test-driven development, but I am coding a website in NodeJS and I am not testing my app.
This is not because I don't see any reason. I know it allow me to check at each commit whether my code is right, thus avoiding security flaws.
I don't do any tests because I don't know how or what to test. I coded a MVC app with express + mongoose + passport, and I have no idea what to test or how to test. I know it is possible to mock express requests or mongodb, but I don' find that clean and flexible.
So, what and how to test?

A: If you want to test your code independently of NodeJS, create a service layer or repository layer that contains an API you can call on one side, and Node.JS calls on the other.  You can use your stubs or mocks on the methods in that layer, or even swap out the entire implementation of the service layer if that works for you.
What you test is the same as it ever was: methods.


text:
Q: Using cscript to output "ipconfig /all" but text file is blank I am trying to pull ipconfig /all output and put it into a text file.  I have created a small VBScript that runs ipconfig without issues.  Then I call it in another VBScript.  All of this runs, but the output text file remains empty and the primary VBScript doesn't seem to write anything after the ipconfig.vbs runs.
Here is the sample from the primary .vbs script:
' Pulling network config
Set objFSO = WScript.CreateObject("Scripting.FileSystemObject")
Set objFile = objFSO.CreateTextFile("C:\Users\dsadmin\Desktop\LogNet\network_config.txt", 8)
set objFile = objFSO.OpenTextFile("C:\Users\dsadmin\Desktop\LogNet\network_config.txt")
objShell.Run("cscript //nologo C:\Users\dsadmin\Downloads\ipconfig.vbs >C:\Users\dsadmin\Desktop\LogNet\network_config.txt")

Here is the script it calls (ipconfig.vbs):
Set objShell = CreateObject("WScript.Shell")
objShell.Run("ipconfig /all")

I'm out of ideas when it comes to shuffling things around.

A: Redirection (>) is a CMD builtin feature. You need to run the statement in CMD to be able to use it:
objShell.Run "%COMSPEC% /c cscript //NoLogo C:\ipconfig.vbs >C:\network_config.txt"

Of course you need to ensure that the second script writes to STDOUT in the first place, as @Lankymart pointed out.
If all your second script does is running ipconfig /all there's not much point in wrapping that in a separate script, though. Just run it directly:
objShell.Run "%COMSPEC% /c ipconfig /all >C:\network_config.txt"

A: You have two problems with that approach

*

*As @Ansgar-Wiechers points out the > redirection is part of CMD.

*Once the redirection is working you have to retrieve the Standard Output from the executed command and redirect it to the cscript.exe output. Unfortunately .Run() doesn't provide access to the Standard Output Stream you have to use .Exec() instead.
Here is an example (assumes all files in same direction, but can be modified);
' Pulling network config
Set objShell = CreateObject("WScript.Shell")
Call objShell.Run("%COMSPEC% /c cscript //nologo ipconfig.vbs > network_config.txt")

in the ipconfig.vbs
Set objShell = CreateObject("WScript.Shell")
Set exec = objShell.Exec("ipconfig /all")
'Redirect output from executed command to the script output.
Call WScript.StdOut.Write(exec.StdOut.ReadAll)

Output in network_config.txt
Windows IP Configuration

   Host Name . . . . . . . . . . . . :
   Primary Dns Suffix  . . . . . . . :
   Node Type . . . . . . . . . . . . :
   IP Routing Enabled. . . . . . . . : No
   WINS Proxy Enabled. . . . . . . . : No
   DNS Suffix Search List. . . . . . :

Wireless LAN adapter Local Area Connection* 2:

   Media State . . . . . . . . . . . : Media disconnected
   Connection-specific DNS Suffix  . :
   Description . . . . . . . . . . . : Microsoft Wi-Fi Direct Virtual Adapter
   Physical Address. . . . . . . . . :
   DHCP Enabled. . . . . . . . . . . : Yes
   Autoconfiguration Enabled . . . . : Yes
...

... Truncated for readability and sensitive data removed


text:
Q: Series-Shunt Feedback Amplifier Analysis - Finding Loop Gain So I'm trying to solve a problem I found in a textbook (won't say which one so people can't use it to cheat on their hw) and I haven't been able to arrive at the answer found in the appendix. Please note this is not a homework problem, I graduated from college last year and just reviewing for my own benefit and so I can finish an analog MPPT controller I'm designing.
The problem:

simulate this circuit – Schematic created using CircuitLab
Assume each mosfet in the above figure is biased so gm = 4mA/V and that the ro of each mosfet can be ignored. Find the loop gain AB assuming the value for RF is 900 Ohms (the value I calculated for making the closed-loop gain ideally (1/B) 10V/V in the first part of the problem, which is correct)
My attempt at an answer
I used the test-voltage method, where a break is made in the feedback loop and a test voltage is applied and then measured at the other end with t-model for Mosfets:
$$I_{o} = g_{m}V_{T}$$ $$I_{D1} = I_{F}\frac{R_{S1}}{R_{S1} + 1/g_{m}}$$
$$I_{F} = I_{o}\frac{R_{S2}}{R_{S2} + R_{F} + R_{S1} || 1/g_{m}}$$
$$I_{D1} = \frac{g_{m}V_{T}R_{S2}}{R_{S2} + R_{F} + R_{S1} || 1/g_{m}} \cdot \frac{R_{S1}}{R_{S1} + 1/g_{m}} $$
Output voltage of M1: $$V_{o1} = I_{D1}R_{D1}$$
Voltage at opposite end where feedback loop broken:
$$V_{r} = -g_{m}V_{o1}R_{D2} = -g_{m}I_{D1}R_{D1}R_{D2}$$
Loop Gain (Where Vt is test voltage):
$$A\beta = -\frac{V_{r}}{V_{T}}$$
$$A\beta = \frac{g_{m}^{2}R_{D1}R_{D2}R_{S1}R_{S2}}{R_{S2} + R_{F} + R_{S1} || 1/g_{m} \cdot (R_{S1} + 1/g_{m})} $$
However, this gives me the wrong answer, the value for loop gain should be 31.33 according to the appendix.
I must be doing something wrong in calculating the voltage gain of each stage but I haven't been able to wrap my head around it. Any insight in how to approach the problem and some background I might be lacking would be highly appreciated. Guess I'm a little rusty on my circuit theory...

A: Your circuit has voltage-series feedback (Series-Shunt). So, we can draw this equivalent circuit:

simulate this circuit – Schematic created using CircuitLab
The open-loop voltage gain \$A_{OL}\$ can be found out by inspection:
\$M_1\$ voltage gain is:
$$\frac{R_{D1}}{R_{S1}||R_F + \frac{1}{g_{m1}}} \approx 29.41 $$
\$M_2\$ voltage gain:
$$\frac{R_{D1}}{\frac{1}{g_{m2}}}=\frac{10k\Omega}{250 \Omega} = 40 $$
And \$M_3\$ voltage gain:
$$\frac{\left ( R_{F}+R_{S1} \right )||R_{S2}}{\frac{1}{g_{m3}}+\left ( R_{F}+R_{S1} \right )||R_{S2}} \approx 0.267 $$
Hence the open-loop voltage gain is :
$$A_{OL} \approx 314 $$
The feedback factor
$$\beta = \frac{V_{S1}}{V_O} = \frac{R_{S1}}{R_{S1}+R_F} = 0.1 $$
And finally the loop gain:
$$A_{OL}\,\beta = 314*0.1 = 31.4$$
And the Closed loop gain
$$A_{CL} = \frac{A_{OL}}{1+A_{OL}\,\beta} \approx 9.69$$

A: I've no time to write a more complete answer right now. Anyway, the last equation must be wrong, since the dimensions don't match.
Aβ must be a pure number, since it is a ratio between two voltages, whereas you have inconsistent units in the ratio in the right-hand side.
In fact in the numerator you have \$ \Omega^2 \$, whereas in the denominator you have a mismatch: you add \$ \Omega \$ to \$ \Omega^2 \$. Therefore there is an error in the math leading to that denominator (assuming the numerator is correct, you should have \$ \Omega^2 \$ as unit, in the denominator).
Time to check your math between your algebraic passages.

A: Your forward voltage gain (provided by M1 and M2) is over 1,000.
The rightmost Resistor is simply a voltage divider that reduces the 1.000 gain of M3 to something < 1.000. Again, the forward gain is over 1,000.
The feedback is 10:1, so the gain is 20dB.
By the way, I assume these 3 are NFETs. I prefer the bubble nomenclature on FET symbols.


text:
Q: Can't get People Picker value on 'Edit' form load When opening a SharePoint EDIT form, I'm trying to capture a people picker value using JavaScript.  Unfortunately, the people picker isn't loaded with data when I call .GetAllUserInfo.
I'm using the following line inside $(document).ready(function()...
SP.SOD.executeFunc('sp.js', 'SP.ClientContext', readyFunction);

When readyFunction() runs I get:

GetAllUserUserInfo: object is null or undefined

Basically it looks like I need to slow down the execution of my code until the people picker is fully loaded WITH the value.  Waiting for sp.js to be loaded doesn't seem to be the answer.  Any ideas?  Using setTimeout to call the function works, but it's obviously not an ideal way to have to do it.
Here is the code I expected to work:
$(document).ready(function(){

SP.SOD.executeFunc('sp.js', 'SP.ClientContext', theFunction);

theFunction(){
    var dispTitle = "myPpField";
    var pickerDiv = $("[id$='ClientPeoplePicker'][title='" + dispTitle + "']");
    var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv[0].id];
    var theUser = peoplePicker.GetAllUserInfo();
    var theUserId = theUser[0].EntityData.SPUserID;
    alert(theUserId);
}

});

A: Try wrapping your JavaScript inside the SharePoint 'ready' function:
<script>
function _spBodyOnLoad()
{
    var pickerPeople = SPClientPeoplePicker.SPClientPeoplePickerDict['<ID of my people picker>'].GetAllUserInfo();
    if (pickerPeople.length > 0) {
        alert("User: " + pickerPeople[0].DisplayText);
    }
}
</script>

Not sure how you are loading your JS. For my quick test, I put my script file on the edit form by clicking on the List tab, then Form Web Parts, then Default Edit Form. I then put a content editor web part on the page and linked it to my JS file in the documents library.
The code above is exactly what I have in my JS file, including the <script> tags.
EDIT
Based on your code snippet and the extra information you've provided, I tried again. Here is what works for me:
I put this snippet at the bottom of PlaceHolderMain in the Edit form using SharePoint Designer:
<script>
function _spBodyOnLoad()
{
    SP.SOD.executeFunc('sp.js', 'SP.ClientContext', function() {

        var dispTitle = "Users";
        var pickerDiv = document.getElementById("Users_3a52bbd5-aac9-4ced-84d2-080f9fa5f59e_$ClientPeoplePicker");
        var peoplePicker = SPClientPeoplePicker.SPClientPeoplePickerDict[pickerDiv.id];
        var theUser = peoplePicker.GetAllUserInfo();
        var theUserId = theUser[0].EntityData.SPUserID;
        alert("SP User ID: " + theUserId);

    });
}
</script>

You should be able to take your code out of the jQuery ready function and use the SharePoint ready function instead.
The only other difference for me was not using jQuery but you should be able to adapt my snippet to match yours.
Hopefully this solves your problem.

A: try to enclose your code in
_spBodyOnLoadFunctions.push(function(){
// code to capture people picker value
});

Or use JSLink  to add PostRender callback
ovverideCtx.OnPostRender = function(ctx){
   //code here
};

A: I have a template I use for all my scripts that I will post below. I believe it works when you delay the script because "sp.js" has finished loading by then. If you remove the delay you're not giving "sp.js" enough time to load. The script I use will not run until sp.js has finished loading, then it loads my functions and everything runs. I use a CEWP and point to the script file.
<SharePoint:ScriptLink Name="MicrosoftAjax.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.core.js" runat="server" Defer="False" Localizable="false"/>
<SharePoint:ScriptLink Name="SP.js" runat="server" Defer="True" Localizable="false"/>
<SharePoint:FormDigest ID="MyFormDigest" runat="server"/>

<script language="javascript" type="text/javascript">
ExecuteOrDelayUntilScriptLoaded(OnLoad, "sp.js");
    function OnLoad()
    {

    }   // End OnLoad
</script>

Place your code in the OnLoad wrapper function and you should be able to remove the delay. Hope this helps!