问:
Simple row transposition cipher
For a Lisp class, we were given a simple row transposition cipher homework, which I tried to solve in Haskell, too. Basically, one just splits a string into rows of length n, and then transposes the result. The concatenation of the resulting list of lists of chars is the encrypted string. Decoding is a little harder, since there may be missing elements in the last row of input (incomplete columns in the result), which have to be taken care of.

This is my solution in Haskell:

```<code>import Data.List
import Data.Ratio
import Data.List.Split

encode :: String -> Int -> String
encode s n = concat . transpose $ chunk n s

decode :: String -> Int -> String
decode s n = take len $ encode s' rows
    where s'     = foldr (insertAt " ") s idxs
          rows   = ceiling (len % n)
          idxs   = take (n-filled) [n*rows-1,(n-1)*rows-1..]
          filled = len - n * (rows - 1)
          len    = length s

insertAt :: [a] -> Int -> [a] -> [a]
insertAt xs i ys = pre ++ xs ++ post
    where (pre,post) = splitAt i ys
</code>```

It does the job, but I am not sure, whether this would be considered idiomatic Haskell, since my fiddling with the indices does not feel too declarative. Could this be improved, and if yes, how?

By the way: Is there something akin to insertAt in Haskell 98? I.e. a function inserting an element or list at a given index into a list.

Note: This is NOT part of the homework, which was due today anyway.

答:
I would do this by looking at the encode and decode problems slightly differently.  encode breaks up the data into a n-column matrix, which it then transposes (into a n-row matrix) and concatenates by rows.  decode breaks up the data into a n row matrix, which it then transposes (into a n columm matrix) and concatenates by rows.

So I'd start by defining two functions - one to make an array into an n column matrix:

```<code>chunk:: Int -> [a] -> [[a]]
chunk n as = chunk' n (length as) as
  where chunk' n l as | l <= n    = [as]
                      | otherwise = some : chunk' n (l-n) rest
                          where (some, rest) = splitAt n as
</code>```

and another to slice an array into an n row matrix:

```<code>slice :: Int -> [a] -> [[a]]
slice n as = chunk (q+1) front ++ chunk q back
  where (q,r) = length as `divMod` n
        (front, back) = splitAt (r*(q+1)) as
</code>```

Now, encoding and decoding is fairly easy:

```<code>encode :: Int -> [a] -> [a]
encode = ((concat . transpose) .). chunk
decode :: Int -> [a] -> [a]
decode = ((concat . transpose) .). slice
</code>```

Title: Simple row transposition cipher

Body:
For a Lisp class, we were given a simple row transposition cipher homework, which I tried to solve in Haskell, too. Basically, one just splits a string into rows of length n, and then transposes the result. The concatenation of the resulting list of lists of chars is the encrypted string. Decoding is a little harder, since there may be missing elements in the last row of input (incomplete columns in the result), which have to be taken care of.

This is my solution in Haskell:

import Data.List
import Data.Ratio
import Data.List.Split

encode :: String -> Int -> String
encode s n = concat . transpose $ chunk n s

decode :: String -> Int -> String
decode s n = take len $ encode s' rows
    where s'     = foldr (insertAt " ") s idxs
          rows   = ceiling (len % n)
          idxs   = take (n-filled) [n*rows-1,(n-1)*rows-1..]
          filled = len - n * (rows - 1)
          len    = length s

insertAt :: [a] -> Int -> [a] -> [a]
insertAt xs i ys = pre ++ xs ++ post
    where (pre,post) = splitAt i ys

It does the job, but I am not sure, whether this would be considered idiomatic Haskell, since my fiddling with the indices does not feel too declarative. Could this be improved, and if yes, how?

By the way: Is there something akin to insertAt in Haskell 98? I.e. a function inserting an element or list at a given index into a list.

Note: This is NOT part of the homework, which was due today anyway.

Body:
I would do this by looking at the encode and decode problems slightly differently.  encode breaks up the data into a n-column matrix, which it then transposes (into a n-row matrix) and concatenates by rows.  decode breaks up the data into a n row matrix, which it then transposes (into a n columm matrix) and concatenates by rows.

So I'd start by defining two functions - one to make an array into an n column matrix:

chunk:: Int -> [a] -> [[a]]
chunk n as = chunk' n (length as) as
  where chunk' n l as | l <= n    = [as]
                      | otherwise = some : chunk' n (l-n) rest
                          where (some, rest) = splitAt n as

and another to slice an array into an n row matrix:

slice :: Int -> [a] -> [[a]]
slice n as = chunk (q+1) front ++ chunk q back
  where (q,r) = length as `divMod` n
        (front, back) = splitAt (r*(q+1)) as

Now, encoding and decoding is fairly easy:

encode :: Int -> [a] -> [a]
encode = ((concat . transpose) .). chunk
decode :: Int -> [a] -> [a]
decode = ((concat . transpose) .). slice


来源: stackexchange

问:
Import JSON file in node application with TypeScript
I'm really getting crazy because I can't find a solution for this.
What I want to archive is to import a JSON file with a configuration into my TypeScript file.
I've learned that I need a declaration file. So I've added a file json-loader.d.ts into my project. I also tried it at several levels (root, typings folder, custom_typings folder) because this are the solutions I've found.
The file content looks like this:

declare module "json!*" {
    let json: any;
    export = json;
}

declare module "*.json" {
    const value: any;
    export default value;
}```
</div>
</div>
</p>

<p>But the compiler still tells me, that it is not possible to import the JSON file, because it isn't a module.
So, how is the compiler getting aware, that there is such a declaration file?</p>

<p>I already tried to modify my tsconfig.json like this:</p>

```{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "dist",
    "typeRoots": [
      "./node_modules/@types",
      "./typings"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}
```

But it still doesn't work. Any suggestions?

Thanks!

答:
Have you done something like add a SystemJS script in your web page to do module loading - index.html etc. I used https://cdnjs.com/libraries/systemjs and iirc you need https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.20.14/system.src.js System.JS is the module loader.. Has to be first script imported.
And then you need something like this:</p>

```<code>    <script
   src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.20.14/system.src.js "/>
    <script>
       System.config({
         defaultJSExtension:true
       });
      System.import('pathtoscriptwithoutdotjsatend');
   </script>
</code>```

ContentLicense: CC BY-SA 3.0

Body:
I'm really getting crazy because I can't find a solution for this.
What I want to archive is to import a JSON file with a configuration into my TypeScript file.
I've learned that I need a declaration file. So I've added a file json-loader.d.ts into my project. I also tried it at several levels (root, typings folder, custom_typings folder) because this are the solutions I've found.
The file content looks like this:

declare module "json!*" {
    let json: any;
    export = json;
}

declare module "*.json" {
    const value: any;
    export default value;
}

But the compiler still tells me, that it is not possible to import the JSON file, because it isn't a module.
So, how is the compiler getting aware, that there is such a declaration file?

I already tried to modify my tsconfig.json like this:

{
  "compilerOptions": {
    "target": "es6",
    "module": "commonjs",
    "outDir": "dist",
    "typeRoots": [
      "./node_modules/@types",
      "./typings"
    ]
  },
  "include": [
    "src/**/*.ts"
  ],
  "exclude": [
    "node_modules"
  ]
}

But it still doesn't work. Any suggestions?

Thanks!

Body:
Have you done something like add a SystemJS script in your web page to do module loading - index.html etc. I used https://cdnjs.com/libraries/systemjs and iirc you need https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.20.14/system.src.js System.JS is the module loader.. Has to be first script imported.
And then you need something like this:

    <script
   src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.20.14/system.src.js "/>
    <script>
       System.config({
         defaultJSExtension:true
       });
      System.import('pathtoscriptwithoutdotjsatend');
   </script>


问:
react + redux - 401 - unauthorized - missing headers in Request Headers
```<code>return fetch(`{SERVICE API URL}`, {
  method: 'GET',
  headers: {
    'userName': "username",
    'password': "password",
    'content-type': 'application/json'
  }
})
.then(response => response.json())
.then(json => dispatch(receivePosts(reddit, json)))
</code>```

I'm trying to get service API data with authorization headers, but getting 401 - Unauthorized error and the response is Missing Request Headers.

Tried with sending authorization content with body also - getting same error 401 - Unauthorized error.

Edited:

```<code> headers: {
        'userName': "xyz",
        'sessionToken': "xyz................."
      }
</code>```

When I'm checking with Postman client it is working fine, but not with the redux-saga fetch method. Kindly help me for this.

答:
You need to add an Authorization bearer header.

For instance:

```<code>headers = new Headers({
    'Authorization': `Bearer ${authorizationCodeOrCredentials}`
});
</code>```

In your code:

```<code>return fetch(`{SERVICE API URL}`, {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer ' + someValue, // Add this line
    'userName': "username",
    'password': "password",
    'content-type': 'application/json'
  }
})
.then(response => response.json())
.then(json => dispatch(receivePosts(reddit, json)))
</code>```

Body:
return fetch(`{SERVICE API URL}`, {
  method: 'GET',
  headers: {
    'userName': "username",
    'password': "password",
    'content-type': 'application/json'
  }
})
.then(response => response.json())
.then(json => dispatch(receivePosts(reddit, json)))

I'm trying to get service API data with authorization headers, but getting 401 - Unauthorized error and the response is Missing Request Headers.

Tried with sending authorization content with body also - getting same error 401 - Unauthorized error.

Edited:

 headers: {
        'userName': "xyz",
        'sessionToken': "xyz................."
      }

When I'm checking with Postman client it is working fine, but not with the redux-saga fetch method. Kindly help me for this.

Body:
You need to add an Authorization bearer header.

For instance:

headers = new Headers({
    'Authorization': `Bearer ${authorizationCodeOrCredentials}`
});

In your code:

return fetch(`{SERVICE API URL}`, {
  method: 'GET',
  headers: {
    'Authorization': 'Bearer ' + someValue, // Add this line
    'userName': "username",
    'password': "password",
    'content-type': 'application/json'
  }
})
.then(response => response.json())
.then(json => dispatch(receivePosts(reddit, json)))


问:
reading HttpwebResponse in json format
I have doubt about how creating a class for receiving the response from HttpWebResponse.

The code I use for receiving a json response is:

```<code>using (var response = (HttpWebResponse)request.GetResponse())
        {
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                var objText = reader.ReadToEnd();
                ResJson myojb = (ResJson )js.Deserialize(objText, typeof(ResJson ));
            }
        }
</code>```

The json I receive is:

```<code>{
"name": "Rube Goldberg Machine Stage 1",
"published": true,
"description": "<p>.STEP Version\n<br /><br><a href=\"http://grabcad.com/cadfiles/rube-goldberg-experiment\">Rube Goldberg Experiment</a></p>",
"raw_description": ".STEP Version\r\nhttp://grabcad.com/cadfiles/rube-goldberg-experiment",
"cached_slug": "rube-goldberg-machine-stage-1",
"created_at": "2011-04-06T21:58:06Z",
"updated_at": "2017-05-02T07:44:08Z",
"preview_image": "https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/08d3763d43243a1a5f88c89dbfb8910c/card.jpg",
"image_missing_url": "https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/missing_small.png",
"likes_count": 9,
"downloads_count": 116,
"comments_count": 1,
"contentfiles_count": 3,
"top_comments_count": 1,
"video_link": "https://youtu.be/paDE3KO7eb0",
"author": {
    "name": "Scott Bruins",
    "cached_slug": "scott.bruins",
    "avatar": "https://d2t1xqejof9utc.cloudfront.net/members/avatars/320/feed.gif?1316795450"
},
"tags": [
    "machine",
    "rube",
    "goldberg",
    "crowdcad"
],
"softwares": [
    {
        "name": "Other",
        "cached_slug": "other"
    },
    {
        "name": "STL",
        "cached_slug": "stl"
    },
    {
        "name": "Rendering",
        "cached_slug": "rendering"
    }
]
}
</code>```

When creating the ResJson class I can not figure out how set softwares variable type.

How should it be declared?

答:
```<code>public class Software
{
    [JsonProperty("name")]
    public string Name {get;set;}

    [JsonProperty("cached_slug")]
    public string CachedSlug {get;set;}
}
</code>```

And then in your ResJson:

```<code>{
    ...
    [JsonProperty("softwares")]
    public List<Software> Softwares {get;set;}
    ...
}
</code>```

Title: reading HttpwebResponse in json format

Body:
I have doubt about how creating a class for receiving the response from HttpWebResponse.

The code I use for receiving a json response is:

using (var response = (HttpWebResponse)request.GetResponse())
        {
            using (var reader = new StreamReader(response.GetResponseStream()))
            {
                JavaScriptSerializer js = new JavaScriptSerializer();
                var objText = reader.ReadToEnd();
                ResJson myojb = (ResJson )js.Deserialize(objText, typeof(ResJson ));
            }
        }

The json I receive is:

{
"name": "Rube Goldberg Machine Stage 1",
"published": true,
"description": "
.STEP Version\n

Rube Goldberg Experiment
",
"raw_description": ".STEP Version\r\nhttp://grabcad.com/cadfiles/rube-goldberg-experiment",
"cached_slug": "rube-goldberg-machine-stage-1",
"created_at": "2011-04-06T21:58:06Z",
"updated_at": "2017-05-02T07:44:08Z",
"preview_image": "https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/08d3763d43243a1a5f88c89dbfb8910c/card.jpg",
"image_missing_url": "https://d2t1xqejof9utc.cloudfront.net/screenshots/pics/missing_small.png",
"likes_count": 9,
"downloads_count": 116,
"comments_count": 1,
"contentfiles_count": 3,
"top_comments_count": 1,
"video_link": "https://youtu.be/paDE3KO7eb0",
"author": {
    "name": "Scott Bruins",
    "cached_slug": "scott.bruins",
    "avatar": "https://d2t1xqejof9utc.cloudfront.net/members/avatars/320/feed.gif?1316795450"
},
"tags": [
    "machine",
    "rube",
    "goldberg",
    "crowdcad"
],
"softwares": [
    {
        "name": "Other",
        "cached_slug": "other"
    },
    {
        "name": "STL",
        "cached_slug": "stl"
    },
    {
        "name": "Rendering",
        "cached_slug": "rendering"
    }
]
}

When creating the ResJson class I can not figure out how set softwares variable type.

How should it be declared?

Body:
public class Software
{
    [JsonProperty("name")]
    public string Name {get;set;}

    [JsonProperty("cached_slug")]
    public string CachedSlug {get;set;}
}

And then in your ResJson:

{
    ...
    [JsonProperty("softwares")]
    public List<Software> Softwares {get;set;}
    ...
}


问:
Fatal error: Call to a member function query() on a non-object in
Connection failed: SQLSTATE[28000] [1045] Access denied for user 'rkcat'@'localhost' (using password: YES)
Fatal error: Call to a member function query() on a non-object in

```<code> <?php
    $servername = "localhost";
    $username = "rkcat";
    $password = "rkcat123!@#";
    enter code here
    try {
      $conn = new PDO("mysql:host=$servername;dbname=shradha_padma", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    }
    catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }

    $sql = "SELECT * FROM slider";
    $result = $conn->query($sql);
    $data = $result->fetchAll(PDO::FETCH_ASSOC);

     ?>
</code>```

答:
DB Connection failed ,correct your connection params, or check if  user  "rkcat" has access rights in DB

also exit when you get connection error.

Body:
Connection failed: SQLSTATE[28000] [1045] Access denied for user 'rkcat'@'localhost' (using password: YES)
Fatal error: Call to a member function query() on a non-object in

 <?php
    $servername = "localhost";
    $username = "rkcat";
    $password = "rkcat123!@#";
    enter code here
    try {
      $conn = new PDO("mysql:host=$servername;dbname=shradha_padma", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    }
    catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }

    $sql = "SELECT * FROM slider";
    $result = $conn->query($sql);
    $data = $result->fetchAll(PDO::FETCH_ASSOC);

     ?>


问:
Manual Route Adjustment Using Google Maps API
In Google Maps for the web, it is possible to manually adjust an automatically created route by dragging a point on the path to any other road in view.  The Android app does not have this feature built-in.  Is it possible to manually adjust routes in an application that uses the com.google.android.maps API?</p>

答:
com.google.android.maps does not offer routing at all, let alone automated routing, let alone manual adjustments to automated routing.

If you are drawing your own routes using an overlay, you can respond to touch events in the overlay and adjust your route however you wish.

ContentLicense: CC BY-SA 2.5


问:
Check if two dictionaries are disjoint
Is there an easier/faster way to find out if two dictionaries are disjoint than calculating their intersection?

For the intersection I found this answer, so the disjoint-test would look like this:

```<code>def dicts_disjoint(a, b):
    keys_a = set(a.keys())
    keys_b = set(b.keys())
    intersection = keys_a & keys_b
    return not len(intersection)
</code>```

However I think this is inefficient since it always calculates the whole intersection (no short-circuit quit).

Any better ideas?

答:
Edited to display methods and timings only

Since the OP asked about the fastest method to perform this operation, I've ranked the ones under discussion according to a (I hope) fair test on my machine. The aim is to find if the keys of a dictionary are disjoint, and it seems the dict_keys.isdisjoint() method wins out over other set or list operations.

However, as mentioned in other answers, this will vary considerably depending on the size of the relative dictionaries and whether or not they are disjoint.

These tests are only for two disjoint dictionaries of equal (small) size.

Fastest: dict_keys.isdisjoint()

Example:

```<code>{"a": 1, "b": 2, "c": 3 }.keys().isdisjoint({ "d": 4, "e": 5, "f": 6}.keys())
</code>```

Timing:

```<code>>>> timeit.timeit('{"a": 1, "b": 2, "c": 3 }.keys().isdisjoint({ "d": 4, "e": 5, "f": 6}.keys())')
0.4637166199972853
</code>```

Second Fastest: set.isdisjoint()

Example:

```<code>set({"a": 1, "b": 2, "c": 3 }.keys()).isdisjoint(set({ "d": 4, "e": 5, "f": 6}.keys()))
</code>```

Timing:

```<code>>>> timeit.timeit('set({"a": 1, "b": 2, "c": 3 }.keys()).isdisjoint(set({ "d": 4, "e": 5, "f": 6}.keys()))')
0.774243315012427
</code>```

Third Fastest: List Comp and all():

Example:

```<code>all(k not in {"a": 1, "b": 2, "c": 3 } for k in { "d": 4, "e": 5, "f": 6})
</code>```

Timing:

```<code>>>> timeit.timeit('all(k not in {"a": 1, "b": 2, "c": 3 } for k in { "d": 4, "e": 5, "f": 6})')
0.8577601349970791
</code>```

Fourth Fastest: Symmetric Difference (^) with not()

Example:

```<code>not set({"a": 1, "b": 2, "c": 3 }.keys()) ^ set({ "d": 4, "e": 5, "f": 6}.keys())
</code>```

Timing:

```<code>>>> timeit.timeit('not set({"a": 1, "b": 2, "c": 3 }.keys()) ^ set({ "d": 4, "e": 5, "f": 6}.keys())')
0.9617313010094222
</code>```

Title: Check if two dictionaries are disjoint

Body:
Is there an easier/faster way to find out if two dictionaries are disjoint than calculating their intersection?

For the intersection I found this answer, so the disjoint-test would look like this:

def dicts_disjoint(a, b):
    keys_a = set(a.keys())
    keys_b = set(b.keys())
    intersection = keys_a & keys_b
    return not len(intersection)

However I think this is inefficient since it always calculates the whole intersection (no short-circuit quit).

Any better ideas?

Body:
Edited to display methods and timings only

Since the OP asked about the fastest method to perform this operation, I've ranked the ones under discussion according to a (I hope) fair test on my machine. The aim is to find if the keys of a dictionary are disjoint, and it seems the dict_keys.isdisjoint() method wins out over other set or list operations.

However, as mentioned in other answers, this will vary considerably depending on the size of the relative dictionaries and whether or not they are disjoint.

These tests are only for two disjoint dictionaries of equal (small) size.

Fastest: dict_keys.isdisjoint()

Example:

{"a": 1, "b": 2, "c": 3 }.keys().isdisjoint({ "d": 4, "e": 5, "f": 6}.keys())

Timing:

>>> timeit.timeit('{"a": 1, "b": 2, "c": 3 }.keys().isdisjoint({ "d": 4, "e": 5, "f": 6}.keys())')
0.4637166199972853

Second Fastest: set.isdisjoint()

Example:

set({"a": 1, "b": 2, "c": 3 }.keys()).isdisjoint(set({ "d": 4, "e": 5, "f": 6}.keys()))

Timing:

>>> timeit.timeit('set({"a": 1, "b": 2, "c": 3 }.keys()).isdisjoint(set({ "d": 4, "e": 5, "f": 6}.keys()))')
0.774243315012427

Third Fastest: List Comp and all():

Example:

all(k not in {"a": 1, "b": 2, "c": 3 } for k in { "d": 4, "e": 5, "f": 6})

Timing:

>>> timeit.timeit('all(k not in {"a": 1, "b": 2, "c": 3 } for k in { "d": 4, "e": 5, "f": 6})')
0.8577601349970791

Fourth Fastest: Symmetric Difference (^) with not()

Example:

not set({"a": 1, "b": 2, "c": 3 }.keys()) ^ set({ "d": 4, "e": 5, "f": 6}.keys())

Timing:

>>> timeit.timeit('not set({"a": 1, "b": 2, "c": 3 }.keys()) ^ set({ "d": 4, "e": 5, "f": 6}.keys())')
0.9617313010094222


问:
Eclipse scout hibernate
I used Eclipse Scout and i followed the instructions in the tutorial to create the sample application. It looks great and it was very easy to build an application with it.

I would like to ask if anyone has used it for a 'real' application and how it worked for him.
Is there a tutorial/example on how i could use Eclipse Scout with Hibernate?

答:
Now that Eclipse Scout has moved from OSGI to became J2EE oriented and maven based framework, I suppose that using Hibernate and other frameworks is easy.

EDIT :
There is an exemple of scout + spring boot + spring data integration :
https://github.com/BSI-Business-Systems-Integration-AG/ScoutBoot-Tasks

Title: Eclipse scout hibernate


问:
How to extend a Vec<String> as HashMap value?
I have a HashMap<String, Vec<String>>. I cannot figure out how to update the value by growing the Vec.  I thought the following would work:

```<code>fn add_employee(mut data: HashMap<String, Vec<String>>) -> HashMap<String, Vec<String>> {
    loop {
        println!("Please enter the name of the employee you would like to manage.");

        let mut employee = String::new();

        io::stdin().read_line(&mut employee).expect(
            "Failed to read line",
        );

        let employee = employee.trim();

        let mut department = String::new();

        println!("Please enter the name of the department you would like to add the employee to.");

        io::stdin().read_line(&mut department).expect(
            "Failed to read line",
        );

        let department = department.trim();

        data.entry(department.to_string())
            .extend(vec![employee.to_string()])
            .or_insert(vec![employee.to_string()]);
    }
}
</code>```

but it instead gives the error

error: no method named `extend` found for type `std::collections::hash_map::Entry<'_, std::string::String, std::vec::Vec<std::string::String>>` in the current scope
  --> src/main.rs:27:14
   |
27 |             .extend(vec![employee.to_string()])
   |              ^^^^^^
```

答:
Use this code:

```<code>use std::collections::hash_map::Entry;

match data.entry(department.to_string()) {
    Entry::Occupied(mut entry)  => { entry.get_mut().push(employee.to_string()); },
    Entry::Vacant(entry)        => { entry.insert(vec!(employee.to_string())); },
}
</code>```

If the key exists, get a mutable reference on the value and add the new string,

Else, create a new vector and insert it in the hashmap.

All this information is in the documentation.

Body:
I have a HashMap<String, Vec<String>>. I cannot figure out how to update the value by growing the Vec.  I thought the following would work:

fn add_employee(mut data: HashMap<String, Vec<String>>) -> HashMap<String, Vec<String>> {
    loop {
        println!("Please enter the name of the employee you would like to manage.");

        let mut employee = String::new();

        io::stdin().read_line(&mut employee).expect(
            "Failed to read line",
        );

        let employee = employee.trim();

        let mut department = String::new();

        println!("Please enter the name of the department you would like to add the employee to.");

        io::stdin().read_line(&mut department).expect(
            "Failed to read line",
        );

        let department = department.trim();

        data.entry(department.to_string())
            .extend(vec![employee.to_string()])
            .or_insert(vec![employee.to_string()]);
    }
}

but it instead gives the error

error: no method named `extend` found for type `std::collections::hash_map::Entry<'_, std::string::String, std::vec::Vec<std::string::String>>` in the current scope
  --> src/main.rs:27:14
   |
27 |             .extend(vec![employee.to_string()])
   |              ^^^^^^

Body:
Use this code:

use std::collections::hash_map::Entry;

match data.entry(department.to_string()) {
    Entry::Occupied(mut entry)  => { entry.get_mut().push(employee.to_string()); },
    Entry::Vacant(entry)        => { entry.insert(vec!(employee.to_string())); },
}

If the key exists, get a mutable reference on the value and add the new string,

Else, create a new vector and insert it in the hashmap.

All this information is in the documentation.


问:
Angular - animate time as variable
I'm writing a lathe simulator in Angular 4. Is it possible to set animate time to a variable?

I've got this component code:

```<code>@Component({
selector: 'lathe-cell',
templateUrl: './lathe-cell.component.html',
styleUrls: ['./lathe-cell.component.css'],
animations: [
    trigger('latheMould', [
        state('in', style({opacity: 0})),
        state('cuttingStart', style({})),
        state('cuttingEnd', style({ backgroundColor: 'green'})),
        state('out', style({opacity: 0})),
        transition('in => cuttingStart', [
            animate(3000, keyframes([
                style({ opacity: 1, transform: 'translate(-90px, 43px)', offset: 0 }),
                style({ opacity: 1, transform: 'translate(-90px, 0px)', offset: 0.4 }),
                style({ opacity: 1, transform: 'translate(0px, 0px)', offset: 1 })
            ]))
        ]),
        transition('cuttingStart => cuttingEnd', [
            animate(5000)
        ]),
        transition('cuttingEnd => out', [
            animate(3600, keyframes([
                style({ opacity: 1, transform: 'translate(90px, 0px)', offset: 0.5 }),
                style({ opacity: 1, transform: 'translate(90px, 80px)', offset: 1 })
            ]))
        ])
    ])
]
})

export class LatheCellComponent implements OnInit {

lathe: Lathe;
state: string = 'in';
logWell: string[] = new Array;

constructor(
    private latheService: LatheService,
    private route: ActivatedRoute
) { }

ngOnInit(): void {
    this.route.params
        .switchMap((params: Params) => this.latheService.getLathe(+params['id']))
        .subscribe(lathe => this.lathe = lathe);
}
}
</code>```

In a transition cuttingStart => cuttingEnd I would like to set the time to a variable lathe.cuttingTime. Is this possible?

Some code was omitted for clarity.

答:
This is currently not possible. However, you can work with animation-callbacks to inform your main lathe logic when an animation has finished (or started, though this is analogue to the time of setting state to the animation triggering value):</p>

```<code><div [@latheMould]="state"
     (@latheMould.start)="onStart($event)"
     (@latheMould.done)="onDone($event)">
</code>```

Title: Angular - animate time as variable

Body:
I'm writing a lathe simulator in Angular 4. Is it possible to set animate time to a variable?

I've got this component code:

@Component({
selector: 'lathe-cell',
templateUrl: './lathe-cell.component.html',
styleUrls: ['./lathe-cell.component.css'],
animations: [
    trigger('latheMould', [
        state('in', style({opacity: 0})),
        state('cuttingStart', style({})),
        state('cuttingEnd', style({ backgroundColor: 'green'})),
        state('out', style({opacity: 0})),
        transition('in => cuttingStart', [
            animate(3000, keyframes([
                style({ opacity: 1, transform: 'translate(-90px, 43px)', offset: 0 }),
                style({ opacity: 1, transform: 'translate(-90px, 0px)', offset: 0.4 }),
                style({ opacity: 1, transform: 'translate(0px, 0px)', offset: 1 })
            ]))
        ]),
        transition('cuttingStart => cuttingEnd', [
            animate(5000)
        ]),
        transition('cuttingEnd => out', [
            animate(3600, keyframes([
                style({ opacity: 1, transform: 'translate(90px, 0px)', offset: 0.5 }),
                style({ opacity: 1, transform: 'translate(90px, 80px)', offset: 1 })
            ]))
        ])
    ])
]
})

export class LatheCellComponent implements OnInit {

lathe: Lathe;
state: string = 'in';
logWell: string[] = new Array;

constructor(
    private latheService: LatheService,
    private route: ActivatedRoute
) { }

ngOnInit(): void {
    this.route.params
        .switchMap((params: Params) => this.latheService.getLathe(+params['id']))
        .subscribe(lathe => this.lathe = lathe);
}
}

In a transition cuttingStart => cuttingEnd I would like to set the time to a variable lathe.cuttingTime. Is this possible?

Some code was omitted for clarity.

Body:
This is currently not possible. However, you can work with animation-callbacks to inform your main lathe logic when an animation has finished (or started, though this is analogue to the time of setting state to the animation triggering value):

<div [@latheMould]="state"
     (@latheMould.start)="onStart($event)"
     (@latheMould.done)="onDone($event)">


问:
Create javascript array using xml attributes
Given this XML file

```<code><?xml version="1.0" encoding="UTF-8"?>
<GRAPHVS>
    <BASICS>
        <numbers name="model.XML" type="Euclidean/symmetric/mixed" number_of_vertices="2" number_of_links="1" Coordinate_System="Euclidean/UTM/Polar" date_creation="23/06/2017" hour_creation="12:16:24"/>
    </BASICS>
    <VERTICES>
        <node id="1" coordx="100.02346" coordy="80.00101" coordz="21.10201" group="1" r="1" g="0" b="0" node_type="simple"/>
        <node id="2" coordx="120.12346" coordy="89.02112" coordz="26.20111" group="2" r="1" g="0" b="0" node_type="origin"/>
        <node id="3" coordx="125.12346" coordy="80.02112" coordz="22.20111" group="2" r="1" g="0" b="0" node_type="destination"/>
        <node id="4" coordx="120.12786" coordy="79.17842" coordz="19.27811" group="3" r="0" g="0" b="1" node_type="center"/>
    </VERTICES>
    <LINKS>
        <link origin="1" destination="2" cost="177" edge="1" linklabel="0" required="1" Cost="177" group="1" r="" g="" b="" />
    </LINKS>
</GRAPHVS>
</code>```

Using the FileReader I want to get only a few attributes from this file, like id, coordx, coordy, coordz, r, g and b, to push them into a 2D Array like this:

```<code>var verticesArray = [
    [1, 100.02346, 80.00101, 21.10201, 1, 0, 0],
    [2, 120.12346, 89.02112, 26.20111, 1, 0, 0],
    [3, 125.12346, 80.02112, 22.20111, 1, 0, 0],
    [4, 120.12786, 79.17842, 19.27811, 0, 0, 1]
];
</code>```

So far I've only parsed the file, but I'm having trouble on how to get exactly those attributes into the array, since I'm kinda new with JS

```<code>function readXML(evt) {
    var xmlFile = evt.target.files;
    var verticesArray = [];
    if (xmlFile){
        var xmlReader = new FileReader();
        xmlReader.onload = function() {
            var parsed = new DOMParser().parseFromString(this.result, "text/xml");
            console.log(parsed);
        };
        xmlReader.readAsText(xmlFile[0]);
    } else {
        alert("Failed");
    }
}
</code>```

Any thoughts oh how can I manage that out?

Thanks :)

答:
You just need to query all the nodes using the querySelector API, and get the desired attributes from this elements:

/* This part is just to be able to run this snippet, in your case this string is coming from the file */
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<GRAPHVS>
    <BASICS>
        <numbers name="model.XML" type="Euclidean/symmetric/mixed" number_of_vertices="2" number_of_links="1" Coordinate_System="Euclidean/UTM/Polar" date_creation="23/06/2017" hour_creation="12:16:24"/>
    </BASICS>
    <VERTICES>
        <node id="1" coordx="100.02346" coordy="80.00101" coordz="21.10201" group="1" r="1" g="0" b="0" node_type="simple"/>
        <node id="2" coordx="120.12346" coordy="89.02112" coordz="26.20111" group="2" r="1" g="0" b="0" node_type="origin"/>
        <node id="3" coordx="125.12346" coordy="80.02112" coordz="22.20111" group="2" r="1" g="0" b="0" node_type="destination"/>
        <node id="4" coordx="120.12786" coordy="79.17842" coordz="19.27811" group="3" r="0" g="0" b="1" node_type="center"/>
    </VERTICES>
    <LINKS>
        <link origin="1" destination="2" cost="177" edge="1" linklabel="0" required="1" Cost="177" group="1" r="" g="" b="" />
    </LINKS>
</GRAPHVS>
`;

const xmlEl = new DOMParser().parseFromString(xml, 'text/xml');
const nodes = [...xmlEl.querySelectorAll("node")];
const columns = ["id", "coordx", "coordy", "r", "g", "b"];

const verticesArray = nodes.map(n => columns.map(col => n.getAttribute(col)));

console.log(verticesArray)```
</div>
</div>
</p>

<p>I'm using some ES2015 features as "const, "arrow functions" and the "spread operator (the tree dots)", but if you're using just ES5 you can just change it for "var"s, "function(){ }"s and the "Array slice" respectively:</p>

```var nodes = Array.prototype.slice.call(xmlEl.querySelectorAll("node"))
```

Body:
Given this XML file

<?xml version="1.0" encoding="UTF-8"?>
<GRAPHVS>
    <BASICS>
        <numbers name="model.XML" type="Euclidean/symmetric/mixed" number_of_vertices="2" number_of_links="1" Coordinate_System="Euclidean/UTM/Polar" date_creation="23/06/2017" hour_creation="12:16:24"/>
    </BASICS>
    <VERTICES>
        <node id="1" coordx="100.02346" coordy="80.00101" coordz="21.10201" group="1" r="1" g="0" b="0" node_type="simple"/>
        <node id="2" coordx="120.12346" coordy="89.02112" coordz="26.20111" group="2" r="1" g="0" b="0" node_type="origin"/>
        <node id="3" coordx="125.12346" coordy="80.02112" coordz="22.20111" group="2" r="1" g="0" b="0" node_type="destination"/>
        <node id="4" coordx="120.12786" coordy="79.17842" coordz="19.27811" group="3" r="0" g="0" b="1" node_type="center"/>
    </VERTICES>
    <LINKS>
        <link origin="1" destination="2" cost="177" edge="1" linklabel="0" required="1" Cost="177" group="1" r="" g="" b="" />
    </LINKS>
</GRAPHVS>

Using the FileReader I want to get only a few attributes from this file, like id, coordx, coordy, coordz, r, g and b, to push them into a 2D Array like this:

var verticesArray = [
    [1, 100.02346, 80.00101, 21.10201, 1, 0, 0],
    [2, 120.12346, 89.02112, 26.20111, 1, 0, 0],
    [3, 125.12346, 80.02112, 22.20111, 1, 0, 0],
    [4, 120.12786, 79.17842, 19.27811, 0, 0, 1]
];

So far I've only parsed the file, but I'm having trouble on how to get exactly those attributes into the array, since I'm kinda new with JS

function readXML(evt) {
    var xmlFile = evt.target.files;
    var verticesArray = [];
    if (xmlFile){
        var xmlReader = new FileReader();
        xmlReader.onload = function() {
            var parsed = new DOMParser().parseFromString(this.result, "text/xml");
            console.log(parsed);
        };
        xmlReader.readAsText(xmlFile[0]);
    } else {
        alert("Failed");
    }
}

Any thoughts oh how can I manage that out?

Thanks :)

Body:
You just need to query all the nodes using the querySelector API, and get the desired attributes from this elements:

/* This part is just to be able to run this snippet, in your case this string is coming from the file */
const xml = `<?xml version="1.0" encoding="UTF-8"?>
<GRAPHVS>
    <BASICS>
        <numbers name="model.XML" type="Euclidean/symmetric/mixed" number_of_vertices="2" number_of_links="1" Coordinate_System="Euclidean/UTM/Polar" date_creation="23/06/2017" hour_creation="12:16:24"/>
    </BASICS>
    <VERTICES>
        <node id="1" coordx="100.02346" coordy="80.00101" coordz="21.10201" group="1" r="1" g="0" b="0" node_type="simple"/>
        <node id="2" coordx="120.12346" coordy="89.02112" coordz="26.20111" group="2" r="1" g="0" b="0" node_type="origin"/>
        <node id="3" coordx="125.12346" coordy="80.02112" coordz="22.20111" group="2" r="1" g="0" b="0" node_type="destination"/>
        <node id="4" coordx="120.12786" coordy="79.17842" coordz="19.27811" group="3" r="0" g="0" b="1" node_type="center"/>
    </VERTICES>
    <LINKS>
        <link origin="1" destination="2" cost="177" edge="1" linklabel="0" required="1" Cost="177" group="1" r="" g="" b="" />
    </LINKS>
</GRAPHVS>
`;

const xmlEl = new DOMParser().parseFromString(xml, 'text/xml');
const nodes = [...xmlEl.querySelectorAll("node")];
const columns = ["id", "coordx", "coordy", "r", "g", "b"];

const verticesArray = nodes.map(n => columns.map(col => n.getAttribute(col)));

console.log(verticesArray)

I'm using some ES2015 features as "const, "arrow functions" and the "spread operator (the tree dots)", but if you're using just ES5 you can just change it for "var"s, "function(){ }"s and the "Array slice" respectively:

var nodes = Array.prototype.slice.call(xmlEl.querySelectorAll("node"))


问:
Create matrix from vector's rolling window
I would like to do something like this question but in R.

Given:

```<code>> my_vector
[1] 1 2 3 4 5 6
</code>```

And window_size = 3, I would like to get the following matrix:

```<code>> my_matrix
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    3    4
[3,]    3    4    5
[4,]    4    5    6
</code>```

As you can see, every row of the matrix is a window of the vector.

Is there any efficient way to do it in R without for loop?

答:
We can use embed

```<code>apply(embed(my_vector, 4), 1, rev)
#     [,1] [,2] [,3]
#[1,]    1    2    3
#[2,]    2    3    4
#[3,]    3    4    5
#[4,]    4    5    6
</code>```

Or it can be modified to

```<code>t(embed(rev(my_vector), 4))[, 3:1]
</code>```

Or as @lmo suggested

```<code>embed(my_vector, 3)[, 3:1]
</code>```

Or with matrix

```<code>matrix(my_vector, 7, 3)[1:4,]
</code>```

Body:
I would like to do something like this question but in R.

Given:

> my_vector
[1] 1 2 3 4 5 6

And window_size = 3, I would like to get the following matrix:

> my_matrix
     [,1] [,2] [,3]
[1,]    1    2    3
[2,]    2    3    4
[3,]    3    4    5
[4,]    4    5    6

As you can see, every row of the matrix is a window of the vector.

Is there any efficient way to do it in R without for loop?

Body:
We can use embed

apply(embed(my_vector, 4), 1, rev)
#     [,1] [,2] [,3]
#[1,]    1    2    3
#[2,]    2    3    4
#[3,]    3    4    5
#[4,]    4    5    6

Or it can be modified to

t(embed(rev(my_vector), 4))[, 3:1]

Or as @lmo suggested

embed(my_vector, 3)[, 3:1]

Or with matrix

matrix(my_vector, 7, 3)[1:4,]


问:
import bulk users (csv file) into a 2003 active directory server
I have a list of users that is pretty long, so long it would take too much time to do it one by one.

I've created so far the entire page enlisted like this:

"Name,Surname,Job,Login,Password"

I've used powershell and tried to put "adduser" along with the path in active directory, but i can't seem to make it work, "adduser" works on 2008 server but i do not know any orther way than this. and I couldn't find orther way at all.

i would like to ask if there is orther way to create a huge group of users with a command from powershell for 2003 servers, or even orther program than powershell that could import csv files to the active directory .

答:
Powershell 2.0 / ADDS cmdlets are likely not installed on your Windows 2003 server. If you install them, you can use New-ADUser as you would on 2008+.

See the following for instructions: https://blogs.technet.microsoft.com/danstolts/2011/03/how-to-install-powershell-on-windows-server-2003-and-enable-remote-powershell-managementall-servers-should-have-this-done/


问:
Keep logged in on each page
When i log in on my index.php, and then go to another page like members.php, i am a guest again. How can i do so they are logged in on each site? I know that sessions are involved, but cant figure it out. Any help is needed!

EDIT: Ok, so i have tried some stuff that you guys have commented and this is my final code:

my index.php

<?php
session_start();
?>

      <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

      <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>

      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title><?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?></title>
    <meta name="description" content="This is the Responsive Grid System, a quick, easy and flexible way to create a responsive web site.">
    <meta name="keywords" content="responsive, grid, system, web design">

    <meta name="author" content="www.grahamrobertsonmiller.co.uk">

    <meta http-equiv="cleartype" content="on">

    <link rel="shortcut icon" href="/favicon.ico">

    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="css/html5reset.css" media="all">
    <link rel="stylesheet" href="css/col.css" media="all">
    <link rel="stylesheet" href="css/2cols.css" media="all">

<link rel="stylesheet" href="demo.css">
<link rel="stylesheet" href="header-fixed.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Cookie' rel='stylesheet' type='text/css'>

<link href="http://fonts.googleapis.com/css?family=Roboto+Condensed:400,300,700" rel="stylesheet" type="text/css">

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?>

            <?php
$navigasjon = fopen("navigasjon.txt", "r") or die("En error har oppstått!!");
echo fread($navigasjon,filesize("navigasjon.txt"));
fclose($navigasjon);
?>

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?>

Teamspeak 3: <?php
$teamspeak = fopen("teamspeak.txt", "r") or die("En error har oppstått!!");
echo fread($teamspeak,filesize("teamspeak.txt"));
fclose($teamspeak);
?>

<marquee behavior="scroll" direction="right"><?php
$infonavb = fopen("infonavb.txt", "r") or die("En error har oppstått!!");
echo fread($infonavb,filesize("infonavb.txt"));
fclose($infonavb);
?></marquee>

Månedens klanspiller

                    <?php
$topspiller = fopen("topspiller.txt", "r") or die("En error har oppstått!!");
echo fread($topspiller,filesize("topspiller.txt"));
fclose($topspiller);
?>

Klan Info

                   <?php
$klaninfo = fopen("klaninfo.txt", "r") or die("En error har oppstått!!");
echo fread($klaninfo,filesize("klaninfo.txt"));
fclose($klaninfo);
?>

Logg inn

<?php
if (!isset($_POST['submit'])){
?>

 <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  Brukernavn: <input type="text" name="username" style="margin-top: 1%;" />

  Passord: <input type="password" name="password" style="margin-top: 1%;" />

  <input type="submit" name="submit" value="Login" class="knapp" style="margin-top: 1%;" />
 </form>

    Har du ikke en bruker enda?
    <form action="register.php" method="get">
            <input type="submit" name="register" value="Registrer">
        </form>
<?php
} else {
    require_once("db_const.php");
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    # check connection
    if ($mysqli->connect_errno) {
        echo "
MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}
";
        exit();
    }

    $username = $_POST['username'];
    $password = $_POST['password'];

    $_SESSION['username'] = $username;

    $sql = "SELECT * from users WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
    $result = $mysqli->query($sql);
    if (!$result->num_rows == 1) {
        echo "Invalid username/password combination";
    } else {
        echo "Du har logget inn som ";
        echo $_POST['username'];
        echo "";

        ?>

<form action="index.php" method="get">
            <input type="submit" name="on" value="Logg ut">
        </form>
<?php

function onFfunc(){
         session_destroy();
       }

    if(isset($_GET['on'])) {
   onFfunc();
}

    }
}

?>

<?php
include "fusion/upload/news.php";
?>

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?> Bedwars Clan | GommeHD & PvPHeroes

Copyright © 2017 | Coded by Thesevs

```
</div>
</div>
</p>

<p>my members.php
<div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
<div class="snippet-code">
<pre class="snippet-code-html lang-html prettyprint-override"><code><?php
session_start();
$_SESSION['username'] = $username;

if(isset($_SESSION['username'])){
?>

 <!DOCTYPE html>
<!-- HTML5 Boilerplate -->
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->

<head>

 <!--Import Google Icon Font-->
      <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
      <!--Import materialize.css-->
      <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>

      <!--Let browser know website is optimized for mobile-->
      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

 <meta charset="utf-8">
 <!-- Always force latest IE rendering engine & Chrome Frame -->
 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

 <title><?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?></title>
 <meta name="description" content="This is the Responsive Grid System, a quick, easy and flexible way to create a responsive web site.">
 <meta name="keywords" content="responsive, grid, system, web design">

 <meta name="author" content="www.grahamrobertsonmiller.co.uk">

 <meta http-equiv="cleartype" content="on">

 <link rel="shortcut icon" href="/favicon.ico">

 <!-- Responsive and mobile friendly stuff -->
 <meta name="HandheldFriendly" content="True">
 <meta name="MobileOptimized" content="320">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">

 <!-- Stylesheets -->
 <link rel="stylesheet" href="css/html5reset.css" media="all">
 <link rel="stylesheet" href="css/col.css" media="all">
 <link rel="stylesheet" href="css/2cols.css" media="all">
 <style type="text/css">

 /*
 ========================
 - Note: These styles are just to pretty the basic page up a bit.
 You should ignore these when copying and pasting into your site
 because your stylesheet should take care of making it look pretty!
 ========================
 */
 body { padding:2em; font : 100%/1.4 'Roboto Condensed', Helvetica, sans-serif;
 }
 h1 { font-size:2.2em; padding:0 0 .5em 0; }
 h2 { font-size:1.5em; }
 .header { padding:1em 0; }
 .col { background: black; color: white; padding: 1% 0; text-align: center;}

 </style>

<link rel="stylesheet" href="demo.css">
<link rel="stylesheet" href="header-fixed.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Cookie' rel='stylesheet' type='text/css'>

<link href="http://fonts.googleapis.com/css?family=Roboto+Condensed:400,300,700" rel="stylesheet" type="text/css">
</head>
<body>

<header class="header-fixed">

 <div class="header-limiter">

  <h1><?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?></h1>

  <nav>
   <?php
$navigasjon = fopen("navigasjon.txt", "r") or die("En error har oppstått!!");
echo fread($navigasjon,filesize("navigasjon.txt"));
fclose($navigasjon);
?>
  </nav>

 </div>

</header>

<!-- You need this element to prevent the content of the page from jumping up -->
<div class="header-fixed-placeholder"></div>

<div class="headbanner">
 <center>
<div class="headBannerText">
<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?></center>
</div>

</div>

<div class="infonav">
    <div class="infonavText">
        <center>
        <i><div style="float: left;">Teamspeak 3: <?php
$teamspeak = fopen("teamspeak.txt", "r") or die("En error har oppstått!!");
echo fread($teamspeak,filesize("teamspeak.txt"));
fclose($teamspeak);
?></div></i>
        <i><div style="float: right;"><span id="demo"></span> <span id="txt"></span></div></i>
        <div style="width: 60%;"><marquee behavior="scroll" direction="right"><?php
$infonavb = fopen("infonavb.txt", "r") or die("En error har oppstått!!");
echo fread($infonavb,filesize("infonavb.txt"));
fclose($infonavb);
?></marquee></div>

        </center>
    </div>
</div>

<script>
var day;
switch (new Date().getDay()) {
    case 0:
        day = "Søndag";
        break;
    case 1:
        day = "Mandag";
        break;
    case 2:
        day = "Tirsdag";
        break;
    case 3:
        day = "Onsdag";
        break;
    case 4:
        day = "Torsdag";
        break;
    case 5:
        day = "Fredag";
        break;
    case  6:
        day = "Lørdag";
}
document.getElementById("demo").innerHTML = day;
</script>

    <!-- HEADER SLUTTER HER -->
    <center>

    <br><br>
      <div id="wrapper">

    <div id="right">

        <div class="parent">

            <div class="main">

                <p>Månedens klanspillere</p>

                <div class="content" style="font-size: 19px;">

                    <?php
$topspiller = fopen("topspiller.txt", "r") or die("En error har oppstått!!");
echo fread($topspiller,filesize("topspiller.txt"));
fclose($topspiller);
?>

<style>
.list-group {
    padding-left: 0;
    margin-bottom: 15px;
}

.list-group-item {
    position: relative;
    display: block;
    padding: 7px 0px;
    background-color: #fff;
    border: 1px solid #ddd;
    border-top-left-radius: 4px;
    border-top-right-radius: 4px;
    border-bottom-left-radius: 4px;
    border-bottom-right-radius: 4px;
    margin: auto;
}

.badge {
    float: right;
    min-width: 10px;
    margin-right: 2%;
    padding: 3px 5px;
    font-size: 12px;
    font-weight: 700;
    line-height: 1;
    color: #fff;
    text-align: center;
    white-space: nowrap;
    vertical-align: middle;
    background-color: #777;
    border-radius: 10px;
}
</style>

                </div>
            </div>
       </div>

        <div class="parent">

            <div class="main">

                <p>Klan Info</p>

                <div class="content">

                    <?php
$klaninfo = fopen("klaninfo.txt", "r") or die("En error har oppstått!!");
echo fread($klaninfo,filesize("klaninfo.txt"));
fclose($klaninfo);
?>

                </div>
            </div>
        </div>

    </div>

    <div id="left">

        <?php
$stab = fopen("stab.txt", "r") or die("En error har oppstått!!");
echo fread($stab,filesize("stab.txt"));
fclose($stab);
?>

  </div>
</div>

<div class="footer"><div class="footerText">
<b><?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?></b> Bedwars Clan | GommeHD & PvPHeroes<br>
Copyright © 2017 | Coded by Thesevs
</div></div>

    <script src="http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script>

 $(document).ready(function(){

  var showHeaderAt = 150;

  var win = $(window),
    body = $('body');

  // Show the fixed header only on larger screen devices

  if(win.width() > 600){

   // When we scroll more than 150px down, we set the
   // "fixed" class on the body element.

   win.on('scroll', function(e){

    if(win.scrollTop() > showHeaderAt) {
     body.addClass('fixed');
    }
    else {
     body.removeClass('fixed');
    }
   });

  }

 });

</script>

</center>
</body>

    </html>
<?php

} else{

 header("Location: index.php");

}

?></code>```

But this is still not working, what am i doing wrong?

答:
You would want to use PHP Sessions.
 Once you log in, you start a session.
There is a super global $_SESSION. You could save your session data to this.
This is persistent and will stay intact until you unregister your variables or end your session.

One common mistake a beginner would do is forget the session_start() method.

To use session super global, you must call the session_start() function.

From my understanding, you seem to be a beginner with sessions. You would want to check PHP Sessions on w3schools.com. But make sure you move on to something else as soon as you get some basic understanding about what sessions are.

Hope this helps!

Title: Keep logged in on each page

Body:
When i log in on my index.php, and then go to another page like members.php, i am a guest again. How can i do so they are logged in on each site? I know that sessions are involved, but cant figure it out. Any help is needed!

EDIT: Ok, so i have tried some stuff that you guys have commented and this is my final code:

my index.php

<?php
session_start();
?>

      <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

      <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>

      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

    <meta charset="utf-8">

    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

    <title><?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?></title>
    <meta name="description" content="This is the Responsive Grid System, a quick, easy and flexible way to create a responsive web site.">
    <meta name="keywords" content="responsive, grid, system, web design">

    <meta name="author" content="www.grahamrobertsonmiller.co.uk">

    <meta http-equiv="cleartype" content="on">

    <link rel="shortcut icon" href="/favicon.ico">

    <meta name="HandheldFriendly" content="True">
    <meta name="MobileOptimized" content="320">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="css/html5reset.css" media="all">
    <link rel="stylesheet" href="css/col.css" media="all">
    <link rel="stylesheet" href="css/2cols.css" media="all">

<link rel="stylesheet" href="demo.css">
<link rel="stylesheet" href="header-fixed.css">
<link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Cookie' rel='stylesheet' type='text/css'>

<link href="http://fonts.googleapis.com/css?family=Roboto+Condensed:400,300,700" rel="stylesheet" type="text/css">

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?>

            <?php
$navigasjon = fopen("navigasjon.txt", "r") or die("En error har oppstått!!");
echo fread($navigasjon,filesize("navigasjon.txt"));
fclose($navigasjon);
?>

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?>

Teamspeak 3: <?php
$teamspeak = fopen("teamspeak.txt", "r") or die("En error har oppstått!!");
echo fread($teamspeak,filesize("teamspeak.txt"));
fclose($teamspeak);
?>

<marquee behavior="scroll" direction="right"><?php
$infonavb = fopen("infonavb.txt", "r") or die("En error har oppstått!!");
echo fread($infonavb,filesize("infonavb.txt"));
fclose($infonavb);
?></marquee>

Månedens klanspiller

                    <?php
$topspiller = fopen("topspiller.txt", "r") or die("En error har oppstått!!");
echo fread($topspiller,filesize("topspiller.txt"));
fclose($topspiller);
?>

Klan Info

                   <?php
$klaninfo = fopen("klaninfo.txt", "r") or die("En error har oppstått!!");
echo fread($klaninfo,filesize("klaninfo.txt"));
fclose($klaninfo);
?>

Logg inn

<?php
if (!isset($_POST['submit'])){
?>

 <form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  Brukernavn: <input type="text" name="username" style="margin-top: 1%;" />

  Passord: <input type="password" name="password" style="margin-top: 1%;" />

  <input type="submit" name="submit" value="Login" class="knapp" style="margin-top: 1%;" />
 </form>

    Har du ikke en bruker enda?
    <form action="register.php" method="get">
            <input type="submit" name="register" value="Registrer">
        </form>
<?php
} else {
    require_once("db_const.php");
    $mysqli = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
    # check connection
    if ($mysqli->connect_errno) {
        echo "
MySQL error no {$mysqli->connect_errno} : {$mysqli->connect_error}
";
        exit();
    }

    $username = $_POST['username'];
    $password = $_POST['password'];

    $_SESSION['username'] = $username;

    $sql = "SELECT * from users WHERE username LIKE '{$username}' AND password LIKE '{$password}' LIMIT 1";
    $result = $mysqli->query($sql);
    if (!$result->num_rows == 1) {
        echo "Invalid username/password combination";
    } else {
        echo "Du har logget inn som ";
        echo $_POST['username'];
        echo "";

        ?>

<form action="index.php" method="get">
            <input type="submit" name="on" value="Logg ut">
        </form>
<?php

function onFfunc(){
         session_destroy();
       }

    if(isset($_GET['on'])) {
   onFfunc();
}

    }
}

?>

<?php
include "fusion/upload/news.php";
?>

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?> Bedwars Clan | GommeHD & PvPHeroes

Copyright © 2017 | Coded by Thesevs

my members.php

<?php
session_start();
$_SESSION['username'] = $username;

if(isset($_SESSION['username'])){
?>

 <!DOCTYPE html>

      <link href="http://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">

      <link type="text/css" rel="stylesheet" href="css/materialize.min.css"  media="screen,projection"/>

      <meta name="viewport" content="width=device-width, initial-scale=1.0"/>

 <meta charset="utf-8">

 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">

 <title><?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?></title>
 <meta name="description" content="This is the Responsive Grid System, a quick, easy and flexible way to create a responsive web site.">
 <meta name="keywords" content="responsive, grid, system, web design">

 <meta name="author" content="www.grahamrobertsonmiller.co.uk">

 <meta http-equiv="cleartype" content="on">

 <link rel="shortcut icon" href="/favicon.ico">

 <meta name="HandheldFriendly" content="True">
 <meta name="MobileOptimized" content="320">
 <meta name="viewport" content="width=device-width, initial-scale=1.0">

 <link rel="stylesheet" href="css/html5reset.css" media="all">
 <link rel="stylesheet" href="css/col.css" media="all">
 <link rel="stylesheet" href="css/2cols.css" media="all">

<link rel="stylesheet" href="demo.css">
<link rel="stylesheet" href="header-fixed.css">
    <link rel="stylesheet" type="text/css" href="css/style.css">
<link href='http://fonts.googleapis.com/css?family=Cookie' rel='stylesheet' type='text/css'>

<link href="http://fonts.googleapis.com/css?family=Roboto+Condensed:400,300,700" rel="stylesheet" type="text/css">

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?>

   <?php
$navigasjon = fopen("navigasjon.txt", "r") or die("En error har oppstått!!");
echo fread($navigasjon,filesize("navigasjon.txt"));
fclose($navigasjon);
?>

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?>

Teamspeak 3: <?php
$teamspeak = fopen("teamspeak.txt", "r") or die("En error har oppstått!!");
echo fread($teamspeak,filesize("teamspeak.txt"));
fclose($teamspeak);
?>

<marquee behavior="scroll" direction="right"><?php
$infonavb = fopen("infonavb.txt", "r") or die("En error har oppstått!!");
echo fread($infonavb,filesize("infonavb.txt"));
fclose($infonavb);
?></marquee>

Månedens klanspillere

                    <?php
$topspiller = fopen("topspiller.txt", "r") or die("En error har oppstått!!");
echo fread($topspiller,filesize("topspiller.txt"));
fclose($topspiller);
?>

Klan Info

                    <?php
$klaninfo = fopen("klaninfo.txt", "r") or die("En error har oppstått!!");
echo fread($klaninfo,filesize("klaninfo.txt"));
fclose($klaninfo);
?>

        <?php
$stab = fopen("stab.txt", "r") or die("En error har oppstått!!");
echo fread($stab,filesize("stab.txt"));
fclose($stab);
?>

<?php
$klan = fopen("klan.txt", "r") or die("En error har oppstått!!");
echo fread($klan,filesize("klan.txt"));
fclose($klan);
?> Bedwars Clan | GommeHD & PvPHeroes

Copyright © 2017 | Coded by Thesevs

<?php

} else{

 header("Location: index.php");

}

?>

But this is still not working, what am i doing wrong?


问:
How to do a deep comparison between 2 objects with lodash?
I have 2 nested objects which are different and I need to know if they have a difference in one of their nested properties.

var a = {};
var b = {};

a.prop1 = 2;
a.prop2 = { prop3: 2 };

b.prop1 = 2;
b.prop2 = { prop3: 3 };
```

The object could be much more complex with more nested properties. But this one is a good example. I have the option to use recursive functions or something with lodash...

答:
```<code>var isEqual = function(f,s) {
  if (f === s) return true;

  if (Array.isArray(f)&&Array.isArray(s)) {
    return isEqual(f.sort(), s.sort());
  }
  if (_.isObject(f)) {
    return isEqual(f, s);
  }
  return _.isEqual(f, s);
};
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I have 2 nested objects which are different and I need to know if they have a difference in one of their nested properties.

var a = {};
var b = {};

a.prop1 = 2;
a.prop2 = { prop3: 2 };

b.prop1 = 2;
b.prop2 = { prop3: 3 };

The object could be much more complex with more nested properties. But this one is a good example. I have the option to use recursive functions or something with lodash...


Title: Create matrix from vector's rolling window

Body:
sapply(1:3, function(i) my_vector[i:(i+3)])
#     [,1] [,2] [,3]
#[1,]    1    2    3
#[2,]    2    3    4
#[3,]    3    4    5
#[4,]    4    5    6


问:
Spring error while sending email
I try to send email using spring framework.I'm a beginner so feel free to explain or suggest me. I've the following bean declaration

```<code> @Configuration
public class EmailConfig {

     @Bean
        public JavaMailSender getMailSender(){
            JavaMailSenderImpl mailSender = new JavaMailSenderImpl();

            //Using gmail
            mailSender.setHost("smtp.gmail.com");
            mailSender.setPort(587);
            mailSender.setUsername("xxxxxx@gmail.com");
            mailSender.setPassword("xxxxxx");

            Properties javaMailProperties = new Properties();
            javaMailProperties.put("mail.smtp.starttls.enable", "true");
            javaMailProperties.put("mail.smtp.auth", "true");
            javaMailProperties.put("mail.transport.protocol", "smtp");
            javaMailProperties.put("mail.debug", "true");//Prints out everything on screen

            mailSender.setJavaMailProperties(javaMailProperties);
            return mailSender;
        }

}
</code>```

This is my class for sending email

```<code>public class SendEmail {

private JavaMailSender mailSender;

public void setMailSender(JavaMailSender mailSender) {
    this.mailSender = mailSender;
}

public void send(String to, String subject, String text){

    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo(to);
    message.setSubject(subject);
    message.setText(text);
    mailSender.send(message);
  }

}
</code>```

I've used above as

```<code> try{
     SendEmail mm = new SendEmail();
     mm.send("abc@gmail.com", "do not reply", "this is the template mesage");
 }catch(Exception ex){
     ex.printStackTrace();
 }
</code>```

above code gives following console error

```<code>java.lang.NullPointerException
    at com.sparktronix.mvc.mail.SendEmail.send(SendEmail.java:20)
    at com.sparktronix.mvc.controllers.RegistrationController.userRegistration(RegistrationController.java:142)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
</code>```

at com.sparktronix.mvc.mail.SendEmail.send(SendEmail.java:20)

this error is for

```<code>  public void send(String to, String subject, String text){

     SimpleMailMessage message = new SimpleMailMessage();
     message.setTo(to);
     message.setSubject(subject);
     message.setText(text);
     mailSender.send(message); } //this line is creating the error
</code>```

It will be nice if somebody helps me. Any suggestion is welcome. Thanks in advance

答:
Spring doesn't know about your service. One way to do this is:

```<code>@Service
public class SendEmailService {

   @Autowired
   @Setter //using lombok
   private JavaMailSenderImpl mailSender;

   public void send(String to, String subject, String text){

       SimpleMailMessage message = new SimpleMailMessage();
       message.setTo(to);
       message.setSubject(subject);
       message.setText(text);
       mailSender.send(message);
   }
}
</code>```

Note that the class above is annotated with @Service and we autowire (dependency inject) the mailSender.  You can alternatively use constructor injection.

When you want to call the service, you can do:

```<code>@Autowired
private SendEmailService sendEmailService;

try {
    sendEmailService.send("abc@gmail.com", "do not reply", "this is the template mesage");
}
catch (Exception ex) {
   ex.printStackTrace(); //but use a logger instead
}
</code>```

Title: Spring error while sending email

Body:
I try to send email using spring framework.I'm a beginner so feel free to explain or suggest me. I've the following bean declaration

 @Configuration
public class EmailConfig {

     @Bean
        public JavaMailSender getMailSender(){
            JavaMailSenderImpl mailSender = new JavaMailSenderImpl();

            //Using gmail
            mailSender.setHost("smtp.gmail.com");
            mailSender.setPort(587);
            mailSender.setUsername("xxxxxx@gmail.com");
            mailSender.setPassword("xxxxxx");

            Properties javaMailProperties = new Properties();
            javaMailProperties.put("mail.smtp.starttls.enable", "true");
            javaMailProperties.put("mail.smtp.auth", "true");
            javaMailProperties.put("mail.transport.protocol", "smtp");
            javaMailProperties.put("mail.debug", "true");//Prints out everything on screen

            mailSender.setJavaMailProperties(javaMailProperties);
            return mailSender;
        }

}

This is my class for sending email

public class SendEmail {

private JavaMailSender mailSender;

public void setMailSender(JavaMailSender mailSender) {
    this.mailSender = mailSender;
}

public void send(String to, String subject, String text){

    SimpleMailMessage message = new SimpleMailMessage();
    message.setTo(to);
    message.setSubject(subject);
    message.setText(text);
    mailSender.send(message);
  }

}

I've used above as

 try{
     SendEmail mm = new SendEmail();
     mm.send("abc@gmail.com", "do not reply", "this is the template mesage");
 }catch(Exception ex){
     ex.printStackTrace();
 }

above code gives following console error

java.lang.NullPointerException
    at com.sparktronix.mvc.mail.SendEmail.send(SendEmail.java:20)
    at com.sparktronix.mvc.controllers.RegistrationController.userRegistration(RegistrationController.java:142)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
    at java.lang.reflect.Method.invoke(Unknown Source)
    at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205)
    at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:133)
    at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:116)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
    at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
    at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:872)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
    at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:846)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:330)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.invoke(FilterSecurityInterceptor.java:118)
    at org.springframework.security.web.access.intercept.FilterSecurityInterceptor.doFilter(FilterSecurityInterceptor.java:84)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.access.ExceptionTranslationFilter.doFilter(ExceptionTranslationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.session.SessionManagementFilter.doFilter(SessionManagementFilter.java:103)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AnonymousAuthenticationFilter.doFilter(AnonymousAuthenticationFilter.java:113)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.servletapi.SecurityContextHolderAwareRequestFilter.doFilter(SecurityContextHolderAwareRequestFilter.java:154)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.savedrequest.RequestCacheAwareFilter.doFilter(RequestCacheAwareFilter.java:45)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter.doFilter(AbstractAuthenticationProcessingFilter.java:199)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.authentication.logout.LogoutFilter.doFilter(LogoutFilter.java:110)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.header.HeaderWriterFilter.doFilterInternal(HeaderWriterFilter.java:57)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.SecurityContextPersistenceFilter.doFilter(SecurityContextPersistenceFilter.java:87)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.context.request.async.WebAsyncManagerIntegrationFilter.doFilterInternal(WebAsyncManagerIntegrationFilter.java:50)
    at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
    at org.springframework.security.web.FilterChainProxy$VirtualFilterChain.doFilter(FilterChainProxy.java:342)
    at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:192)
    at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:160)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:262)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:198)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1410)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

at com.sparktronix.mvc.mail.SendEmail.send(SendEmail.java:20)

this error is for

  public void send(String to, String subject, String text){

     SimpleMailMessage message = new SimpleMailMessage();
     message.setTo(to);
     message.setSubject(subject);
     message.setText(text);
     mailSender.send(message); } //this line is creating the error

It will be nice if somebody helps me. Any suggestion is welcome. Thanks in advance

Body:
Spring doesn't know about your service. One way to do this is:

@Service
public class SendEmailService {

   @Autowired
   @Setter //using lombok
   private JavaMailSenderImpl mailSender;

   public void send(String to, String subject, String text){

       SimpleMailMessage message = new SimpleMailMessage();
       message.setTo(to);
       message.setSubject(subject);
       message.setText(text);
       mailSender.send(message);
   }
}

Note that the class above is annotated with @Service and we autowire (dependency inject) the mailSender.  You can alternatively use constructor injection.

When you want to call the service, you can do:

@Autowired
private SendEmailService sendEmailService;

try {
    sendEmailService.send("abc@gmail.com", "do not reply", "this is the template mesage");
}
catch (Exception ex) {
   ex.printStackTrace(); //but use a logger instead
}


问:
How to find all instances of a procedure (or function) in SQL Server 2005/2008
I modified a procedure and it now takes a greater number of parameters. How can I find every place that the procedure is called so I can update the number of arguments the proc is passed?

I tried this:

```<code>select * from syscomments where text like '%MODIFIED-PROCEDURE-NAME%'
</code>```

but I'm still finding other places the proc is called that this query did not return.

答:
use sys.sql_modules:

```<code>SELECT
    OBJECT_SCHEMA_NAME(m.object_id) + '.' + OBJECT_NAME(m.object_id)
    FROM sys.sql_modules  m
    WHERE m.definition like '%whatever%'
</code>```

sys.sql_modules.definition is nvarchar(max).  Other similar views have nvarchar(4000) columns, where the text is split over multiple rows.

Body:
I modified a procedure and it now takes a greater number of parameters. How can I find every place that the procedure is called so I can update the number of arguments the proc is passed?

I tried this:

select * from syscomments where text like '%MODIFIED-PROCEDURE-NAME%'

but I'm still finding other places the proc is called that this query did not return.

Body:
use sys.sql_modules:

SELECT
    OBJECT_SCHEMA_NAME(m.object_id) + '.' + OBJECT_NAME(m.object_id)
    FROM sys.sql_modules  m
    WHERE m.definition like '%whatever%'

sys.sql_modules.definition is nvarchar(max).  Other similar views have nvarchar(4000) columns, where the text is split over multiple rows.


问:
Need a way to delete a file in Livelink from a cmd prompt
Would there be a way to delete a file in Livelink (OpenText Content Server 10 to be exact) from a command prompt?

I should delete more than 7000 documents, thus it would be quite slow to do it manually. I could generate the object ID's from SQL Server and ideally would run the delete calls one-by-one programmatically on command line.

答:
You have many options to do it but not from the CMD.

If you have access to the database you can change item parentId to common folder and then delete that folder. Be careful when playing around with DB directly.

You can built LAPI application if you are familiar with coding.

If you have web services you can use custom application or program like JMeter, SoapUI to delete all documents.

Use LL Explorer to delete them

....

It depends how many times you have to execute this job.


答: Evidently the program does not like the fact that you have missing values, probably because you're generating a matrix, so it doesn't like replacing missing values with Nans. Try adding 0's in the places with missing values, or at least the tab delimiter so that it will register as having all 174 columns.</p>

Title: loading my data in numpy genfromtxt get errors

Body:
I have my data file contain 7500 lines with :

Y1C 1.53    -0.06   0.58    0.52    0.42    0.16    0.79        -0.6    -0.3
-0.78   -0.14   0.38    0.34    0.23    0.26    -1.8    -0.1    -0.17   0.3
0.6 0.9 0.71    0.5 0.49    1.06    0.25    0.96    -0.39   0.24    0.69
0.41    0.7 -0.16   -0.39   0.6 1.04    0.4 -0.04   0.36    0.23    -0.14
-0.09   0.15    -0.46   -0.05   0.32    -0.54   -0.28   -0.15   1.34    0.29
0.59    -0.43   -0.55   -0.18   -0.01   0.68        -0.06   -0.11   -0.67
-0.25   -0.34   -0.38   0.02    -0.21   0.12    0.01    0.07    0.15    0.14
0.15    -0.11   0.07    -0.41   -0.2    0.24    0.06    0.12    0.12    0.11
0.1 0.24    -0.71   0.22    -0.02   0.15    0.84    1.39    0.13    0.48
0.19    -0.23   -0.12   0.33    0.37    0.18    0.06    0.32    0.09
-0.09   0.02    -0.01   -0.06   -0.23   0.52    0.14    0.24    -0.05   0.37
0.1 0.45    0.38    1.34    0.74    0.5 0.92    0.91    1.34    1.78    2.26
0.05    0.29    0.53    0.17    0.41    0.47    0.47    1.21    0.87    0.68
1.08    0.89    0.13    0.5 0.57    -0.5    -0.78   -0.34   -0.3    0.54
0.31    0.64    1.23    0.335   0.36    -0.65   0.39    0.39    0.31    0.73
0.54    0.3 0.26    0.47    0.13    0.24    -0.6    0.02    0.11    0.27
0.21    -0.3    -1  -0.44   -0.15   -0.51   0.3 0.14    -0.15   -0.27   -0.27

Y2W -0.01   -0.3    0.23    0.01    -0.15   0.45    -0.04   0.14    -1.16
-0.14   -0.56   -0.13   0.77    0.77    -0.57   0.48    0.22    -0.08
-1.81   -0.46   -0.17   0.2 -0.18   -0.45   -0.4    1.35    0.81    1.21
0.52    0.02    -0.06   0.37    0   -0.38   -0.02   0.48    0   0.58    0.81
0.54    0.18    -0.11   0.03    0.1 -0.38   0.17    0.37    -0.05   0.13
-0.01   -0.17   0.36    0.22    0   -1.4    -0.67   -0.45   -0.62   -0.58
-0.47   -0.86   -1.12   -0.43   0.1 0.06    -0.45   -0.14   0.68    -0.16
0.14    0.14    0.18    0.14    0.17    0.13    0.07    0.05    0.04    0.07
-0.01   0.03    0.05    0.02    0.12    0.34    -0.04   -0.75   1.68    0.23
0.49    0.38    -0.57   0.17    -0.04   0.19    0.22    0.29    -0.04   -0.3
0.18    0.04    0.3 -0.06   -0.07   -0.21   -0.01   0.51    -0.04   -0.04
-0.23   0.06    0.9 -0.14   0.19    2.5 2.84    3.27    2.13    2.5 2.66
4.16    3.52    -0.12   0.13    0.44    0.32    0.44    0.46    0.7 0.68
0.99    0.83    0.74    0.51    0.33    0.22    0.01    0.33    -0.19   0.4
0.41    0.07    0.18    -0.01   0.45    -0.37   -0.49   1.02    -0.59
-1.44   -1.53   -0.74   -1.48   0.12    0.05    0.02    -0.1    0.57
-0.36   0.1 -0.16   -0.23   -0.34   -0.61   -0.37   -0.14   -0.22   -0.27
-0.08   -0.08   -0.17   0.18    -0.74

Y3W 0.15    -0.07   -0.25   -0.3    -1.12   -0.67   -0.15   -0.43   0.63
0.92    0.25    0.33    0.81    -0.12   -0.12   0.67    0.86    0.86
1.54    -0.3    0   -0.29   -0.74   0.15    0.59    0.15    0.34    0.23
0.5 0.52    0.25    0.86    0.53    0.51    0.25        -1.29   -1.79
-0.45   -0.64   0.01    -0.58   -0.51   -0.74   -1.32               -0.47
-0.81   0.55    -0.09   0.46    -0.3    -0.2    -0.81   -1.56   -2.74   1.03
1   1.01    0.29    -0.64   -1.03   0.07    0.46    0.33    0.04    -0.6
-0.64   -0.51   -0.36   -0.1    0.13    -1.4    -1.17   -0.64   -0.16   -0.5
-0.47   0.75    0.62    0.7 1.06    0.93    0.56    -2.25   -0.94   -0.09
0.08    -0.15   -1.6    -1.43   -0.84   -0.25   -1.22   -0.92   -1.22
-0.97   -0.84   -0.89   0.24    0   -0.04   -0.64   -0.94   -1.56   -2.32
0.63    -0.17   -3.06   -2.4    -2  -1.4    -0.81   -1.6    -3.06   -1.79
0.17    0.28    -0.67   -2.82   -1.47   -1.82   -1.69   -1.38   -1.96
-1.88   -2.34   -3.06   -0.18   0.5 -0.03   -0.49   -0.61   -0.54   -0.37
0.1 -0.92   -1.79   -0.03   -0.54   0.94    -1  0.15    0.95    0.55
-0.36   0.4 -0.73   0.85    -0.26   0.55    0.14    -0.36   0.38    0.87
0.62    0.66    0.79    -0.67   0.48    0.62    0.48    0.72    0.73    0.29
-0.3    -0.81

Y4W 0.24    0.76    0.2 0.34    0.11    0.07    0.01    0.36    0.4 -0.25
-0.45   0.09    -0.97   0.19    0.28    -1.81   -0.64   -0.49   -1.27
-0.95   -0.1    0.12    -0.1    0   -0.08   0.77    1.02    0.92    0.56
0.1 0.7 0.57    0.16    1.29    0.82    0.55    0.5 1.83    1.79    0.01
0.24    -0.67   -0.85   -0.42   -0.37   0.2 0.07    -0.01   -0.17   -0.2
-0.43   -0.34   0.12    -0.21   -0.23   -0.22   -0.1    -0.07   -0.61
-0.14   -0.43   -0.97   0.27    0.7 0.54    0.11    -0.5    -0.39   0.01
0.61    0.88    1   0.35    0.67    0.6 0.78    0.46    0.09    -0.06
-0.35   0.08    -0.14   -0.32   -0.11   0   0.01    0.02    0.77    0.18
0.36    -1.15   -0.42   -0.19   0.06    -0.25   -0.81   -0.63   -1.43
-0.85   -0.88   -0.68   -0.59   -1.01   -0.68   -0.71   0.15    0.08    0.08
-0.03   -0.2    0.03    -0.18   -0.01   -0.08   -1.61   -0.67   -0.74
-0.54   -0.8    -1.02   -0.84   -1.91   -0.22   -0.02   0.05    -0.84
-0.65   -0.82   -0.4    -0.83   -0.9    -1.04   -1.23   -0.91   0.28    0.68
0.57    -0.02   0.4 -1.52   0.17    0.44    -1.18   0.04    0.17    0.16
0.04    -0.26   0.04    0.1 -0.11   -0.64   -0.09   -0.16   0.16    -0.05
0.39    0.39    -0.06   0.46    0.2 -0.45   -0.35   -1.3    -0.26   -0.29
0.02    0.16    0.18    -0.35   -0.45   -1.04   -0.69

Y5C 2.85    3.34                            -1  -0.47   -0.66   -0.03   1.41
0.8 0   0.41    -0.14   -0.86   -0.79   -1.69       0           0   1.52
1.29    0.84    0.58    1.02    1.35    0.45    1.02    1.47    0.82    0.46
0.25    0.77    0.93            -0.58   -0.67   -0.18   -0.56   -0.01   0.25
-0.71   -0.49           -0.43   0   -1.06   0.44    -0.29   0.26    -0.04
-0.14   -0.1    -0.12   -1.6    0.33    0.62    0.52    0.7 -0.22   0.44
-0.6    0.86    1.19    1.58    0.93    1   0.85    1.24    1.06    0.49
0.26    0.18    0.3 -0.09   -0.42   0.05    0.54    0.24    0.37    0.86
0.9 0.49    -1.47   -0.2    -0.43   0.2 0.1 -0.81   -0.74   -1.36   -0.97
-0.94   -0.86   -1.56   -1.89   -1.89   -1.06   0.12    0.06    0.04
-0.01   -0.12   0.01    -0.15   0.76    0.89    0.71    -1.12   0.03
-0.86   0.26    0   -0.25   -0.06   0.19    0.41    0.58    -0.46   0.01
-0.15   0.04    -1.01   -0.57   -0.71   -0.3    -1.01       1.83    0.59
1.04    -1.43   0.38    0.65    -6.64   -0.42   0.24    0.46    0.96    0.24
0.7 1.21    0.6 0.12    0.77    -0.03   0.53    0.31    0.46    0.51
-0.45   0.23    0.32    -0.34   -0.1    0.1 -0.45   0.74    -0.06   0.21
0.29    0.45    0.68    0.29    0.45

Y7C -0.22   -0.12   -0.29   -0.51   -0.81   -0.47   0.28    -0.1    0.15
0.38    0.18    -0.27   0.12    -0.15   0.43    0.25    0.19    0.33    0.67
0.86    -0.56   -0.29   -0.36   -0.42   0.08    0.04    -0.04   0.15    0.38
-0.07   -0.1    -0.2    -0.03   -0.29   0.06    0.65    0.58    0.86    2.05
0.3 0.33    -0.29   -0.23   -0.15   -0.32   0.08    0.34    0.15    0
-0.01   0.28    0.36    0.25    0.46    0.4     0.7 0.49    0.97    1.04
0.36    -0.47   -0.29   0.77    0.57    0.45    0.77    0.24    -0.23   0.12
0.49    0.62    0.49    0.84    0.89    1.08    0.87    -0.18   -0.43
-0.39   -0.18   -0.02   0.01    0.2 -0.2    -0.03   0.01    0.25    0.1
-0.07   -1.43   -0.2    -0.4    0.32    0.72    -0.42   -0.3    -0.38
-0.22   -0.81   -1.15   -1.6    -1.89   -2.06   -2.4    0.08    0.34    0.1
-0.15   -0.06   -0.17   -0.47   -0.4    0.15    -1.22   -1.43   -1.03
-1.03   -1.64   -1.84   -2.64   -2  0.05    0.4 0.88    -1.54   -1.21
-1.46   -1.92   -1.52   -1.92   -1.7    -1.94   -1.86   -0.1    -0.02
-0.22   -0.34   -0.48   0.28    0   0.14    0.4 -0.29   -0.27   -0.3
-0.67   -0.09   0.23    0.33    0.23    0.1 0.38    -0.51   0.23    -0.73
0.22    -0.47   0.24    0.68    0.53    0.23    -0.1    0.11    -0.18   0.16
0.68    0.55    0.28    -0.03   0.03    0.08    0.12

There is a missing value, I wanted to load it as matrix I used :

data = np.genfromtxt("This_data.txt", delimiter='\t', missing_values=np.nan)

When I print data I get :

Traceback (most recent call last):
  File "matrix.py", line 8, in <module>
    data = np.genfromtxt("This_data.txt", delimiter='\t', missing_values=np.nan ,usecols=np.arange(0,174))
  File "/home/anaconda2/lib/python2.7/numpy/lib/npyio.py", line 1769, in genfromtxt
    raise ValueError(errmsg)
ValueError: Some errors were detected !
    Line #25 (got 172 columns instead of 174)

I used to put:

data = np.genfromtxt("This_data.txt", delimiter='\t', missing_values=np.nan ,usecols=np.arange(0,174))

But I have same errors. Any suggestion?