问:
R fromJSON - $ operator is invalid for atomic vectors
Why do I get this error below:

```<code>Error: $ operator is invalid for atomic vectors
</code>```

My dummy code for a simple test:

```<code>l <- fromJSON('[{"winner":"68694999",  "votes":[
   {"ts":"Thu Mar 25 03:13:01 UTC 2010", "user":{"name":"Lamur","user_id":"68694999"}},
   {"ts":"Thu Mar 25 03:13:08 UTC 2010", "user":{"name":"Lamur","user_id":"68694999"}}],
  "lastVote":{"timestamp":1269486788526,"user":
   {"name":"Lamur","user_id":"68694999"}},"startPrice":0}]'
)

for(i in l) {
    print(i$votes)
}
</code>```

I just want to get the data off votes

Any ideas?

This is my more complex json that I need to pull the data from:

```<code>json <- '[{
    "data": {
        "dailysummary": [{
            "date": {
                "pretty": "12:20 AM BST on June 28, 2017",
                "year": "2017",
                "mon": "06",
                "mday": "28",
                "hour": "00",
                "min": "20",
                "tzname": "Europe/London"
            },
            "fog": "0",
            "rain": "1",
            "snow": "0",
            "snowfallm": "",
            "snowfalli": "",
            "monthtodatesnowfallm": "",
            "monthtodatesnowfalli": "",
            "since1julsnowfallm": "",
            "since1julsnowfalli": "",
            "snowdepthm": "",
            "snowdepthi": "",
            "hail": "0",
            "thunder": "0",
            "tornado": "0",
            "meantempm": "16",
            "meantempi": "60",
            "meandewptm": "13",
            "meandewpti": "56",
            "meanpressurem": "997.19",
            "meanpressurei": "29.45",
            "meanwindspdm": "9",
            "meanwindspdi": "6",
            "meanwdire": "NW",
            "meanwdird": "326",
            "meanvism": "8.9",
            "meanvisi": "5.5",
            "humidity": "86",
            "maxtempm": "17",
            "maxtempi": "62",
            "mintempm": "14",
            "mintempi": "57",
            "maxhumidity": "100",
            "minhumidity": "77",
            "maxdewptm": "15",
            "maxdewpti": "59",
            "mindewptm": "10",
            "mindewpti": "50",
            "maxpressurem": "1001",
            "maxpressurei": "29.56",
            "minpressurem": "996",
            "minpressurei": "29.42",
            "maxwspdm": "18",
            "maxwspdi": "12",
            "minwspdm": "6",
            "minwspdi": "4",
            "maxvism": "10.0",
            "maxvisi": "6.2",
            "minvism": "4.5",
            "minvisi": "2.8",
            "gdegreedays": "10",
            "heatingdegreedays": "6",
            "coolingdegreedays": "0",
            "precipm": "0.0",
            "precipi": "0.00",
            "precipsource": "3Or6HourObs",
            "heatingdegreedaysnormal": "",
            "monthtodateheatingdegreedays": "",
            "monthtodateheatingdegreedaysnormal": "",
            "since1sepheatingdegreedays": "",
            "since1sepheatingdegreedaysnormal": "",
            "since1julheatingdegreedays": "",
            "since1julheatingdegreedaysnormal": "",
            "coolingdegreedaysnormal": "",
            "monthtodatecoolingdegreedays": "",
            "monthtodatecoolingdegreedaysnormal": "",
            "since1sepcoolingdegreedays": "",
            "since1sepcoolingdegreedaysnormal": "",
            "since1jancoolingdegreedays": "",
            "since1jancoolingdegreedaysnormal": ""
        }],
        "airport": "LCY"
    },
    "date": "2017-06-28"
},{
    "data": {
        "dailysummary": [{
            "date": {
                "pretty": "12:20 AM BST on June 29, 2017",
                "year": "2017",
                "mon": "06",
                "mday": "29",
                "hour": "00",
                "min": "20",
                "tzname": "Europe/London"
            },
            "fog": "0",
            "rain": "0",
            "snow": "0",
            "snowfallm": "",
            "snowfalli": "",
            "monthtodatesnowfallm": "",
            "monthtodatesnowfalli": "",
            "since1julsnowfallm": "",
            "since1julsnowfalli": "",
            "snowdepthm": "",
            "snowdepthi": "",
            "hail": "0",
            "thunder": "0",
            "tornado": "0",
            "meantempm": "16",
            "meantempi": "60",
            "meandewptm": "11",
            "meandewpti": "51",
            "meanpressurem": "995.85",
            "meanpressurei": "29.41",
            "meanwindspdm": "14",
            "meanwindspdi": "9",
            "meanwdire": "WSW",
            "meanwdird": "256",
            "meanvism": "10.0",
            "meanvisi": "6.2",
            "humidity": "71",
            "maxtempm": "18",
            "maxtempi": "64",
            "mintempm": "13",
            "mintempi": "55",
            "maxhumidity": "82",
            "minhumidity": "63",
            "maxdewptm": "11",
            "maxdewpti": "52",
            "mindewptm": "10",
            "mindewpti": "50",
            "maxpressurem": "999",
            "maxpressurei": "29.50",
            "minpressurem": "994",
            "minpressurei": "29.36",
            "maxwspdm": "24",
            "maxwspdi": "15",
            "minwspdm": "9",
            "minwspdi": "6",
            "maxvism": "10.0",
            "maxvisi": "6.2",
            "minvism": "10.0",
            "minvisi": "6.2",
            "gdegreedays": "10",
            "heatingdegreedays": "6",
            "coolingdegreedays": "0",
            "precipm": "0.0",
            "precipi": "0.00",
            "precipsource": "3Or6HourObs",
            "heatingdegreedaysnormal": "",
            "monthtodateheatingdegreedays": "",
            "monthtodateheatingdegreedaysnormal": "",
            "since1sepheatingdegreedays": "",
            "since1sepheatingdegreedaysnormal": "",
            "since1julheatingdegreedays": "",
            "since1julheatingdegreedaysnormal": "",
            "coolingdegreedaysnormal": "",
            "monthtodatecoolingdegreedays": "",
            "monthtodatecoolingdegreedaysnormal": "",
            "since1sepcoolingdegreedays": "",
            "since1sepcoolingdegreedaysnormal": "",
            "since1jancoolingdegreedays": "",
            "since1jancoolingdegreedaysnormal": ""
        }],
        "airport": "LCY"
    },
    "date": "2017-06-29"
}]'

l <- fromJSON(json, ,flatten=TRUE)
</code>```

I need to make it into a new dataframe:

```<code>airport key_date        ws      wd      tempi humidity
LCY     2017-06-28      x       x       x       x
LCY     2017-06-29      x       x       x       x
</code>```

This is my old code but it does not work with this l dataframe from json anymore:

```<code># Initialize a data frame.
weatherDf <- data.frame()

# Set key conditions for checking later.
keyConditions <- c("meanwindspdi", "meanwdird", "meantempm", "humidity")

for(i in l) {
    # Get the airport code.
    airport <- i$airport

    # Get the date.
    date <- as.POSIXct(as.numeric(as.character(i$date))/1000, origin="1970-01-01", tz="UTC-1")

    # Get the data in dailysummary only.
    dailySummary <- i$dailysummary

    # print(all(keyConditions %in% names(dailySummary)))

    # Make sure key conditions exist in dailySummary,
    # then use rbind or will get 'numbers of columns of arguments do not match'
    if (all(keyConditions %in% names(dailySummary))) {
        weatherDf <- rbind(weatherDf, ldply(
            list(dailySummary),
            function(x) c(airport, format(as.Date(date), "%Y-%m-%d"), x[["meanwindspdi"]], x[["meanwdird"]], x[["meantempm"]], x[["humidity"]])
        ))
    }
}

# Rename column names.
colnames(weatherDf) <- c("airport", "key_date", "ws", "wd", "tempi", 'humidity')

# Convert certain columns weatherDf type to numberic.
columns <-c("ws", "wd", "tempi", "humidity")
weatherDf[, columns] <- lapply(columns, function(x) as.numeric(weatherDf[[x]]))
</code>```

EDIT:

```<code>weatherDf <- data.frame()
for(i in 1:nrow(l)) {
    row <- l[i,]
    # do stuff with row

    # Get the date.
    date <- row$date

    # Get the airport code.
    airport <- row$data.airport
    print(airport)

    # Get the data in dailysummary only.
    dailySummary <- row$data.dailysummary

    # print(all(keyConditions %in% names(dailySummary)))
    weatherDf <- rbind(weatherDf, ldply(
        list(dailySummary),
        function(x) c(airport, format(as.Date(date), "%Y-%m-%d"), x[["meanwindspdi"]], x[["meanwdird"]], x[["meantempm"]], x[["humidity"]])
    ))
}
</code>```

Edit 2:

```<code>dailySummary <- row$data.dailysummary
print(names(dailySummary))
</code>```

Result:

```<code>NULL
</code>```

What I try to get:

```<code>[1] "fog"                                "rain"                               "snow"
 [4] "snowfallm"                          "snowfalli"                          "monthtodatesnowfallm"
 [7] "monthtodatesnowfalli"               "since1julsnowfallm"                 "since1julsnowfalli"
[10] "snowdepthm"                         "snowdepthi"                         "hail"
[13] "thunder"                            "tornado"                            "meantempm"
[16] "meantempi"                          "meandewptm"                         "meandewpti"
[19] "meanpressurem"                      "meanpressurei"                      "meanwindspdm"
[22] "meanwindspdi"                       "meanwdire"                          "meanwdird"
[25] "meanvism"                           "meanvisi"                           "humidity"
[28] "maxtempm"                           "maxtempi"                           "mintempm"
[31] "mintempi"                           "maxhumidity"                        "minhumidity"
[34] "maxdewptm"                          "maxdewpti"                          "mindewptm"
[37] "mindewpti"                          "maxpressurem"                       "maxpressurei"
[40] "minpressurem"                       "minpressurei"                       "maxwspdm"
[43] "maxwspdi"                           "minwspdm"                           "minwspdi"
[46] "maxvism"                            "maxvisi"                            "minvism"
[49] "minvisi"                            "gdegreedays"                        "heatingdegreedays"
[52] "coolingdegreedays"                  "precipm"                            "precipi"
[55] "precipsource"                       "heatingdegreedaysnormal"            "monthtodateheatingdegreedays"
[58] "monthtodateheatingdegreedaysnormal" "since1sepheatingdegreedays"         "since1sepheatingdegreedaysnormal"
[61] "since1julheatingdegreedays"         "since1julheatingdegreedaysnormal"   "coolingdegreedaysnormal"
[64] "monthtodatecoolingdegreedays"       "monthtodatecoolingdegreedaysnormal" "since1sepcoolingdegreedays"
[67] "since1sepcoolingdegreedaysnormal"   "since1jancoolingdegreedays"         "since1jancoolingdegreedaysnormal"
[70] "date.pretty"                        "date.year"                          "date.mon"
[73] "date.mday"                          "date.hour"                          "date.min"
[76] "date.tzname"
 [1] "fog"                                "rain"                               "snow"
 [4] "snowfallm"                          "snowfalli"                          "monthtodatesnowfallm"
 [7] "monthtodatesnowfalli"               "since1julsnowfallm"                 "since1julsnowfalli"
[10] "snowdepthm"                         "snowdepthi"                         "hail"
[13] "thunder"                            "tornado"                            "meantempm"
[16] "meantempi"                          "meandewptm"                         "meandewpti"
[19] "meanpressurem"                      "meanpressurei"                      "meanwindspdm"
[22] "meanwindspdi"                       "meanwdire"                          "meanwdird"
[25] "meanvism"                           "meanvisi"                           "humidity"
[28] "maxtempm"                           "maxtempi"                           "mintempm"
[31] "mintempi"                           "maxhumidity"                        "minhumidity"
[34] "maxdewptm"                          "maxdewpti"                          "mindewptm"
[37] "mindewpti"                          "maxpressurem"                       "maxpressurei"
[40] "minpressurem"                       "minpressurei"                       "maxwspdm"
[43] "maxwspdi"                           "minwspdm"                           "minwspdi"
[46] "maxvism"                            "maxvisi"                            "minvism"
[49] "minvisi"                            "gdegreedays"                        "heatingdegreedays"
[52] "coolingdegreedays"                  "precipm"                            "precipi"
[55] "precipsource"                       "heatingdegreedaysnormal"            "monthtodateheatingdegreedays"
[58] "monthtodateheatingdegreedaysnormal" "since1sepheatingdegreedays"         "since1sepheatingdegreedaysnormal"
[61] "since1julheatingdegreedays"         "since1julheatingdegreedaysnormal"   "coolingdegreedaysnormal"
[64] "monthtodatecoolingdegreedays"       "monthtodatecoolingdegreedaysnormal" "since1sepcoolingdegreedays"
[67] "since1sepcoolingdegreedaysnormal"   "since1jancoolingdegreedays"         "since1jancoolingdegreedaysnormal"
[70] "date.pretty"                        "date.year"                          "date.mon"
[73] "date.mday"                          "date.hour"                          "date.min"
[76] "date.tzname"
</code>```

答:
Why not just access the data by l$votes?

The for loop you are using makes little sense. It is not defining i as l, but instead feeds the columns of the data frame l into the loop, i.e. "winner", "votes", "lastvote" and "startprice".

The error comes from the fact that you try to use $-indexing with the character vector l$winner, trying to print l$winner$votes.

EDIT: This is the code for the new data frame you gave

```<code>day_n <- length(l$data.dailysummary) # number of days
weather <- NULL; # daily summary data will be saved here

for (i in 1:day_n){
  weather <- rbind(weather, c(ws=as.numeric(l$data.dailysummary[[i]]$meanwindspdi),
                              wd=as.numeric(l$data.dailysummary[[i]]$meanwdird),
                              tempi=as.numeric(l$data.dailysummary[[i]]$meantempm),
                              humidity=as.numeric(l$data.dailysummary[[i]]$humidity))
        )
}

# make matrix of weather data for every day
# l$data.dailysummary is a list, containing the weather data in data frames for each day
# these data frames are accessed by l$data.dailysummary[[i]], to get the desired data

out <- data.frame(airport=l$data.airport, key_date=as.Date(l$date),
                  weather, stringsAsFactors = F)
</code>```

We get the data frame you asked for in the question:

```<code>> str(out)
'data.frame':   2 obs. of  6 variables:
 $ airport : chr  "LCY" "LCY"
 $ key_date: Date, format: "2017-06-28" "2017-06-29"
 $ ws      : num  6 9
 $ wd      : num  326 256
 $ tempi   : num  16 16
 $ humidity: num  86 71
> out
  airport   key_date ws  wd tempi humidity
1     LCY 2017-06-28  6 326    16       86
2     LCY 2017-06-29  9 256    16       71
</code>```

Body:
Why do I get this error below:

Error: $ operator is invalid for atomic vectors

My dummy code for a simple test:

l <- fromJSON('[{"winner":"68694999",  "votes":[
   {"ts":"Thu Mar 25 03:13:01 UTC 2010", "user":{"name":"Lamur","user_id":"68694999"}},
   {"ts":"Thu Mar 25 03:13:08 UTC 2010", "user":{"name":"Lamur","user_id":"68694999"}}],
  "lastVote":{"timestamp":1269486788526,"user":
   {"name":"Lamur","user_id":"68694999"}},"startPrice":0}]'
)

for(i in l) {
    print(i$votes)
}

I just want to get the data off votes

Any ideas?

This is my more complex json that I need to pull the data from:

json <- '[{
    "data": {
        "dailysummary": [{
            "date": {
                "pretty": "12:20 AM BST on June 28, 2017",
                "year": "2017",
                "mon": "06",
                "mday": "28",
                "hour": "00",
                "min": "20",
                "tzname": "Europe/London"
            },
            "fog": "0",
            "rain": "1",
            "snow": "0",
            "snowfallm": "",
            "snowfalli": "",
            "monthtodatesnowfallm": "",
            "monthtodatesnowfalli": "",
            "since1julsnowfallm": "",
            "since1julsnowfalli": "",
            "snowdepthm": "",
            "snowdepthi": "",
            "hail": "0",
            "thunder": "0",
            "tornado": "0",
            "meantempm": "16",
            "meantempi": "60",
            "meandewptm": "13",
            "meandewpti": "56",
            "meanpressurem": "997.19",
            "meanpressurei": "29.45",
            "meanwindspdm": "9",
            "meanwindspdi": "6",
            "meanwdire": "NW",
            "meanwdird": "326",
            "meanvism": "8.9",
            "meanvisi": "5.5",
            "humidity": "86",
            "maxtempm": "17",
            "maxtempi": "62",
            "mintempm": "14",
            "mintempi": "57",
            "maxhumidity": "100",
            "minhumidity": "77",
            "maxdewptm": "15",
            "maxdewpti": "59",
            "mindewptm": "10",
            "mindewpti": "50",
            "maxpressurem": "1001",
            "maxpressurei": "29.56",
            "minpressurem": "996",
            "minpressurei": "29.42",
            "maxwspdm": "18",
            "maxwspdi": "12",
            "minwspdm": "6",
            "minwspdi": "4",
            "maxvism": "10.0",
            "maxvisi": "6.2",
            "minvism": "4.5",
            "minvisi": "2.8",
            "gdegreedays": "10",
            "heatingdegreedays": "6",
            "coolingdegreedays": "0",
            "precipm": "0.0",
            "precipi": "0.00",
            "precipsource": "3Or6HourObs",
            "heatingdegreedaysnormal": "",
            "monthtodateheatingdegreedays": "",
            "monthtodateheatingdegreedaysnormal": "",
            "since1sepheatingdegreedays": "",
            "since1sepheatingdegreedaysnormal": "",
            "since1julheatingdegreedays": "",
            "since1julheatingdegreedaysnormal": "",
            "coolingdegreedaysnormal": "",
            "monthtodatecoolingdegreedays": "",
            "monthtodatecoolingdegreedaysnormal": "",
            "since1sepcoolingdegreedays": "",
            "since1sepcoolingdegreedaysnormal": "",
            "since1jancoolingdegreedays": "",
            "since1jancoolingdegreedaysnormal": ""
        }],
        "airport": "LCY"
    },
    "date": "2017-06-28"
},{
    "data": {
        "dailysummary": [{
            "date": {
                "pretty": "12:20 AM BST on June 29, 2017",
                "year": "2017",
                "mon": "06",
                "mday": "29",
                "hour": "00",
                "min": "20",
                "tzname": "Europe/London"
            },
            "fog": "0",
            "rain": "0",
            "snow": "0",
            "snowfallm": "",
            "snowfalli": "",
            "monthtodatesnowfallm": "",
            "monthtodatesnowfalli": "",
            "since1julsnowfallm": "",
            "since1julsnowfalli": "",
            "snowdepthm": "",
            "snowdepthi": "",
            "hail": "0",
            "thunder": "0",
            "tornado": "0",
            "meantempm": "16",
            "meantempi": "60",
            "meandewptm": "11",
            "meandewpti": "51",
            "meanpressurem": "995.85",
            "meanpressurei": "29.41",
            "meanwindspdm": "14",
            "meanwindspdi": "9",
            "meanwdire": "WSW",
            "meanwdird": "256",
            "meanvism": "10.0",
            "meanvisi": "6.2",
            "humidity": "71",
            "maxtempm": "18",
            "maxtempi": "64",
            "mintempm": "13",
            "mintempi": "55",
            "maxhumidity": "82",
            "minhumidity": "63",
            "maxdewptm": "11",
            "maxdewpti": "52",
            "mindewptm": "10",
            "mindewpti": "50",
            "maxpressurem": "999",
            "maxpressurei": "29.50",
            "minpressurem": "994",
            "minpressurei": "29.36",
            "maxwspdm": "24",
            "maxwspdi": "15",
            "minwspdm": "9",
            "minwspdi": "6",
            "maxvism": "10.0",
            "maxvisi": "6.2",
            "minvism": "10.0",
            "minvisi": "6.2",
            "gdegreedays": "10",
            "heatingdegreedays": "6",
            "coolingdegreedays": "0",
            "precipm": "0.0",
            "precipi": "0.00",
            "precipsource": "3Or6HourObs",
            "heatingdegreedaysnormal": "",
            "monthtodateheatingdegreedays": "",
            "monthtodateheatingdegreedaysnormal": "",
            "since1sepheatingdegreedays": "",
            "since1sepheatingdegreedaysnormal": "",
            "since1julheatingdegreedays": "",
            "since1julheatingdegreedaysnormal": "",
            "coolingdegreedaysnormal": "",
            "monthtodatecoolingdegreedays": "",
            "monthtodatecoolingdegreedaysnormal": "",
            "since1sepcoolingdegreedays": "",
            "since1sepcoolingdegreedaysnormal": "",
            "since1jancoolingdegreedays": "",
            "since1jancoolingdegreedaysnormal": ""
        }],
        "airport": "LCY"
    },
    "date": "2017-06-29"
}]'

l <- fromJSON(json, ,flatten=TRUE)

I need to make it into a new dataframe:

airport key_date        ws      wd      tempi humidity
LCY     2017-06-28      x       x       x       x
LCY     2017-06-29      x       x       x       x

This is my old code but it does not work with this l dataframe from json anymore:

# Initialize a data frame.
weatherDf <- data.frame()

# Set key conditions for checking later.
keyConditions <- c("meanwindspdi", "meanwdird", "meantempm", "humidity")

for(i in l) {
    # Get the airport code.
    airport <- i$airport

    # Get the date.
    date <- as.POSIXct(as.numeric(as.character(i$date))/1000, origin="1970-01-01", tz="UTC-1")

    # Get the data in dailysummary only.
    dailySummary <- i$dailysummary

    # print(all(keyConditions %in% names(dailySummary)))

    # Make sure key conditions exist in dailySummary,
    # then use rbind or will get 'numbers of columns of arguments do not match'
    if (all(keyConditions %in% names(dailySummary))) {
        weatherDf <- rbind(weatherDf, ldply(
            list(dailySummary),
            function(x) c(airport, format(as.Date(date), "%Y-%m-%d"), x[["meanwindspdi"]], x[["meanwdird"]], x[["meantempm"]], x[["humidity"]])
        ))
    }
}

# Rename column names.
colnames(weatherDf) <- c("airport", "key_date", "ws", "wd", "tempi", 'humidity')

# Convert certain columns weatherDf type to numberic.
columns <-c("ws", "wd", "tempi", "humidity")
weatherDf[, columns] <- lapply(columns, function(x) as.numeric(weatherDf[[x]]))

EDIT:

weatherDf <- data.frame()
for(i in 1:nrow(l)) {
    row <- l[i,]
    # do stuff with row

    # Get the date.
    date <- row$date

    # Get the airport code.
    airport <- row$data.airport
    print(airport)

    # Get the data in dailysummary only.
    dailySummary <- row$data.dailysummary

    # print(all(keyConditions %in% names(dailySummary)))
    weatherDf <- rbind(weatherDf, ldply(
        list(dailySummary),
        function(x) c(airport, format(as.Date(date), "%Y-%m-%d"), x[["meanwindspdi"]], x[["meanwdird"]], x[["meantempm"]], x[["humidity"]])
    ))
}

Edit 2:

dailySummary <- row$data.dailysummary
print(names(dailySummary))

Result:

NULL

What I try to get:

[1] "fog"                                "rain"                               "snow"
 [4] "snowfallm"                          "snowfalli"                          "monthtodatesnowfallm"
 [7] "monthtodatesnowfalli"               "since1julsnowfallm"                 "since1julsnowfalli"
[10] "snowdepthm"                         "snowdepthi"                         "hail"
[13] "thunder"                            "tornado"                            "meantempm"
[16] "meantempi"                          "meandewptm"                         "meandewpti"
[19] "meanpressurem"                      "meanpressurei"                      "meanwindspdm"
[22] "meanwindspdi"                       "meanwdire"                          "meanwdird"
[25] "meanvism"                           "meanvisi"                           "humidity"
[28] "maxtempm"                           "maxtempi"                           "mintempm"
[31] "mintempi"                           "maxhumidity"                        "minhumidity"
[34] "maxdewptm"                          "maxdewpti"                          "mindewptm"
[37] "mindewpti"                          "maxpressurem"                       "maxpressurei"
[40] "minpressurem"                       "minpressurei"                       "maxwspdm"
[43] "maxwspdi"                           "minwspdm"                           "minwspdi"
[46] "maxvism"                            "maxvisi"                            "minvism"
[49] "minvisi"                            "gdegreedays"                        "heatingdegreedays"
[52] "coolingdegreedays"                  "precipm"                            "precipi"
[55] "precipsource"                       "heatingdegreedaysnormal"            "monthtodateheatingdegreedays"
[58] "monthtodateheatingdegreedaysnormal" "since1sepheatingdegreedays"         "since1sepheatingdegreedaysnormal"
[61] "since1julheatingdegreedays"         "since1julheatingdegreedaysnormal"   "coolingdegreedaysnormal"
[64] "monthtodatecoolingdegreedays"       "monthtodatecoolingdegreedaysnormal" "since1sepcoolingdegreedays"
[67] "since1sepcoolingdegreedaysnormal"   "since1jancoolingdegreedays"         "since1jancoolingdegreedaysnormal"
[70] "date.pretty"                        "date.year"                          "date.mon"
[73] "date.mday"                          "date.hour"                          "date.min"
[76] "date.tzname"
 [1] "fog"                                "rain"                               "snow"
 [4] "snowfallm"                          "snowfalli"                          "monthtodatesnowfallm"
 [7] "monthtodatesnowfalli"               "since1julsnowfallm"                 "since1julsnowfalli"
[10] "snowdepthm"                         "snowdepthi"                         "hail"
[13] "thunder"                            "tornado"                            "meantempm"
[16] "meantempi"                          "meandewptm"                         "meandewpti"
[19] "meanpressurem"                      "meanpressurei"                      "meanwindspdm"
[22] "meanwindspdi"                       "meanwdire"                          "meanwdird"
[25] "meanvism"                           "meanvisi"                           "humidity"
[28] "maxtempm"                           "maxtempi"                           "mintempm"
[31] "mintempi"                           "maxhumidity"                        "minhumidity"
[34] "maxdewptm"                          "maxdewpti"                          "mindewptm"
[37] "mindewpti"                          "maxpressurem"                       "maxpressurei"
[40] "minpressurem"                       "minpressurei"                       "maxwspdm"
[43] "maxwspdi"                           "minwspdm"                           "minwspdi"
[46] "maxvism"                            "maxvisi"                            "minvism"
[49] "minvisi"                            "gdegreedays"                        "heatingdegreedays"
[52] "coolingdegreedays"                  "precipm"                            "precipi"
[55] "precipsource"                       "heatingdegreedaysnormal"            "monthtodateheatingdegreedays"
[58] "monthtodateheatingdegreedaysnormal" "since1sepheatingdegreedays"         "since1sepheatingdegreedaysnormal"
[61] "since1julheatingdegreedays"         "since1julheatingdegreedaysnormal"   "coolingdegreedaysnormal"
[64] "monthtodatecoolingdegreedays"       "monthtodatecoolingdegreedaysnormal" "since1sepcoolingdegreedays"
[67] "since1sepcoolingdegreedaysnormal"   "since1jancoolingdegreedays"         "since1jancoolingdegreedaysnormal"
[70] "date.pretty"                        "date.year"                          "date.mon"
[73] "date.mday"                          "date.hour"                          "date.min"
[76] "date.tzname"

Body:
Why not just access the data by l$votes?

The for loop you are using makes little sense. It is not defining i as l, but instead feeds the columns of the data frame l into the loop, i.e. "winner", "votes", "lastvote" and "startprice".

The error comes from the fact that you try to use $-indexing with the character vector l$winner, trying to print l$winner$votes.

EDIT: This is the code for the new data frame you gave

day_n <- length(l$data.dailysummary) # number of days
weather <- NULL; # daily summary data will be saved here

for (i in 1:day_n){
  weather <- rbind(weather, c(ws=as.numeric(l$data.dailysummary[[i]]$meanwindspdi),
                              wd=as.numeric(l$data.dailysummary[[i]]$meanwdird),
                              tempi=as.numeric(l$data.dailysummary[[i]]$meantempm),
                              humidity=as.numeric(l$data.dailysummary[[i]]$humidity))
        )
}

# make matrix of weather data for every day
# l$data.dailysummary is a list, containing the weather data in data frames for each day
# these data frames are accessed by l$data.dailysummary[[i]], to get the desired data

out <- data.frame(airport=l$data.airport, key_date=as.Date(l$date),
                  weather, stringsAsFactors = F)

We get the data frame you asked for in the question:

> str(out)
'data.frame':   2 obs. of  6 variables:
 $ airport : chr  "LCY" "LCY"
 $ key_date: Date, format: "2017-06-28" "2017-06-29"
 $ ws      : num  6 9
 $ wd      : num  326 256
 $ tempi   : num  16 16
 $ humidity: num  86 71
> out
  airport   key_date ws  wd tempi humidity
1     LCY 2017-06-28  6 326    16       86
2     LCY 2017-06-29  9 256    16       71


来源: stackexchange

问:
Selenium webdriver Unsupported major.minor version 51.0 - Java version issue
I am setting selenium web driver. I set it up as Maven project.

My basic "Hello world" equivalent tests that are not using webdriver is class is working fine. How ever when I tried using the code breaks and I get the following error.

```<code>WebDriver driver = new FirefoxDriver();
</code>```

java.lang.UnsupportedClassVersionError:
  org/openqa/selenium/firefox/FirefoxDriver : Unsupported major.minor
  version 51.0

From what I understand it is a java version issue. So, I went ahead and installed Java 1.8.

When I run java -version I get this:

java version "1.8.0_77" Java(TM) SE Runtime Environment (build
  1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

But still my code breaks.

My bash profile still reads java 1.6 export PATH="/Users/pathToPerForce/p4/JavaLib/main/build/apache-ant-1.6.3/bin:/Applications/p4:${PATH}

When I set up this as Maven project I could right click on project and "build as" maven build. Now that is failing too.

I am fairly new to java and selenium and not able to comprehend this is good depth. Any help in fixing this is much appreciated.

答:
I too was facing the same issue but with chrome driver.
error: ...Unsupported major.minor version 51.0
All I did is, I installed 1.8 jre, Configures it in the BUILD PATH and the issue got resolved.

RCA:
The dependency jars I was using is configurable with latest version of jre.

ContentLicense: CC BY-SA 3.0

Body:
I am setting selenium web driver. I set it up as Maven project.

My basic "Hello world" equivalent tests that are not using webdriver is class is working fine. How ever when I tried using the code breaks and I get the following error.

WebDriver driver = new FirefoxDriver();

java.lang.UnsupportedClassVersionError:
  org/openqa/selenium/firefox/FirefoxDriver : Unsupported major.minor
  version 51.0

From what I understand it is a java version issue. So, I went ahead and installed Java 1.8.

When I run java -version I get this:

java version "1.8.0_77" Java(TM) SE Runtime Environment (build
  1.8.0_77-b03) Java HotSpot(TM) 64-Bit Server VM (build 25.77-b03, mixed mode)

But still my code breaks.

My bash profile still reads java 1.6 export PATH="/Users/pathToPerForce/p4/JavaLib/main/build/apache-ant-1.6.3/bin:/Applications/p4:${PATH}

When I set up this as Maven project I could right click on project and "build as" maven build. Now that is failing too.

I am fairly new to java and selenium and not able to comprehend this is good depth. Any help in fixing this is much appreciated.


问:
Ajax & Session Variables? Worksafe Filter (selective image hiding)
I'm building a photography portfolio. Some of my images have nudity, so I want to hide those by default until the user clicks a "Toggle Worksafe Mode" button.

I can do it with a standard form post (and sessions), but that causes "confirm form resubmission" errors when the user backs or reloads. I'm trying to figure out an AJAX post instead to avoid that.

UPDATE: This is the working code. Please note that this does NOT work with the "slim" jQuery distro; that's one of the main reasons I was having trouble.

Image Index Page:

```<code><?php
    session_start();
    if (!isset($_SESSION['Worksafe_Mode'] {
        $_SESSION['Worksafe_Mode'] = 1;
    }
?>
<!-- other page content -->
<script src="scripts/jquery-3.2.1.min.js"></script>
<!-- other page content -->
<button type="button" id="Worksafe_Button" name="Worksafe_Button">
    Toggle Worksafe Mode
</button>
<script>
    $('#Worksafe_Button').click(function() {
        $.post("worksafe_mode_toggle.php")
            .done(function(data) {
                window.location.href = window.location.href;
        });
    });
</script>
<!-- other page content -->
<?php
$Connection = Connect();
$query = mysqli_query($Connection, 'SELECT uri, name, nsfw FROM images ORDER BY uri');

while($row = mysqli_fetch_assoc($image)) {
    if ($_SESSION['Worksafe_Mode'] == 1 && $row['nsfw'] == 1) {
        echo 'If you are over 18, toggle Worksafe Mode to view this image';
    }
    else {
        echo '<img alt="'.$row['title'].'" src="../'.$row['uri'].'/s.jpg" srcset="../'.$row['uri'].'/m.jpg 2x">';
    }
}
?>
</code>```

worksafe_mode_script:

```<code>session_start();
if (isset($_SESSION['Worksafe_Mode'])) {
    if ($_SESSION['Worksafe_Mode'] == 1) {
        $_SESSION['Worksafe_Mode'] = 0;
    }
    else {
        $_SESSION['Worksafe_Mode'] = 1;
    }
}
</code>```

答:
Confirm form resubmission happens because you do not perform a redirect after a successful form submission.

Take a look at this wiki page to see how to do it right. https://en.wikipedia.org/wiki/Post/Redirect/Get

Body:
I'm building a photography portfolio. Some of my images have nudity, so I want to hide those by default until the user clicks a "Toggle Worksafe Mode" button.

I can do it with a standard form post (and sessions), but that causes "confirm form resubmission" errors when the user backs or reloads. I'm trying to figure out an AJAX post instead to avoid that.

UPDATE: This is the working code. Please note that this does NOT work with the "slim" jQuery distro; that's one of the main reasons I was having trouble.

Image Index Page:

<?php
    session_start();
    if (!isset($_SESSION['Worksafe_Mode'] {
        $_SESSION['Worksafe_Mode'] = 1;
    }
?>

<button type="button" id="Worksafe_Button" name="Worksafe_Button">
    Toggle Worksafe Mode
</button>

<?php
$Connection = Connect();
$query = mysqli_query($Connection, 'SELECT uri, name, nsfw FROM images ORDER BY uri');

while($row = mysqli_fetch_assoc($image)) {
    if ($_SESSION['Worksafe_Mode'] == 1 && $row['nsfw'] == 1) {
        echo 'If you are over 18, toggle Worksafe Mode to view this image';
    }
    else {
        echo '';
    }
}
?>

worksafe_mode_script:

session_start();
if (isset($_SESSION['Worksafe_Mode'])) {
    if ($_SESSION['Worksafe_Mode'] == 1) {
        $_SESSION['Worksafe_Mode'] = 0;
    }
    else {
        $_SESSION['Worksafe_Mode'] = 1;
    }
}


问:
How to create a form that generates a pdf and saves to a mongoDB without using PHP
I'm just going to be collecting demographic information from end users who will be registering for my Aunt's Driver's Ed class. I will be changing the starter code below to reflect that. It would be helpful if the information they enter was put into a pdf form in which the students can print off, sign (or e-sign) and bring to class. It would also be helpful if we had this information stored somewhere so that we the students come to class we could print it off for them if they forgot. In this case, I can see that I need a database. But what do I need to connect it to the form and create a pdf? I would like to use MEAN stack if possible. PHP is not an option.

This is the starter code that I will be using:

.register-form {
 line-height: 1.4;
}
.form-group {
 background: #F6DDCE;
 margin-bottom: 1em;
 padding: 10px;
}
.form-group ul {
 list-style: none;
 margin: 0 0 2em;
 padding: 0;
}
.form-group li {
 margin-bottom: 0.5em;
}
.form-group h3 {
 margin-bottom: 1em;
}
.form-fields input[type="text"],
.form-fields input[type="tel"],
.form-fields input[type="url"],
.form-fields input[type="email"],
.form-fields input[type="number"],
.form-fields select {
  box-sizing: border-box;
  padding: 0.6em 0.8em;
  color: #999;
  background: #f7f7f7;
  border: 1px solid #e1e1e1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9em;
  text-decoration: none;
  line-height: normal;
  max-height: 3em;
}
.form-fields input[type="text"]:focus,
.form-fields input[type="tel"]:focus,
.form-fields input[type="url"]:focus,
.form-fields input[type="email"]:focus,
.form-fields input[type="number"]:focus,
.form-food textarea:focus,
.form-fields select:focus {
  color: #333;
  border: 1px solid #C17CCF;
  outline: none;
  background: #f2f2f2;
}
.form-food textarea {
    display: block;
    box-sizing: border-box;
    font: 0.9em Lato, Helvetica, sans-serif;
    width: 90%;
    height: 6em;
    overflow: auto;
    padding: 0.6em 0.8em;
    color: #999;
    background: #f7f7f7;
    border: 1px solid #e1e1e1;
    line-height: normal;
}
.register-btn {
 border-radius: 0px 2px 2px 0px;
 box-sizing: content-box;
 background: #8B798C;
 font-weight: 300;
 text-transform: uppercase;
 color: white;
 padding: 0.35em 0.75em;
 border: none;
 font-size: 1.1em;
 text-decoration: none;
 cursor: pointer;
}
.register-btn:hover, .register-btn:focus {
 background: #C17CCF;
}
/*flex it*/
.register-form {
 display: flex;
 flex-wrap: wrap;
}
.form-group {
 flex: 1 0 300px;
}
.form-submit {
 flex: 0 0 100%;
}
.form-fields li {
 display: flex;
 flex-wrap: wrap;
}
.form-fields input[type="text"],
.form-fields input[type="tel"],
.form-fields input[type="url"],
.form-fields input[type="email"],
.form-fields input[type="number"],
.form-fields select {
 flex: 1 0 230px;
}
.form-fields label {
 flex: 1 0 90px;
 max-width: 200px;
}
.form-skills, .form-workshop {
 display: flex;
 flex-wrap: wrap;
 justify-content: space-between;
}
.form-skills li {
 width: 145px;
}
.form-workshop li {
 ```
<pre class="snippet-code-html lang-html prettyprint-override"><code><form class="register-form">
<section class="form-group">
<h3>Personal Info</h3>
<ul class="form-fields">
<li><label for="name">Name:</label> <input type="text" name="name" id="name" placeholder="your full name" class="text-input"></li>
<li><label for="street-address">Street address:</label> <input type="text" name="street-address" id="street-address" placeholder="your street address" class="text-input"></li>
<li><label for="city">City:</label> <input type="text" name="city" id="city" placeholder="city" class="text-input"></li>
<li><label for="state">State:</label> <select class="select-menu" id="state" name="state">
 <option value="AL">Alabama</option>
 <option value="AK">Alaska</option>
 <option value="AZ">Arizona</option>
 <option value="AR">Arkansas</option>
 <option value="CA">California</option>
 <option value="CO">Colorado</option>
 <option value="CT">Connecticut</option>
 <option value="DE">Delaware</option>
 <option value="DC">District Of Columbia</option>
 <option value="FL">Florida</option>
 <option value="GA">Georgia</option>
 <option value="HI">Hawaii</option>
 <option value="ID">Idaho</option>
 <option value="IL">Illinois</option>
 <option value="IN">Indiana</option>
 <option value="IA">Iowa</option>
 <option value="KS">Kansas</option>
 <option value="KY">Kentucky</option>
 <option value="LA">Louisiana</option>
 <option value="ME">Maine</option>
 <option value="MD">Maryland</option>
 <option value="MA">Massachusetts</option>
 <option value="MI">Michigan</option>
 <option value="MN">Minnesota</option>
 <option value="MS">Mississippi</option>
 <option value="MO">Missouri</option>
 <option value="MT">Montana</option>
 <option value="NE">Nebraska</option>
 <option value="NV">Nevada</option>
 <option value="NH">New Hampshire</option>
 <option value="NJ">New Jersey</option>
 <option value="NM">New Mexico</option>
 <option value="NY">New York</option>
 <option value="NC">North Carolina</option>
 <option value="ND">North Dakota</option>
 <option value="OH">Ohio</option>
 <option value="OK">Oklahoma</option>
 <option value="OR">Oregon</option>
 <option value="PA">Pennsylvania</option>
 <option value="RI">Rhode Island</option>
 <option value="SC">South Carolina</option>
 <option value="SD">South Dakota</option>
 <option value="TN">Tennessee</option>
 <option value="TX">Texas</option>
 <option value="UT">Utah</option>
 <option value="VT">Vermont</option>
 <option value="VA">Virginia</option>
 <option value="WA">Washington</option>
 <option value="WV">West Virginia</option>
 <option value="WI">Wisconsin</option>
 <option value="WY">Wyoming</option>
</select> </li>
<li><label for="street-address">Zip code:</label> <input type="text" name="zip-code" id="zip-code" placeholder="zip code" class="text-input"></li>
<li><label for="email">Email:</label> <input type="email" name="email" id="email" placeholder="confirmation email" class="text-input"></li>
</ul>
<h4>Registration Info</h4>
<p>This info will be on your badge and help us match you with information and events throughout the conference.
<ul class="form-fields">
<li><label for="description">Primary role:</label> <select class="select-menu" id="description" name="description">
 <option value="designer">Designer</option>
 <option value="developer">Developer</option>
 <option value="other">Other</option>
 </select></li>
<li><label for="job-title">Job title:</label> <input type="text" name="job-title" id="job-title" placeholder="job title" class="text-input"></li>
<li><label for="company">Company:</label> <input type="text" name="company" id="company" placeholder="company" class="text-input"></li>
<li><label for="phone">Phone:</label> <input type="tel" name="phone" id="phone" placeholder="your phone number" class="text-input"></li>
</ul>
</section>
<section class="form-group">
<h3>Sessions</h3>
<h4>Skills</h4>
<p>Listing skills will help us match up our break out sessions and lunch!</p>
<ul class="form-skills">
<li><input type="checkbox" id="css" value="css"> <label for="css">CSS</label></li>
<li><input type="checkbox" id="html" value="html"> <label for="html">HTML</label></li>
<li><input type="checkbox" id="js" value="js"> <label for="js">JavaScript</label></li>
<li><input type="checkbox" id="content" value="content"> <label for="content">Content Strategy</label></li>
<li><input type="checkbox" id="ux" value="ux"> <label for="ux">UX</label></li>
<li><input type="checkbox" id="rails" value="rails"> <label for="rails">Rails</label></li>
<li><input type="checkbox" id="node" value="node"> <label for="node">Node</label></li>
<li><input type="checkbox" id="sass" value="sass"> <label for="sass">SASS</label></li>
<li><input type="checkbox" id="mobile" value="mobile"> <label for="mobile">Mobile</label></li>
</ul>
<h4>Workshops</h4>
<p>Workshops are half-day, hands-on classes. Each are an additional $50.</p>
<ul class="form-workshop">
<li><input type="checkbox" id="forms-ws" value="forms"> <label for="forms-ws">Creating Responsive Forms with Flexbox</label></li>
<li><input type="checkbox" id="jekyll-ws" value="jekyll"> <label for="jekyll-ws">Blogging with Jekyll</label></li>
<li><input type="checkbox" id="usability-ws" value="usability"> <label for="usability-ws">Usability Testing with Cats</label></li>
<li><input type="checkbox" id="node-ws" value="node"> <label for="node-ws">Building Stuff with Node</label></li>
</ul>
<h4>Lunch</h4>
<p>Lunch is provided each day. We have vegetarian options as well as gluten-free choices available. Please let us know about any food allergies or dietary restrictions.</p>
<ul class="form-food">
<li><input type="radio" id="meat" value="meat" name="food"> <label for="meat">Chicken, Beef, or Fish</label></li>
<li><input type="radio" id="vegetarian" value="vegetarian" name="food"> <label for="vegetarian">Vegetarian</label></li>
<li><input type="radio" id="gluten" value="gluten" name="food"> <label for="gluten">Gluten Free</label></li>
<li><label for="food-options">Please list any dietary restrictions:</label><textarea id="food-options" name="food-options" class="text-area">food allergies or other restrictions</textarea> </li>
</ul>
</section>
<section class="form-submit">
<h4>All finished?</h4>
<p>We're looking forward to seeing you!</p>
<button type="submit" class="register-btn">Register</button>
</section>
</form></code>```

答:
Assuming you've setup a Node.js server using the Express framework, configured MongoDB with mongoose, and setup your models, the flow would be something like:

User fills out forms and submits it to the Express server.

The form submits to some route handler (controller) function.

Inside the controller you'd generate the PDF and save the data to the database.

So the code would be something like:

```<code>const PDFDocument  = require('pdfkit')

exports.createPdf = async (req, res) => {
  // Save form data to the database
  const myModel = new myModel(req.body)
  await myModel.save()

  const document = new PDFDocument()
  // PDF generation logic...
}
</code>```

Body:
I'm just going to be collecting demographic information from end users who will be registering for my Aunt's Driver's Ed class. I will be changing the starter code below to reflect that. It would be helpful if the information they enter was put into a pdf form in which the students can print off, sign (or e-sign) and bring to class. It would also be helpful if we had this information stored somewhere so that we the students come to class we could print it off for them if they forgot. In this case, I can see that I need a database. But what do I need to connect it to the form and create a pdf? I would like to use MEAN stack if possible. PHP is not an option.

This is the starter code that I will be using:

.register-form {
 line-height: 1.4;
}
.form-group {
 background: #F6DDCE;
 margin-bottom: 1em;
 padding: 10px;
}
.form-group ul {
 list-style: none;
 margin: 0 0 2em;
 padding: 0;
}
.form-group li {
 margin-bottom: 0.5em;
}
.form-group h3 {
 margin-bottom: 1em;
}
.form-fields input[type="text"],
.form-fields input[type="tel"],
.form-fields input[type="url"],
.form-fields input[type="email"],
.form-fields input[type="number"],
.form-fields select {
  box-sizing: border-box;
  padding: 0.6em 0.8em;
  color: #999;
  background: #f7f7f7;
  border: 1px solid #e1e1e1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.9em;
  text-decoration: none;
  line-height: normal;
  max-height: 3em;
}
.form-fields input[type="text"]:focus,
.form-fields input[type="tel"]:focus,
.form-fields input[type="url"]:focus,
.form-fields input[type="email"]:focus,
.form-fields input[type="number"]:focus,
.form-food textarea:focus,
.form-fields select:focus {
  color: #333;
  border: 1px solid #C17CCF;
  outline: none;
  background: #f2f2f2;
}
.form-food textarea {
    display: block;
    box-sizing: border-box;
    font: 0.9em Lato, Helvetica, sans-serif;
    width: 90%;
    height: 6em;
    overflow: auto;
    padding: 0.6em 0.8em;
    color: #999;
    background: #f7f7f7;
    border: 1px solid #e1e1e1;
    line-height: normal;
}
.register-btn {
 border-radius: 0px 2px 2px 0px;
 box-sizing: content-box;
 background: #8B798C;
 font-weight: 300;
 text-transform: uppercase;
 color: white;
 padding: 0.35em 0.75em;
 border: none;
 font-size: 1.1em;
 text-decoration: none;
 cursor: pointer;
}
.register-btn:hover, .register-btn:focus {
 background: #C17CCF;
}
/*flex it*/
.register-form {
 display: flex;
 flex-wrap: wrap;
}
.form-group {
 flex: 1 0 300px;
}
.form-submit {
 flex: 0 0 100%;
}
.form-fields li {
 display: flex;
 flex-wrap: wrap;
}
.form-fields input[type="text"],
.form-fields input[type="tel"],
.form-fields input[type="url"],
.form-fields input[type="email"],
.form-fields input[type="number"],
.form-fields select {
 flex: 1 0 230px;
}
.form-fields label {
 flex: 1 0 90px;
 max-width: 200px;
}
.form-skills, .form-workshop {
 display: flex;
 flex-wrap: wrap;
 justify-content: space-between;
}
.form-skills li {
 width: 145px;
}
.form-workshop li {

<form class="register-form">

Personal Info

Name: <input type="text" name="name" id="name" placeholder="your full name" class="text-input">

Street address: <input type="text" name="street-address" id="street-address" placeholder="your street address" class="text-input">

City: <input type="text" name="city" id="city" placeholder="city" class="text-input">

State: <select class="select-menu" id="state" name="state">
 <option value="AL">Alabama</option>
 <option value="AK">Alaska</option>
 <option value="AZ">Arizona</option>
 <option value="AR">Arkansas</option>
 <option value="CA">California</option>
 <option value="CO">Colorado</option>
 <option value="CT">Connecticut</option>
 <option value="DE">Delaware</option>
 <option value="DC">District Of Columbia</option>
 <option value="FL">Florida</option>
 <option value="GA">Georgia</option>
 <option value="HI">Hawaii</option>
 <option value="ID">Idaho</option>
 <option value="IL">Illinois</option>
 <option value="IN">Indiana</option>
 <option value="IA">Iowa</option>
 <option value="KS">Kansas</option>
 <option value="KY">Kentucky</option>
 <option value="LA">Louisiana</option>
 <option value="ME">Maine</option>
 <option value="MD">Maryland</option>
 <option value="MA">Massachusetts</option>
 <option value="MI">Michigan</option>
 <option value="MN">Minnesota</option>
 <option value="MS">Mississippi</option>
 <option value="MO">Missouri</option>
 <option value="MT">Montana</option>
 <option value="NE">Nebraska</option>
 <option value="NV">Nevada</option>
 <option value="NH">New Hampshire</option>
 <option value="NJ">New Jersey</option>
 <option value="NM">New Mexico</option>
 <option value="NY">New York</option>
 <option value="NC">North Carolina</option>
 <option value="ND">North Dakota</option>
 <option value="OH">Ohio</option>
 <option value="OK">Oklahoma</option>
 <option value="OR">Oregon</option>
 <option value="PA">Pennsylvania</option>
 <option value="RI">Rhode Island</option>
 <option value="SC">South Carolina</option>
 <option value="SD">South Dakota</option>
 <option value="TN">Tennessee</option>
 <option value="TX">Texas</option>
 <option value="UT">Utah</option>
 <option value="VT">Vermont</option>
 <option value="VA">Virginia</option>
 <option value="WA">Washington</option>
 <option value="WV">West Virginia</option>
 <option value="WI">Wisconsin</option>
 <option value="WY">Wyoming</option>
</select>

Zip code: <input type="text" name="zip-code" id="zip-code" placeholder="zip code" class="text-input">

Email: <input type="email" name="email" id="email" placeholder="confirmation email" class="text-input">

Registration Info

This info will be on your badge and help us match you with information and events throughout the conference.

Primary role: <select class="select-menu" id="description" name="description">
 <option value="designer">Designer</option>
 <option value="developer">Developer</option>
 <option value="other">Other</option>
 </select>

Job title: <input type="text" name="job-title" id="job-title" placeholder="job title" class="text-input">

Company: <input type="text" name="company" id="company" placeholder="company" class="text-input">

Phone: <input type="tel" name="phone" id="phone" placeholder="your phone number" class="text-input">

Sessions

Skills

Listing skills will help us match up our break out sessions and lunch!

<input type="checkbox" id="css" value="css"> CSS

<input type="checkbox" id="html" value="html"> HTML

<input type="checkbox" id="js" value="js"> JavaScript

<input type="checkbox" id="content" value="content"> Content Strategy

<input type="checkbox" id="ux" value="ux"> UX

<input type="checkbox" id="rails" value="rails"> Rails

<input type="checkbox" id="node" value="node"> Node

<input type="checkbox" id="sass" value="sass"> SASS

<input type="checkbox" id="mobile" value="mobile"> Mobile

Workshops

Workshops are half-day, hands-on classes. Each are an additional $50.

<input type="checkbox" id="forms-ws" value="forms"> Creating Responsive Forms with Flexbox

<input type="checkbox" id="jekyll-ws" value="jekyll"> Blogging with Jekyll

<input type="checkbox" id="usability-ws" value="usability"> Usability Testing with Cats

<input type="checkbox" id="node-ws" value="node"> Building Stuff with Node

Lunch

Lunch is provided each day. We have vegetarian options as well as gluten-free choices available. Please let us know about any food allergies or dietary restrictions.

<input type="radio" id="meat" value="meat" name="food"> Chicken, Beef, or Fish

<input type="radio" id="vegetarian" value="vegetarian" name="food"> Vegetarian

<input type="radio" id="gluten" value="gluten" name="food"> Gluten Free

Please list any dietary restrictions:<textarea id="food-options" name="food-options" class="text-area">food allergies or other restrictions</textarea>

All finished?

We're looking forward to seeing you!

<button type="submit" class="register-btn">Register</button>

</form>

Body:
Assuming you've setup a Node.js server using the Express framework, configured MongoDB with mongoose, and setup your models, the flow would be something like:

User fills out forms and submits it to the Express server.

The form submits to some route handler (controller) function.

Inside the controller you'd generate the PDF and save the data to the database.

So the code would be something like:

const PDFDocument  = require('pdfkit')

exports.createPdf = async (req, res) => {
  // Save form data to the database
  const myModel = new myModel(req.body)
  await myModel.save()

  const document = new PDFDocument()
  // PDF generation logic...
}


问:
How to keep track of virtual memory used when running Python code?
I have a Python package I am benchmarking for virtual memory used.

At the moment, this isn't very precise. I submit the script e.g.

```<code>python script1.py
</code>```

and look at the time and resources used in order to execute.

Is there some package/method to find out where my RAM bottlenecks are? I'm thinking of a tool like

```<code>ram_used python script1.py
</code>```

that would keep track of how much RAM is used.

Does such a thing exist?

答:
There's also memory_info psutil. https://pythonhosted.org/psutil/

Place at the beginning of the script:

```<code>import psutil
p = psutil.Process()
</code>```

and given that the code is running correctly, place this on the last line:

```<code>print(p.memory_info())
</code>```

Body:
I have a Python package I am benchmarking for virtual memory used.

At the moment, this isn't very precise. I submit the script e.g.

python script1.py

and look at the time and resources used in order to execute.

Is there some package/method to find out where my RAM bottlenecks are? I'm thinking of a tool like

ram_used python script1.py

that would keep track of how much RAM is used.

Does such a thing exist?

Body:
There's also memory_info psutil. https://pythonhosted.org/psutil/

Place at the beginning of the script:

import psutil
p = psutil.Process()

and given that the code is running correctly, place this on the last line:

print(p.memory_info())


问:
Convert string to array in Java?
I have a string which has the values like this (format is the same):

```<code>name:xxx
occupation:yyy
phone:zzz
</code>```

I want to convert this into an array and get the occupation value using indexes.

Any suggestions?

答:
Basically you would use Java's split() function:

```<code>String str = "Name:Glenn Occupation:Code_Monkey";

String[] temp = str.split(" ");
String[] name = temp[0].split(":");
String[] occupation = temp[1].split(":");
</code>```

The resultant values would be:

```<code>name[0] - Name
name[1] - Glenn

occupation[0] - Occupation
occupation[1] - Code_Monkey
</code>```

ContentLicense: CC BY-SA 2.5

Title: Convert string to array in Java?

Body:
I have a string which has the values like this (format is the same):

name:xxx
occupation:yyy
phone:zzz

I want to convert this into an array and get the occupation value using indexes.

Any suggestions?

Body:
Basically you would use Java's split() function:

String str = "Name:Glenn Occupation:Code_Monkey";

String[] temp = str.split(" ");
String[] name = temp[0].split(":");
String[] occupation = temp[1].split(":");

The resultant values would be:

name[0] - Name
name[1] - Glenn

occupation[0] - Occupation
occupation[1] - Code_Monkey


问:
MongoDB returns nothing?

I am trying to run Perl with MongoDB but I get nothing

use MongoDB;
use Data::Dumper;

my $client = MongoDB::connect("mongodb://admin:admin123@localhost");
my $db = $client->get_database( 'admin' );
my $x = $db->get_collection( 'inventory' );
my $y = $x->find({"item" => "journal"});
print Dumper($y->all);
```

<p>In the <code>mongo</code> client, I get this</p>

<pre class="lang-none prettyprint-override"><code>mongo -u admin -p admin123 --authenticationDatabase admin
MongoDB shell version: 3.2.15
connecting to: test
Server has startup warnings:
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten]
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten]
> db.inventory.find({})
{ "_id" : ObjectId("5960dec814a535e879221157"), "item" : "journal", "qty" : 26, "size" : { "h" : 17, "w" : 21, "uom" : "cm" }, "status" : "B" }
{ "_id" : ObjectId("5960dec814a535e879221158"), "item" : "notebook", "qty" : 50, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "A" }
{ "_id" : ObjectId("5960dec814a535e879221159"), "item" : "paper", "qty" : 100, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "D" }
{ "_id" : ObjectId("5960dec814a535e87922115a"), "item" : "planner", "qty" : 75, "size" : { "h" : 22.85, "w" : 30, "uom" : "cm" }, "status" : "D" }
{ "_id" : ObjectId("5960dec814a535e87922115b"), "item" : "postcard", "qty" : 45, "size" : { "h" : 10, "w" : 15.25, "uom" : "cm" }, "status" : "A" }
{ "_id" : ObjectId("5960e7bb14a535e87922115c"), "foo" : { "a" : [ 1, 2, 3 ] } }
{ "_id" : ObjectId("5960e87614a535e87922115d"), "foo" : { "a" : [ 2, 3, 4 ] } }
{ "_id" : ObjectId("5960e87c14a535e87922115e"), "foo" : { "a" : [ 5, 3, 4 ] } }
>
</code>```

答:
You are looking in the wrong database. Actually in the shell you are connecting to the "test" database. See:

```<code>connecting to: test
</code>```

and you never ask to switch the namespace, so that is where the data is.

Change to

```<code>$client->get_database( 'test' );
</code>```

and as noted, it's a lot better if you actually write MongoDB->connect instead, though instance method to class method distinctions at this point have little consequence. You simply chose the wrong database. The "admin" namespace gets automatically switched by the driver for authentication. All you need to do is use the real space where data is.

Title: MongoDB returns nothing?

Body:
I am trying to run Perl with MongoDB but I get nothing

use MongoDB;
use Data::Dumper;

my $client = MongoDB::connect("mongodb://admin:admin123@localhost");
my $db = $client->get_database( 'admin' );
my $x = $db->get_collection( 'inventory' );
my $y = $x->find({"item" => "journal"});
print Dumper($y->all);

In the mongo client, I get this

mongo -u admin -p admin123 --authenticationDatabase admin
MongoDB shell version: 3.2.15
connecting to: test
Server has startup warnings:
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten]
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten] **        We suggest setting it to 'never'
2017-07-08T08:28:16.694-0500 I CONTROL  [initandlisten]
> db.inventory.find({})
{ "_id" : ObjectId("5960dec814a535e879221157"), "item" : "journal", "qty" : 26, "size" : { "h" : 17, "w" : 21, "uom" : "cm" }, "status" : "B" }
{ "_id" : ObjectId("5960dec814a535e879221158"), "item" : "notebook", "qty" : 50, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "A" }
{ "_id" : ObjectId("5960dec814a535e879221159"), "item" : "paper", "qty" : 100, "size" : { "h" : 8.5, "w" : 11, "uom" : "in" }, "status" : "D" }
{ "_id" : ObjectId("5960dec814a535e87922115a"), "item" : "planner", "qty" : 75, "size" : { "h" : 22.85, "w" : 30, "uom" : "cm" }, "status" : "D" }
{ "_id" : ObjectId("5960dec814a535e87922115b"), "item" : "postcard", "qty" : 45, "size" : { "h" : 10, "w" : 15.25, "uom" : "cm" }, "status" : "A" }
{ "_id" : ObjectId("5960e7bb14a535e87922115c"), "foo" : { "a" : [ 1, 2, 3 ] } }
{ "_id" : ObjectId("5960e87614a535e87922115d"), "foo" : { "a" : [ 2, 3, 4 ] } }
{ "_id" : ObjectId("5960e87c14a535e87922115e"), "foo" : { "a" : [ 5, 3, 4 ] } }
>

Body:
You are looking in the wrong database. Actually in the shell you are connecting to the "test" database. See:

connecting to: test

and you never ask to switch the namespace, so that is where the data is.

Change to

$client->get_database( 'test' );

and as noted, it's a lot better if you actually write MongoDB->connect instead, though instance method to class method distinctions at this point have little consequence. You simply chose the wrong database. The "admin" namespace gets automatically switched by the driver for authentication. All you need to do is use the real space where data is.


问:
Quill editor integration with dojo
I am trying to use Quill editor with dojo framework, but its not working. The editor is not shown over there. Any help in this regard will be highly appreciated.

```<code><html>
<head>
    <link rel="stylesheet" href="http://cdn.quilljs.com/0.16.0/quill.snow.css" />
    <script type="text/javascript"
        src="https://ajax.googleapis.com/ajax/libs/dojo/1.7.0/dojo/dojo.js"
        data-dojo-config="async: true, packages: [
            { name: 'quill', location: 'http://cdn.quilljs.com/0.16.0/', main: 'quill' }
         ]" />
</head>
<body>
    <div id="editor">
        Editor in chief!
    </div>
    <script type="text/javascript">
        define.amd.quill = true;
        require(["quill"], function(quill){
            var editor = new Quill("#editor");
        });
    </script>
</body>
</code>```

答:
I'm not familiar with Dojo 1.7, so opted for 1.10.4.

I also had XSS errors (something about an iframe) with Quill version 0.16, so went with the latest 1.2.6 version.

The below seems to work fine.

require(["dojo/ready", "Quill"], function(ready, Quill){
  ready(function(){
    var editor = new Quill("#editor", { theme: 'snow' })
  })
})```
<pre class="snippet-code-html lang-html prettyprint-override"><code><script>
  var dojoConfig = {
    async: true,
    packages: [{ name: 'Quill', location: '//cdn.quilljs.com/1.2.6', main: 'quill' }]
  }
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//cdn.quilljs.com/1.2.6/quill.snow.css" rel="stylesheet" />
<div id="editor">Editor in chief!</div></code>```

Title: Quill editor integration with dojo

Body:
I am trying to use Quill editor with dojo framework, but its not working. The editor is not shown over there. Any help in this regard will be highly appreciated.

    <link rel="stylesheet" href="http://cdn.quilljs.com/0.16.0/quill.snow.css" />

Body:
I'm not familiar with Dojo 1.7, so opted for 1.10.4.

I also had XSS errors (something about an iframe) with Quill version 0.16, so went with the latest 1.2.6 version.

The below seems to work fine.

require(["dojo/ready", "Quill"], function(ready, Quill){
  ready(function(){
    var editor = new Quill("#editor", { theme: 'snow' })
  })
})

<script>
  var dojoConfig = {
    async: true,
    packages: [{ name: 'Quill', location: '//cdn.quilljs.com/1.2.6', main: 'quill' }]
  }
</script>
<script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"></script>
<link href="//cdn.quilljs.com/1.2.6/quill.snow.css" rel="stylesheet" />
<div id="editor">Editor in chief!</div>


问:
Indexoutofboundsexception after scrolling up while swipe refresh is refreshing

Hello! I've got a recyclerview and a swipe to refresh layout . When i swipe down and it starts refreshing when i scroll up while it's still refreshing the app crashes and the log says the thing in the picture. After refrwshing is completed everything works fine until you scroll up while refreshing again . It says indexoutof bounds and position 2. Thanks in advance! :)

Edit 1:

```<code><?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh"
    android:layout_width="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryNewsBG"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</android.support.v4.widget.SwipeRefreshLayout>
</code>```

答: Fixed it! this question describes almost the exact issue I had. Looking for indexoutofbounds didn't work so I managed to locate the problem : It was happening when it was told to clear the list , but I never notified the adapter that the data is refreshed!</p>

Body:
Hello! I've got a recyclerview and a swipe to refresh layout . When i swipe down and it starts refreshing when i scroll up while it's still refreshing the app crashes and the log says the thing in the picture. After refrwshing is completed everything works fine until you scroll up while refreshing again . It says indexoutof bounds and position 2. Thanks in advance! :)

Edit 1:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.SwipeRefreshLayout
    android:id="@+id/swipe_refresh"
    android:layout_width="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    android:layout_height="wrap_content"
    android:background="@color/colorPrimaryNewsBG"
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

<android.support.v7.widget.RecyclerView
    android:id="@+id/recyclerview"
    android:clipChildren="false"
    android:clipToPadding="false"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"/>

</android.support.v4.widget.SwipeRefreshLayout>


问:
Finding Maximum Value of Array
I'm trying to loop through my array to find the maximum value and print the value. However, nothing is being printed to the console. Can you please take a look at my code below to see what I've done incorrectly.

```<code>for (c = 0; c < n; c++) //loops through array until each index has had a value input by the user
  array[c] = in.nextInt();

maxInt = array[0];
minInt = array[0];

for (c = 0; c < n; c++) {
    if (array[c] > maxInt) {
        maxInt = array[c];
    }
    else {
        break;
    }
}
System.out.println("Max int is: " + maxInt);
}
</code>```

EDIT:

Full class:

```<code>import java.util.Scanner;

public class MaxMinOfArray {
public static void main(String[] args) {
int c, n, search, array[];
int maxInt, minInt;

Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements");
n = in.nextInt(); //asks user to specify array size
array = new int[n]; //creates array of specified array size

System.out.println("Enter " + n + " integers");

for (c = 0; c < n; c++) //loops through array until each index has had a value input by the user
array[c] = in.nextInt();

maxInt = array[0];
minInt = array[0];

for (c = 1; c < n; c++) {
if (array[c] > maxInt) {
    maxInt = array[c];
}
}
System.out.println("Max int is: " + maxInt);
}
}
</code>```

答:
Your second loop compares for each element in array if it is greater than maxInt, but maxInt has just been set to the  first element of array. This fails the condition on the first iteration of the loop, executing the break in the else block, which ends the loop.

Taking out the else block fixes this:

```<code>for (c = 0; c < n; ++c)
{
    if (array[c] > maxInt)
        maxInt = array[c];
}
</code>```

Or alternatively:

```<code>for (c = 0; c < n; ++c)
    maxInt = Math.max(maxInt, array[c]);
</code>```

As for the console message not appearing, make sure the code is properly executed by setting a breakpoint and stepping through the code (depends on the IDE you're using).

Title: Finding Maximum Value of Array

Body:
I'm trying to loop through my array to find the maximum value and print the value. However, nothing is being printed to the console. Can you please take a look at my code below to see what I've done incorrectly.

for (c = 0; c < n; c++) //loops through array until each index has had a value input by the user
  array[c] = in.nextInt();

maxInt = array[0];
minInt = array[0];

for (c = 0; c < n; c++) {
    if (array[c] > maxInt) {
        maxInt = array[c];
    }
    else {
        break;
    }
}
System.out.println("Max int is: " + maxInt);
}

EDIT:

Full class:

import java.util.Scanner;

public class MaxMinOfArray {
public static void main(String[] args) {
int c, n, search, array[];
int maxInt, minInt;

Scanner in = new Scanner(System.in);
System.out.println("Enter number of elements");
n = in.nextInt(); //asks user to specify array size
array = new int[n]; //creates array of specified array size

System.out.println("Enter " + n + " integers");

for (c = 0; c < n; c++) //loops through array until each index has had a value input by the user
array[c] = in.nextInt();

maxInt = array[0];
minInt = array[0];

for (c = 1; c < n; c++) {
if (array[c] > maxInt) {
    maxInt = array[c];
}
}
System.out.println("Max int is: " + maxInt);
}
}

Body:
Your second loop compares for each element in array if it is greater than maxInt, but maxInt has just been set to the  first element of array. This fails the condition on the first iteration of the loop, executing the break in the else block, which ends the loop.

Taking out the else block fixes this:

for (c = 0; c < n; ++c)
{
    if (array[c] > maxInt)
        maxInt = array[c];
}

Or alternatively:

for (c = 0; c < n; ++c)
    maxInt = Math.max(maxInt, array[c]);

As for the console message not appearing, make sure the code is properly executed by setting a breakpoint and stepping through the code (depends on the IDE you're using).


问:
how to delete temp files (clean up) generated by a java program?
I am working on a portable java app that generates some files on the fly on the user's PC (windows xp). Now, what I want is to delete those temp files after the java program's exit. Obviously, java's file deletion mechanism can not be trusted. Even if I mark a file as to be deleted on exit (file.deleteOnExit() ) , most of the times it is not deleted.  I use a wrapper (java2exe) to run it as an executable. Any suggestions or solutions are welcome ?

Thanks,
Deep

答:
I suspect that the reason that deleteOnExit is failing is because your application still has the files open when your application exits.  This will cause the delete to fail on Windows due to lingering file locks.

The solution is to close all streams for your temporary files before you exit.


问:
Laravel api route with postman not working
I started a new project on Laravel 5.3 with xampp on Windows, I instaled the cors package(https://github.com/barryvdh/laravel-cors) to do request in other domains in the future too.

But on localhost using postman The routes are not working I have this on /routes/api.php:

```<code>Route::get('/hello', 'AppController@hello');
</code>```

On controller:

```<code>public function hello()
    {
        return "hello!";
    }
</code>```

on postman:

http://localhost/myproject/api/hello

Responds "object not found error 404", I tried with http://localhost:80/myproject/api/hello and same response.

When I put this http://localhost/myproject/public/api/hello I get the response: "NotFoundHttpException in RouteCollection.php line 161:"

So I don't get it, is this a laravel 5.3 bug or something? This is my php artisan route list:

```<code>+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
| Domain | Method   | URI                    | Name     | Action                                                                 | Middleware   |
+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD | /                      |          | Closure                                                                | web          |
|        | GET|HEAD | api/hello              |          | App\Http\Controllers\AppController@hello                               | api          |
|        | GET|HEAD | api/user               |          | Closure                                                                | api,auth:api |
|        | GET|HEAD | home                   |          | App\Http\Controllers\HomeController@index                              | web,auth     |
|        | GET|HEAD | login                  | login    | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest    |
|        | POST     | login                  |          | App\Http\Controllers\Auth\LoginController@login                        | web,guest    |
|        | POST     | logout                 | logout   | App\Http\Controllers\Auth\LoginController@logout                       | web          |
|        | POST     | password/email         |          | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    |
|        | GET|HEAD | password/reset         |          | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    |
|        | POST     | password/reset         |          | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest    |
|        | GET|HEAD | password/reset/{token} |          | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
|        | GET|HEAD | register               | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
|        | POST     | register               |          | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |
</code>```

答:
I think that you're getting this error due to a missing url segment: /public
The URL should be: /public/api/hello</p>

Body:
I started a new project on Laravel 5.3 with xampp on Windows, I instaled the cors package(https://github.com/barryvdh/laravel-cors) to do request in other domains in the future too.

But on localhost using postman The routes are not working I have this on /routes/api.php:

Route::get('/hello', 'AppController@hello');

On controller:

public function hello()
    {
        return "hello!";
    }

on postman:

http://localhost/myproject/api/hello

Responds "object not found error 404", I tried with http://localhost:80/myproject/api/hello and same response.

When I put this http://localhost/myproject/public/api/hello I get the response: "NotFoundHttpException in RouteCollection.php line 161:"

So I don't get it, is this a laravel 5.3 bug or something? This is my php artisan route list:

+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
| Domain | Method   | URI                    | Name     | Action                                                                 | Middleware   |
+--------+----------+------------------------+----------+------------------------------------------------------------------------+--------------+
|        | GET|HEAD | /                      |          | Closure                                                                | web          |
|        | GET|HEAD | api/hello              |          | App\Http\Controllers\AppController@hello                               | api          |
|        | GET|HEAD | api/user               |          | Closure                                                                | api,auth:api |
|        | GET|HEAD | home                   |          | App\Http\Controllers\HomeController@index                              | web,auth     |
|        | GET|HEAD | login                  | login    | App\Http\Controllers\Auth\LoginController@showLoginForm                | web,guest    |
|        | POST     | login                  |          | App\Http\Controllers\Auth\LoginController@login                        | web,guest    |
|        | POST     | logout                 | logout   | App\Http\Controllers\Auth\LoginController@logout                       | web          |
|        | POST     | password/email         |          | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail  | web,guest    |
|        | GET|HEAD | password/reset         |          | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest    |
|        | POST     | password/reset         |          | App\Http\Controllers\Auth\ResetPasswordController@reset                | web,guest    |
|        | GET|HEAD | password/reset/{token} |          | App\Http\Controllers\Auth\ResetPasswordController@showResetForm        | web,guest    |
|        | GET|HEAD | register               | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm      | web,guest    |
|        | POST     | register               |          | App\Http\Controllers\Auth\RegisterController@register                  | web,guest    |


问:
How to identify a character within a word and substitute that letter into another string - Python
For my hangman project, in the situation that the person does guess a letter correctly, I want to be able to substitute that letter in for a '_' space.

```<code>word = input('Please enter a word for your opponent:')

letter = input('Enter a letter to try and guess the word:')

print('_ '*len(word))

if 'a' in word and letter:
    print('_ '*len(word) with 'a' in word)
</code>```

For example if the word entered was 'matt,' the output would be '_a__'

答:
You can use regex substitution with re.sub:

```<code>In [514]: word = 'matt'

In [515]: letter = 'a'

In [518]: re.sub(r'[^%s]' %letter, '_', word)
Out[518]: '_a__'
</code>```

As a tip on how to continue with this approach with subsequent letters, each time the user inputs a letter, add it to letter, like this:

```<code>In [521]: new_letter = 't' # replace this with user input

In [522]: letter += new_letter
</code>```

And, regex will handle the new letter when displaying, appropriately:

```<code>In [523]: re.sub(r'[^%s]' %letter, '_', word)
Out[523]: '_att'
</code>```

Body:
For my hangman project, in the situation that the person does guess a letter correctly, I want to be able to substitute that letter in for a '_' space.

word = input('Please enter a word for your opponent:')

letter = input('Enter a letter to try and guess the word:')

print('_ '*len(word))

if 'a' in word and letter:
    print('_ '*len(word) with 'a' in word)

For example if the word entered was 'matt,' the output would be '_a__'

Body:
You can use regex substitution with re.sub:

In [514]: word = 'matt'

In [515]: letter = 'a'

In [518]: re.sub(r'[^%s]' %letter, '_', word)
Out[518]: '_a__'

As a tip on how to continue with this approach with subsequent letters, each time the user inputs a letter, add it to letter, like this:

In [521]: new_letter = 't' # replace this with user input

In [522]: letter += new_letter

And, regex will handle the new letter when displaying, appropriately:

In [523]: re.sub(r'[^%s]' %letter, '_', word)
Out[523]: '_att'


问:
Log all of the commands run by Linux build process
For what I am seeking to do with the Linux kernel, it is necessary that I log all of the commands run by the build process. The Linux build system, as it is written, does not display the commands that it runs, like invocations ld and the compiler. Instead, it will print lines like this:

```<code>LD usr/built-in.o
</code>```

I want to be able to see those printed to the terminal, but I'd also like to log the actual commands to a file so I can see what is run to, say, link the initial RAM filesystem into vmlinux or the order in which object files are linked. How can I do this?

The purpose of this is to figure the particular object files I need and what commands to run in order to make different builds with different initial RAM filesystem contents without having to start from scratch. So, if the CPIO was produced by running cpio $dir > initramfs.cpio and then the final kernel image was produced by running ld code.o initramfs.cpio, then I will have the object files that I don't need to rebuild and the way to combine them with the initramfs to make the final kernel image.

答:
Pass V=1 to make.

make V=1 ...

Body:
For what I am seeking to do with the Linux kernel, it is necessary that I log all of the commands run by the build process. The Linux build system, as it is written, does not display the commands that it runs, like invocations ld and the compiler. Instead, it will print lines like this:

LD usr/built-in.o

I want to be able to see those printed to the terminal, but I'd also like to log the actual commands to a file so I can see what is run to, say, link the initial RAM filesystem into vmlinux or the order in which object files are linked. How can I do this?

The purpose of this is to figure the particular object files I need and what commands to run in order to make different builds with different initial RAM filesystem contents without having to start from scratch. So, if the CPIO was produced by running cpio $dir > initramfs.cpio and then the final kernel image was produced by running ld code.o initramfs.cpio, then I will have the object files that I don't need to rebuild and the way to combine them with the initramfs to make the final kernel image.

Body:
Pass V=1 to make.

make V=1 ...


问:
I want to center my
 with css codes
I am learning HTML and CSS and i have problems with positioning.
This is my HTML code:

```<code><!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="https://bootswatch.com/simplex/bootstrap.min.css">
    <meta charset="utf-8">
    <title>My Website</title>
  </head>
  <body>
  <div id="main">
    <header>
      <h1 id="baslik">Dünyanın en iyi web sitesi!</h1>
    </header>
    <nav>
      <p>Bu sitede bulacaklarınız:</p>
      <ul>
        <li>Videolar</li>
        <li>Blog yazıları</li>
        <li>Eğlenceli şeyler...</li>
      </ul>
    </nav>
    <footer>
      <p>Bu sitenin copyright hakları tarafımıza aittir.</p>
    </footer>
  </div>
  </body>
</html>
</code>```

And this is my CSS code:

```<code>#main{
  text-align: center;
}
</code>```

I cant align my text, how do i do this with HTML and CSS?

答:
To horizontally center a block element (like div), use margin: auto;

Setting the width of the element will prevent it from stretching out to the edges of its container.

The element will then take up the specified width, and the remaining space will be split equally between the two margins.

```<code>.center {
    margin: auto;
    width: 50%;
    border: 3px solid green;
    padding: 10px;
}
</code>```

Title: I want to center my <div> with css codes

Body:
I am learning HTML and CSS and i have problems with positioning.
This is my HTML code:

<!DOCTYPE html>

    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="https://bootswatch.com/simplex/bootstrap.min.css">
    <meta charset="utf-8">
    <title>My Website</title>

Dünyanın en iyi web sitesi!

Bu sitede bulacaklarınız:

Videolar

Blog yazıları

Eğlenceli şeyler...

Bu sitenin copyright hakları tarafımıza aittir.

And this is my CSS code:

#main{
  text-align: center;
}

I cant align my text, how do i do this with HTML and CSS?

Body:
To horizontally center a block element (like div), use margin: auto;

Setting the width of the element will prevent it from stretching out to the edges of its container.

The element will then take up the specified width, and the remaining space will be split equally between the two margins.

.center {
    margin: auto;
    width: 50%;
    border: 3px solid green;
    padding: 10px;
}


问:
iPhone: how twitter API help to make app

Possible Duplicate:

  Is there an iPhone SDK API for twitter?

hi i am start to develop twitter app on iPhone, how twitter API help to make app and how i have to use twitter API for developing application on iPhone r any platform

答: Look at ShareKit it covers everything, including Twitter.</p>


问:
Ignore pycharm breakpoint for first N hits
I'm trying to ignore a specific breakpoint in pycharm for the first N times it hits.  Since I'm looking to set it to something like 10k, manually doing this is not an option.  I found the expanded options for breakpoints, including the condition field, but I'm not sure how I can craft a condition which takes into account how many times the breakpoint has been hit.  Thanks.

答:
You can just create a variable in Python specifically for the breakpoint counting purpose, which you increment every time you you go past the break point line. Then just use that variable in your break point condition (i.e. breakpoint_count == 10000).

Update

If you can't add new code into the real python code you can use the breakpoint condition:

eval("exec('try:\\n    x += 1\\nexcept NameError:\\n    x = 1') or x == 10000")

What this does is execute a try statement which increments a variable or creates it if it doesn't exist. Then evaluates that along with a statement checking if the variable has been incremented enough times yet with that being your ending condition. Note, the exec is required to run the try, but the eval is needed to "return" the condition to PyCharm. This is absurdly hacky, but it works for your case!


答:
.center {
  text-align:center !important
}```
<pre class="snippet-code-html lang-html prettyprint-override"><code><!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="https://bootswatch.com/simplex/bootstrap.min.css">
    <meta charset="utf-8">
    <title>My Website</title>
  </head>
  <body>
  <div id="main" class="center">
    <header>
      <h1 id="baslik">Dünyanın en iyi web sitesi!</h1>
    </header>
    <nav>
      <p>Bu sitede bulacaklarınız:</p>
      <ul>
        <li>Videolar</li>
        <li>Blog yazıları</li>
        <li>Eğlenceli şeyler...</li>
      </ul>
    </nav>
    <footer>
      <p>Bu sitenin copyright hakları tarafımıza aittir.</p>
    </footer>
  </div>
  </body></code>```

best to use a class when applying across many divs.

Body:
.center {
  text-align:center !important
}

<!DOCTYPE html>
<html>
  <head>
    <link rel="stylesheet" href="/css/style.css">
    <link rel="stylesheet" href="https://bootswatch.com/simplex/bootstrap.min.css">
    <meta charset="utf-8">
    <title>My Website</title>
  </head>
  <body>
  <div id="main" class="center">
    <header>
      <h1 id="baslik">Dünyanın en iyi web sitesi!</h1>
    </header>
    <nav>
      <p>Bu sitede bulacaklarınız:</p>
      <ul>
        <li>Videolar</li>
        <li>Blog yazıları</li>
        <li>Eğlenceli şeyler...</li>
      </ul>
    </nav>
    <footer>
      <p>Bu sitenin copyright hakları tarafımıza aittir.</p>
    </footer>
  </div>
  </body>

best to use a class when applying across many divs.


问:
Python: how to do this complex multiline regex involving escapes?
I have a file that looks like this:

```<code>...

- family:
  - home: house
    location: 53rd street|Austin|Texas|U.S
    type: old
original entry: '544'
  issues:
  - plumbing: fixed
    ref:
    - id: 28
      cost: 23 USD

- family:
  - home: house
    location: 53rd street|Austin|Texas|U.S
    type: old
original entry: '545'
  issues:
  - plumbing: fixed
    ref:
    - id: 1081
      cost: 33 USD

 ...
</code>```

This file has hundreds of similar entries on other families.

I want to make it look like this:

```<code>- family:
  - home: house
    location: 53rd street|Austin|Texas|U.S
    type: old
original entry: '544'
  issues:
  - plumbing: fixed
    ref:
    - id: 28
      cost: 23 USD
    - id: 1081
      cost: 33 USD
</code>```

I have tried making a multiline regex where I just find the text in the middle and replace it with nothing. Here is the pattern I attempted:

```<code>pattern = "r'\s- family:\n\s+- home: house\n\s+tag: 53rd street|Austin|Texas|U.S\n\s+type: old\n\original entry: \'554\'\n\s+issues:\n\s+- plumbing: fixed\n\s+ref:'"
</code>```

This did not seem to work. I tried one of those online regex tools that suggested:

```<code>pattern = "r'\s- family:\n\s+- home: house\n\s+tag: 53rd street\|Austin\|Texas\|U.S\n\s+type: old\n\original entry: '554'\n\s+issues:\n\s+- plumbing: fixed\n\s+ref:'"
</code>```

This also did not appear to work. I have used my multiline regex function on simpler cases without a problem, so I know the regex code itself works. It is just that it seems a bit tricky getting a pattern that works.

I figure there must be some stuff that is not getting escaped correctly, or escaped too much. Also, this strategy does not seem to get both of the original entry numbers after each other.

Is there a way this can be done? I guess one can just use the entire two blocks as the pattern, and the result as the replacement text, but that seems even more bulkier and difficult...

答:
The parser for doing this using pyparser is uncomplicated. Here, it's declared as the name p. Each line is defined to be everything up to an end-line followed by an end-line, and the entire file consists of OneOrMore of these. Since pyparsing ignores white space by default the empty lines disappear.

```<code>>>> import pyparsing as pp
>>> theFile = open('temp.txt').read()
>>> p = pp.OneOrMore(pp.Combine(pp.restOfLine+pp.Suppress('\n')))
>>> for item in p.parseString(theFile):
...     item
...
'- family:'
'- home: house'
'location: 53rd street|Austin|Texas|U.S'
'type: old'
"original entry: '544'"
'issues:'
'- plumbing: fixed'
'ref:'
'- id: 28'
'cost: 23 USD'
'- family:'
'- home: house'
'location: 53rd street|Austin|Texas|U.S'
'type: old'
"original entry: '545'"
'issues:'
'- plumbing: fixed'
'ref:'
'- id: 1081'
'cost: 33 USD'
</code>```

Body:
I have a file that looks like this:

...

- family:
  - home: house
    location: 53rd street|Austin|Texas|U.S
    type: old
original entry: '544'
  issues:
  - plumbing: fixed
    ref:
    - id: 28
      cost: 23 USD

- family:
  - home: house
    location: 53rd street|Austin|Texas|U.S
    type: old
original entry: '545'
  issues:
  - plumbing: fixed
    ref:
    - id: 1081
      cost: 33 USD

 ...

This file has hundreds of similar entries on other families.

I want to make it look like this:

- family:
  - home: house
    location: 53rd street|Austin|Texas|U.S
    type: old
original entry: '544'
  issues:
  - plumbing: fixed
    ref:
    - id: 28
      cost: 23 USD
    - id: 1081
      cost: 33 USD

I have tried making a multiline regex where I just find the text in the middle and replace it with nothing. Here is the pattern I attempted:

pattern = "r'\s- family:\n\s+- home: house\n\s+tag: 53rd street|Austin|Texas|U.S\n\s+type: old\n\original entry: \'554\'\n\s+issues:\n\s+- plumbing: fixed\n\s+ref:'"

This did not seem to work. I tried one of those online regex tools that suggested:

pattern = "r'\s- family:\n\s+- home: house\n\s+tag: 53rd street\|Austin\|Texas\|U.S\n\s+type: old\n\original entry: '554'\n\s+issues:\n\s+- plumbing: fixed\n\s+ref:'"

This also did not appear to work. I have used my multiline regex function on simpler cases without a problem, so I know the regex code itself works. It is just that it seems a bit tricky getting a pattern that works.

I figure there must be some stuff that is not getting escaped correctly, or escaped too much. Also, this strategy does not seem to get both of the original entry numbers after each other.

Is there a way this can be done? I guess one can just use the entire two blocks as the pattern, and the result as the replacement text, but that seems even more bulkier and difficult...

Body:
The parser for doing this using pyparser is uncomplicated. Here, it's declared as the name p. Each line is defined to be everything up to an end-line followed by an end-line, and the entire file consists of OneOrMore of these. Since pyparsing ignores white space by default the empty lines disappear.

>>> import pyparsing as pp
>>> theFile = open('temp.txt').read()
>>> p = pp.OneOrMore(pp.Combine(pp.restOfLine+pp.Suppress('\n')))
>>> for item in p.parseString(theFile):
...     item
...
'- family:'
'- home: house'
'location: 53rd street|Austin|Texas|U.S'
'type: old'
"original entry: '544'"
'issues:'
'- plumbing: fixed'
'ref:'
'- id: 28'
'cost: 23 USD'
'- family:'
'- home: house'
'location: 53rd street|Austin|Texas|U.S'
'type: old'
"original entry: '545'"
'issues:'
'- plumbing: fixed'
'ref:'
'- id: 1081'
'cost: 33 USD'