问:
Storing public certificates and private keys in AWS
I have a use case where I want to usecertificate based authentication in AWS Lambda to generate oauth tokens. Currently I am storing the certificates and private keys locally and running it like a normal java application.

However while migrating to AWS Lambda, I need to store these .crt and .key files somewhere in AWS, so that I can use it in AWS Lambda.
I have come across some solutions like

1. Storing certs and keys in S3 buckets

2. Storing certs and keys in Secrets Manager

3. Storing them in Amazon Certificate Manager**

Can someone please help with which method is efficient and optimal for storing certs and keys?

答:
AWS ACM is not a regular secret store which you can query anytime you want to get your secrets back. ACM can only be used through integration with selected services such as load balancers. You can't use it with a lambda function.

Your only choices are AWS Secret Manager and SSM Parameter Store. SSM Parameter Store is free, but AWS Secret Manager has some extra features such as automated rotation of secrets.


来源: stackexchange

问:
Does Pandas have a dataframe length limit?
I want to create a system where I load and analyze large amounts of data into pandas. Also, I will later use this to write back to .parquet files

when I try to test this using a simple example, I see that there is some kind of built in limit on the number of rows

```<code>import pandas as pd

# Create file with 100 000 000 rows
contents = """
Tommy;19
Karen;20
"""*50000000

open("person.csv","w").write(
f"""
Name;Age
{contents}
"""
)
print("Test generated")

df = pd.read_csv("person.csv",delimiter=";")
len(df)
</code>```

returns 10 000 000. Not 100 000 000

答:
Change the method to create the file because I think you have to many blank rows and you don't close properly your file (without context manager or explicit close() method):

```<code># Create file with 100 000 000 rows
contents = """\
Tommy;19
Karen;20
"""*50000000

with open('person.csv', 'w') as fp:
    fp.write('Name;Age\n')
    fp.write(contents)
</code>```

Read the file:

```<code>df = pd.read_csv('person.csv', delimiter=';')
print(df)

# Output
           Name  Age
0         Tommy   19
1         Karen   20
2         Tommy   19
3         Karen   20
4         Tommy   19
...         ...  ...
99999995  Karen   20
99999996  Tommy   19
99999997  Karen   20
99999998  Tommy   19
99999999  Karen   20

[100000000 rows x 2 columns]
</code>```

ContentLicense: CC BY-SA 4.0

Body:
I want to create a system where I load and analyze large amounts of data into pandas. Also, I will later use this to write back to .parquet files

when I try to test this using a simple example, I see that there is some kind of built in limit on the number of rows

import pandas as pd

# Create file with 100 000 000 rows
contents = """
Tommy;19
Karen;20
"""*50000000

open("person.csv","w").write(
f"""
Name;Age
{contents}
"""
)
print("Test generated")

df = pd.read_csv("person.csv",delimiter=";")
len(df)

returns 10 000 000. Not 100 000 000

Body:
Change the method to create the file because I think you have to many blank rows and you don't close properly your file (without context manager or explicit close() method):

# Create file with 100 000 000 rows
contents = """\
Tommy;19
Karen;20
"""*50000000

with open('person.csv', 'w') as fp:
    fp.write('Name;Age\n')
    fp.write(contents)

Read the file:

df = pd.read_csv('person.csv', delimiter=';')
print(df)

# Output
           Name  Age
0         Tommy   19
1         Karen   20
2         Tommy   19
3         Karen   20
4         Tommy   19
...         ...  ...
99999995  Karen   20
99999996  Tommy   19
99999997  Karen   20
99999998  Tommy   19
99999999  Karen   20

[100000000 rows x 2 columns]


问:
Open Lite Speed + Elementor not save changes
since i've jumped from apache to open lite speed and started to use OLS cache i have problem with Elementor.
I'm creating something in elementor (can be block, page, post... doesn't matter what) and save it (lets call it v.1). All works fine.
When i want to change something, i'm editing it in Elementor, make some changes (lets call it v.2), save it and ... in front page i see no changes. So i'm reload (F5 or CRTL + F5) and i see page without changes (v.1).
I'm cleaning cache, browser - without success.
I'm taking a look in elementor page history and i see record with my changes (v.2). I click on it, restore changes and i see (v.2), so i save it.
On front page i can see v.2 but on Elementor after F5 / CTRL + F5 i still see v.1.

I suppose that somehow OLS cache is caching my editable pages/posts in backend and once it is cached it won't show any changes. But it should works when i'm cleaning cache...
Did you had any experience with it?

-- update

I see, that when i enable checkPublicCache (set to 1) the problem with Elementor occur:

When is disabled (set to 0) Elementor works fine.
I wonder why - Admin panel shouldn't be cached so much, it's rather private cache not public...

serve stale is off
Cleaning cache from wordpress not work, even disable cache from OLS plugin doesn't works.

答: Very easy to fix that go to CSS Settings --> disable Generate UCSS and disable CCSS per URL</p>


问:
How do I get my pc's windows Workgroup name in python
I'm trying to find my workGroup name in python,
does anybody know a function for that?</p>

答:
```<code>import wmi
wmi_os = wmi.Win32_ComputerSystem()[0]
print(wmi_os.Workgroup)
</code>```

You also can go further and take a look at print(wmi_os.__dict__['properties'].keys())

```<code>dict_keys(['AdminPasswordStatus', 'AutomaticManagedPagefile', 'AutomaticResetBootOption', 'AutomaticResetCapability', 'BootOptionOnLimit', 'BootOptionOnWatchDog', 'BootROMSupported', 'BootStatus', 'BootupState', 'Caption', 'ChassisBootupState', 'ChassisSKUNumber', 'CreationClassName', 'CurrentTimeZone', 'DaylightInEffect', 'Description', 'DNSHostName', 'Domain', 'DomainRole', 'EnableDaylightSavingsTime', 'FrontPanelResetStatus', 'HypervisorPresent', 'InfraredSupported', 'InitialLoadInfo', 'InstallDate', 'KeyboardPasswordStatus', 'LastLoadInfo', 'Manufacturer', 'Model', 'Name', 'NameFormat', 'NetworkServerModeEnabled', 'NumberOfLogicalProcessors', 'NumberOfProcessors', 'OEMLogoBitmap', 'OEMStringArray', 'PartOfDomain', 'PauseAfterReset', 'PCSystemType', 'PCSystemTypeEx', 'PowerManagementCapabilities', 'PowerManagementSupported', 'PowerOnPasswordStatus', 'PowerState', 'PowerSupplyState', 'PrimaryOwnerContact', 'PrimaryOwnerName', 'ResetCapability', 'ResetCount', 'ResetLimit', 'Roles', 'Status', 'SupportContactDescription', 'SystemFamily', 'SystemSKUNumber', 'SystemStartupDelay', 'SystemStartupOptions', 'SystemStartupSetting', 'SystemType', 'ThermalState', 'TotalPhysicalMemory', 'UserName', 'WakeUpType', 'Workgroup'])
</code>```

Some of them might be useful for you

Body:
import wmi
wmi_os = wmi.Win32_ComputerSystem()[0]
print(wmi_os.Workgroup)

You also can go further and take a look at print(wmi_os.__dict__['properties'].keys())

dict_keys(['AdminPasswordStatus', 'AutomaticManagedPagefile', 'AutomaticResetBootOption', 'AutomaticResetCapability', 'BootOptionOnLimit', 'BootOptionOnWatchDog', 'BootROMSupported', 'BootStatus', 'BootupState', 'Caption', 'ChassisBootupState', 'ChassisSKUNumber', 'CreationClassName', 'CurrentTimeZone', 'DaylightInEffect', 'Description', 'DNSHostName', 'Domain', 'DomainRole', 'EnableDaylightSavingsTime', 'FrontPanelResetStatus', 'HypervisorPresent', 'InfraredSupported', 'InitialLoadInfo', 'InstallDate', 'KeyboardPasswordStatus', 'LastLoadInfo', 'Manufacturer', 'Model', 'Name', 'NameFormat', 'NetworkServerModeEnabled', 'NumberOfLogicalProcessors', 'NumberOfProcessors', 'OEMLogoBitmap', 'OEMStringArray', 'PartOfDomain', 'PauseAfterReset', 'PCSystemType', 'PCSystemTypeEx', 'PowerManagementCapabilities', 'PowerManagementSupported', 'PowerOnPasswordStatus', 'PowerState', 'PowerSupplyState', 'PrimaryOwnerContact', 'PrimaryOwnerName', 'ResetCapability', 'ResetCount', 'ResetLimit', 'Roles', 'Status', 'SupportContactDescription', 'SystemFamily', 'SystemSKUNumber', 'SystemStartupDelay', 'SystemStartupOptions', 'SystemStartupSetting', 'SystemType', 'ThermalState', 'TotalPhysicalMemory', 'UserName', 'WakeUpType', 'Workgroup'])

Some of them might be useful for you


问:
How to add quotes from specific delimiter to end of the line, using awk?
I am trying to modify a file: (file.txt)

```<code>abc~123~xyz~123456~12~0.12~14~1.1~
omn~124~xdz~923231~13~0.0~13~1.1~14~0.45~19~80.1~
</code>```

to (new_file.txt)

```<code>abc~123~xyz~123456~"12~0.12~14~1.1~"
omn~124~xdz~923231~"13~0.0~13~1.1~14~0.45~19~80.1~"
</code>```

I tried using awk command:

```<code>awk -F'~' '{for(i=1;i<=4;i++){printf "%s~", $i}; printf"\""} {for(i=5;i<=NF;i+=1){printf "%s~", $i}; printf "\"\n"}' file.txt > new_file.txt
</code>```

but I am getting output as:

```<code>abc~123~xyz~123456~"12~0.12~14~1.1~~"
omn~124~xdz~923231~"13~0.0~13~1.1~14~0.45~19~80.1~~"
</code>```

Can anyone help me out in this as I am getting an extra "~" at end of each line? Any reference would also be helpful as I get confused while dealing with sed and awk commands.

答:
With your shown samples, please try following awk program. Written and tested in GNU awk, should work in any awk.

```<code>awk -v s1="\"" '
match($0,/^[^~]*~([^~]*~){3}/){
  print substr($0,RSTART,RLENGTH) s1 substr($0,RSTART+RLENGTH) s1
}
' Input_file
</code>```

Explanation: Simple explanation would be, firstly creating an awk variable named s1 which has value as ~ in it. Then in main program using awk's match function to match regex ^[^~]*~([^~]*~){3} which will basically match from starting of value to till 4th value of ~. Once its matched, I am printing matched sub string(from starting of value to till 4th occurrence of ~) then printing s1 and rest of the line's value followed by s1(as per OP's requirement).

Additional solution: Assuming in case you have lines which don't match ~ condition( meaning doesn't have 4 times ~ in it and you don't want to add ") then use following:

```<code>awk -v s1="\"" '
match($0,/^[^~]*~([^~]*~){3}/){
  $0=substr($0,RSTART,RLENGTH) s1 substr($0,RSTART+RLENGTH) s1
}
1
' Input_file
</code>```

Body:
I am trying to modify a file: (file.txt)

abc~123~xyz~123456~12~0.12~14~1.1~
omn~124~xdz~923231~13~0.0~13~1.1~14~0.45~19~80.1~

to (new_file.txt)

abc~123~xyz~123456~"12~0.12~14~1.1~"
omn~124~xdz~923231~"13~0.0~13~1.1~14~0.45~19~80.1~"

I tried using awk command:

awk -F'~' '{for(i=1;i<=4;i++){printf "%s~", $i}; printf"\""} {for(i=5;i<=NF;i+=1){printf "%s~", $i}; printf "\"\n"}' file.txt > new_file.txt

but I am getting output as:

abc~123~xyz~123456~"12~0.12~14~1.1~~"
omn~124~xdz~923231~"13~0.0~13~1.1~14~0.45~19~80.1~~"

Can anyone help me out in this as I am getting an extra "~" at end of each line? Any reference would also be helpful as I get confused while dealing with sed and awk commands.

Body:
With your shown samples, please try following awk program. Written and tested in GNU awk, should work in any awk.

awk -v s1="\"" '
match($0,/^[^~]*~([^~]*~){3}/){
  print substr($0,RSTART,RLENGTH) s1 substr($0,RSTART+RLENGTH) s1
}
' Input_file

Explanation: Simple explanation would be, firstly creating an awk variable named s1 which has value as ~ in it. Then in main program using awk's match function to match regex ^[^~]*~([^~]*~){3} which will basically match from starting of value to till 4th value of ~. Once its matched, I am printing matched sub string(from starting of value to till 4th occurrence of ~) then printing s1 and rest of the line's value followed by s1(as per OP's requirement).

Additional solution: Assuming in case you have lines which don't match ~ condition( meaning doesn't have 4 times ~ in it and you don't want to add ") then use following:

awk -v s1="\"" '
match($0,/^[^~]*~([^~]*~){3}/){
  $0=substr($0,RSTART,RLENGTH) s1 substr($0,RSTART+RLENGTH) s1
}
1
' Input_file


答:
An alternative method is to set_index with "movie_id" and explode the rating_all column (this creates a Series with duplicate indexes). Then cast it to a DataFrame constructor to build the preliminary DataFrame. Then use pivot on it to get the output in the desired format.

```<code>s = df.set_index('movie_id')['rating_all'].explode()
tmp = pd.DataFrame(s.tolist(), index = s.index).reset_index()
out = tmp.pivot('movie_id', 'age', ['avg_rating','count'])
</code>```

Output:

```<code>          avg_rating                        count
age            18-29 30-44  45+  <18  all   18-29   30-44    45+   <18         all
movie_id
tt1302006        8.3   7.9  7.8  8.7  8.1   41951   59729  18550   461      187675
tt7131622        7.9   7.6  7.5  8.4  7.8   82133   95878  26383   955      323152
tt7286456        8.7   8.5  8.3  9.1  8.6  160506  160158  30451  2244      592441
tt7653254        8.3   8.0  7.7  8.8  8.1   29740   33012   7875   318      109326
tt8579674        8.7   8.5  8.3  9.1  8.6    2437    2529    960    35        9420
tt8637428        7.9   7.6  7.3  8.0  7.7    5901    6492   2133    45       21362
</code>```

It turns out, set_index + explode + DataFrame + pivot is quite a bit faster than groupby + apply(DataFrame) + pivot_table:

```<code>%timeit -n 1000 s = df.set_index('movie_id')['rating_all'].explode(); tmp = pd.DataFrame(s.tolist(), index = s.index).reset_index(); out = tmp.pivot('movie_id', 'age', ['avg_rating','count'])
%timeit -n 1000 s = df.groupby('movie_id').rating_all.apply(lambda x: pd.DataFrame(x.values[0])).reset_index(); out = s.pivot_table(index='movie_id', columns=['age'],values=['avg_rating','count'],aggfunc='mean')
</code>```
```<code>5.1 ms ± 465 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
21.6 ms ± 1.53 ms per loop (mean ± std. dev. of 7 runs, 1000 loops each)
</code>```

Title: Explode dict from Pandas column

Body:
I have the following df:

    movie_id    rating_all
0   tt7653254   [{'age': 'all', 'avg_rating': 8.1, 'count': 109326}, {'age': '<18', 'avg_rating': 8.8, 'count': 318}, {'age': '18-29', 'avg_rating': 8.3, 'count': 29740}, {'age': '30-44', 'avg_rating': 8.0, 'count': 33012}, {'age': '45+', 'avg_rating': 7.7, 'count': 7875}]
1   tt8579674   [{'age': 'all', 'avg_rating': 8.6, 'count': 9420}, {'age': '<18', 'avg_rating': 9.1, 'count': 35}, {'age': '18-29', 'avg_rating': 8.7, 'count': 2437}, {'age': '30-44', 'avg_rating': 8.5, 'count': 2529}, {'age': '45+', 'avg_rating': 8.3, 'count': 960}]
2   tt7286456   [{'age': 'all', 'avg_rating': 8.6, 'count': 592441}, {'age': '<18', 'avg_rating': 9.1, 'count': 2244}, {'age': '18-29', 'avg_rating': 8.7, 'count': 160506}, {'age': '30-44', 'avg_rating': 8.5, 'count': 160158}, {'age': '45+', 'avg_rating': 8.3, 'count': 30451}]
3   tt1302006   [{'age': 'all', 'avg_rating': 8.1, 'count': 187675}, {'age': '<18', 'avg_rating': 8.7, 'count': 461}, {'age': '18-29', 'avg_rating': 8.3, 'count': 41951}, {'age': '30-44', 'avg_rating': 7.9, 'count': 59729}, {'age': '45+', 'avg_rating': 7.8, 'count': 18550}]
4   tt7131622   [{'age': 'all', 'avg_rating': 7.8, 'count': 323152}, {'age': '<18', 'avg_rating': 8.4, 'count': 955}, {'age': '18-29', 'avg_rating': 7.9, 'count': 82133}, {'age': '30-44', 'avg_rating': 7.6, 'count': 95878}, {'age': '45+', 'avg_rating': 7.5, 'count': 26383}]
5   tt8637428   [{'age': 'all', 'avg_rating': 7.7, 'count': 21362}, {'age': '<18', 'avg_rating': 8.0, 'count': 45}, {'age': '18-29', 'avg_rating': 7.9, 'count': 5901}, {'age': '30-44', 'avg_rating': 7.6, 'count': 6492}, {'age': '45+', 'avg_rating': 7.3, 'count': 2133}]

And I want to transform it to something like:

    movie_id    all_avg     all_count   <18_avg     <18_count   18-29_avg
0   tt7653254   8.1         109326      8.8         318         8.3
1   tt8579674   8.6         9420        9.1         35          8.7
2   tt7286456   8.6         592441      9.1         2244        8.7
3   tt1302006   8.1         187675      8.7         461         8.3
4   tt7131622   7.8         323152      8.4         955         7.9
5   tt8637428   7.7         21362       8           45          7.9

and so on...

I've tried

ratings.set_index('movie_id')['rating_all'].apply(pd.Series).reset_index()

and using

json_normalize(data,
               record_path=['rating_all'],
               meta=['movie_id']).set_index('movie_id')

but none give something similiar. Is there an easy way to explode the dictionary into columns?

Data to produce the DataFrame:

data = {'movie_id': ['tt7653254', 'tt8579674', 'tt7286456', 'tt1302006', 'tt7131622', 'tt8637428'],
        'rating_all': [[{'age': 'all', 'avg_rating': 8.1, 'count': 109326},
                        {'age': '<18', 'avg_rating': 8.8, 'count': 318},
                        {'age': '18-29', 'avg_rating': 8.3, 'count': 29740},
                        {'age': '30-44', 'avg_rating': 8.0, 'count': 33012},
                        {'age': '45+', 'avg_rating': 7.7, 'count': 7875}],
                       [{'age': 'all', 'avg_rating': 8.6, 'count': 9420},
                        {'age': '<18', 'avg_rating': 9.1, 'count': 35},
                        {'age': '18-29', 'avg_rating': 8.7, 'count': 2437},
                        {'age': '30-44', 'avg_rating': 8.5, 'count': 2529},
                        {'age': '45+', 'avg_rating': 8.3, 'count': 960}],
                       [{'age': 'all', 'avg_rating': 8.6, 'count': 592441},
                        {'age': '<18', 'avg_rating': 9.1, 'count': 2244},
                        {'age': '18-29', 'avg_rating': 8.7, 'count': 160506},
                        {'age': '30-44', 'avg_rating': 8.5, 'count': 160158},
                        {'age': '45+', 'avg_rating': 8.3, 'count': 30451}],
                       [{'age': 'all', 'avg_rating': 8.1, 'count': 187675},
                        {'age': '<18', 'avg_rating': 8.7, 'count': 461},
                        {'age': '18-29', 'avg_rating': 8.3, 'count': 41951},
                        {'age': '30-44', 'avg_rating': 7.9, 'count': 59729},
                        {'age': '45+', 'avg_rating': 7.8, 'count': 18550}],
                       [{'age': 'all', 'avg_rating': 7.8, 'count': 323152},
                        {'age': '<18', 'avg_rating': 8.4, 'count': 955},
                        {'age': '18-29', 'avg_rating': 7.9, 'count': 82133},
                        {'age': '30-44', 'avg_rating': 7.6, 'count': 95878},
                        {'age': '45+', 'avg_rating': 7.5, 'count': 26383}],
                       [{'age': 'all', 'avg_rating': 7.7, 'count': 21362},
                        {'age': '<18', 'avg_rating': 8.0, 'count': 45},
                        {'age': '18-29', 'avg_rating': 7.9, 'count': 5901},
                        {'age': '30-44', 'avg_rating': 7.6, 'count': 6492},
                        {'age': '45+', 'avg_rating': 7.3, 'count': 2133}]]}

Body:
An alternative method is to set_index with "movie_id" and explode the rating_all column (this creates a Series with duplicate indexes). Then cast it to a DataFrame constructor to build the preliminary DataFrame. Then use pivot on it to get the output in the desired format.

s = df.set_index('movie_id')['rating_all'].explode()
tmp = pd.DataFrame(s.tolist(), index = s.index).reset_index()
out = tmp.pivot('movie_id', 'age', ['avg_rating','count'])

Output:

          avg_rating                        count
age            18-29 30-44  45+  <18  all   18-29   30-44    45+   <18         all
movie_id
tt1302006        8.3   7.9  7.8  8.7  8.1   41951   59729  18550   461      187675
tt7131622        7.9   7.6  7.5  8.4  7.8   82133   95878  26383   955      323152
tt7286456        8.7   8.5  8.3  9.1  8.6  160506  160158  30451  2244      592441
tt7653254        8.3   8.0  7.7  8.8  8.1   29740   33012   7875   318      109326
tt8579674        8.7   8.5  8.3  9.1  8.6    2437    2529    960    35        9420
tt8637428        7.9   7.6  7.3  8.0  7.7    5901    6492   2133    45       21362

It turns out, set_index + explode + DataFrame + pivot is quite a bit faster than groupby + apply(DataFrame) + pivot_table:

%timeit -n 1000 s = df.set_index('movie_id')['rating_all'].explode(); tmp = pd.DataFrame(s.tolist(), index = s.index).reset_index(); out = tmp.pivot('movie_id', 'age', ['avg_rating','count'])
%timeit -n 1000 s = df.groupby('movie_id').rating_all.apply(lambda x: pd.DataFrame(x.values[0])).reset_index(); out = s.pivot_table(index='movie_id', columns=['age'],values=['avg_rating','count'],aggfunc='mean')

5.1 ms ± 465 µs per loop (mean ± std. dev. of 7 runs, 1000 loops each)
21.6 ms ± 1.53 ms per loop (mean ± std. dev. of 7 runs, 1000 loops each)


问:
Unable to access Google buckets using spark-submit
I'm trying to access google buckets, when using spark-submit and running into issues.

Here is the command, and the error :

```<code>Command :
spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.0 --jars gs://spark-jars-karan/spark-bigquery-with-dependencies_2.12-0.23.2.jar,gs://spark-jars-karan/spark-avro_2.12-3.1.2.jar  /Users/karanalang/PycharmProjects/Kafka/StructuredStreaming_GCP_Versa_Sase.py

Error :
22/02/11 20:06:59 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" org.apache.hadoop.fs.UnsupportedFileSystemException: No FileSystem for scheme "gs"
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:3443)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3466)
    at org.apache.hadoop.fs.FileSystem.access$300(FileSystem.java:174)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:3574)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3521)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:540)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPath(DependencyUtils.scala:317)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2(DependencyUtils.scala:273)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2$adapted(DependencyUtils.scala:271)
    at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:293)
    at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
    at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
    at scala.collection.TraversableLike.flatMap(TraversableLike.scala:293)
    at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:290)
    at scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPaths(DependencyUtils.scala:271)
    at org.apache.spark.deploy.SparkSubmit.$anonfun$prepareSubmitEnvironment$4(SparkSubmit.scala:364)
    at scala.Option.map(Option.scala:230)
    at org.apache.spark.deploy.SparkSubmit.prepareSubmitEnvironment(SparkSubmit.scala:364)
    at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:898)
    at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
    at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
    at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
    at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1043)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1052)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

</code>```

Tried this modified query(adding --conf spark.hadoop.fs.gs.impl=com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem)aand getting ClassNotFoundError :

```<code>Modified command :

spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.0 --conf spark.hadoop.fs.gs.impl=com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem --jars gs://spark-jars-karan/spark-bigquery-with-dependencies_2.12-0.23.2.jar,gs://spark-jars-karan/spark-avro_2.12-3.1.2.jar  /Users/karanalang/PycharmProjects/Kafka/StructuredStreaming_GCP_Versa_Sase.py

Error :
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: Class com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem not found
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2667)
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:3431)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3466)
    at org.apache.hadoop.fs.FileSystem.access$300(FileSystem.java:174)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:3574)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3521)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:540)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPath(DependencyUtils.scala:317)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2(DependencyUtils.scala:273)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2$adapted(DependencyUtils.scala:271)
    at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:293)
    at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
    at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
    at scala.collection.TraversableLike.flatMap(TraversableLike.scala:293)
    at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:290)
    at scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPaths(DependencyUtils.scala:271)
    at org.apache.spark.deploy.SparkSubmit.$anonfun$prepareSubmitEnvironment$4(SparkSubmit.scala:364)
    at scala.Option.map(Option.scala:230)
    at org.apache.spark.deploy.SparkSubmit.prepareSubmitEnvironment(SparkSubmit.scala:364)
    at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:898)
    at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
    at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
    at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
    at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1043)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1052)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: Class com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem not found
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2571)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2665)

</code>```

What needs to be done to debug/fix this ?
tia!

答:
You are trying to access a Google storage bucket gs:// from your local host.

It does not see it because spark-submit assumes that it is a local file system on the host which is not.

You need to mount gs:// bucket as a local file system.

You can use the tool called gcsfuse https://cloud.google.com/storage/docs/gcs-fuse . Cloud Storage FUSE is an open source FUSE adapter that allows you to mount Cloud Storage buckets as file systems on Linux or macOS systems. You can download gcsfuse from https://github.com/GoogleCloudPlatform/gcsfuse

Pretty simple.

It will be installed as /usr/bin/gcsfuse and you can mount it by creating a local mount file like /mnt/gs as root and give permission to others to use it.

As a normal user that needs to access gs:// bucket (not as root), use gcsfuse to mount it. For example I am mounting a gcs bucket called spark-jars-karan here

Just use the bucket name itself

```<code>gcsfuse spark-jars-karan /mnt/gs
</code>```

Then you can refer to it as /mnt/gs in spark-submit from on-premise host

```<code>spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.0 --jars /mnt/gs/spark-bigquery-with-dependencies_2.12-0.23.2.jar
</code>```

Body:
I'm trying to access google buckets, when using spark-submit and running into issues.

Here is the command, and the error :

Command :
spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.0 --jars gs://spark-jars-karan/spark-bigquery-with-dependencies_2.12-0.23.2.jar,gs://spark-jars-karan/spark-avro_2.12-3.1.2.jar  /Users/karanalang/PycharmProjects/Kafka/StructuredStreaming_GCP_Versa_Sase.py

Error :
22/02/11 20:06:59 WARN NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
Exception in thread "main" org.apache.hadoop.fs.UnsupportedFileSystemException: No FileSystem for scheme "gs"
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:3443)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3466)
    at org.apache.hadoop.fs.FileSystem.access$300(FileSystem.java:174)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:3574)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3521)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:540)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPath(DependencyUtils.scala:317)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2(DependencyUtils.scala:273)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2$adapted(DependencyUtils.scala:271)
    at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:293)
    at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
    at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
    at scala.collection.TraversableLike.flatMap(TraversableLike.scala:293)
    at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:290)
    at scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPaths(DependencyUtils.scala:271)
    at org.apache.spark.deploy.SparkSubmit.$anonfun$prepareSubmitEnvironment$4(SparkSubmit.scala:364)
    at scala.Option.map(Option.scala:230)
    at org.apache.spark.deploy.SparkSubmit.prepareSubmitEnvironment(SparkSubmit.scala:364)
    at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:898)
    at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
    at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
    at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
    at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1043)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1052)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)

Tried this modified query(adding --conf spark.hadoop.fs.gs.impl=com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem)aand getting ClassNotFoundError :

Modified command :

spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.0 --conf spark.hadoop.fs.gs.impl=com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem --jars gs://spark-jars-karan/spark-bigquery-with-dependencies_2.12-0.23.2.jar,gs://spark-jars-karan/spark-avro_2.12-3.1.2.jar  /Users/karanalang/PycharmProjects/Kafka/StructuredStreaming_GCP_Versa_Sase.py

Error :
Exception in thread "main" java.lang.RuntimeException: java.lang.ClassNotFoundException: Class com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem not found
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2667)
    at org.apache.hadoop.fs.FileSystem.getFileSystemClass(FileSystem.java:3431)
    at org.apache.hadoop.fs.FileSystem.createFileSystem(FileSystem.java:3466)
    at org.apache.hadoop.fs.FileSystem.access$300(FileSystem.java:174)
    at org.apache.hadoop.fs.FileSystem$Cache.getInternal(FileSystem.java:3574)
    at org.apache.hadoop.fs.FileSystem$Cache.get(FileSystem.java:3521)
    at org.apache.hadoop.fs.FileSystem.get(FileSystem.java:540)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPath(DependencyUtils.scala:317)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2(DependencyUtils.scala:273)
    at org.apache.spark.util.DependencyUtils$.$anonfun$resolveGlobPaths$2$adapted(DependencyUtils.scala:271)
    at scala.collection.TraversableLike.$anonfun$flatMap$1(TraversableLike.scala:293)
    at scala.collection.IndexedSeqOptimized.foreach(IndexedSeqOptimized.scala:36)
    at scala.collection.IndexedSeqOptimized.foreach$(IndexedSeqOptimized.scala:33)
    at scala.collection.mutable.WrappedArray.foreach(WrappedArray.scala:38)
    at scala.collection.TraversableLike.flatMap(TraversableLike.scala:293)
    at scala.collection.TraversableLike.flatMap$(TraversableLike.scala:290)
    at scala.collection.AbstractTraversable.flatMap(Traversable.scala:108)
    at org.apache.spark.util.DependencyUtils$.resolveGlobPaths(DependencyUtils.scala:271)
    at org.apache.spark.deploy.SparkSubmit.$anonfun$prepareSubmitEnvironment$4(SparkSubmit.scala:364)
    at scala.Option.map(Option.scala:230)
    at org.apache.spark.deploy.SparkSubmit.prepareSubmitEnvironment(SparkSubmit.scala:364)
    at org.apache.spark.deploy.SparkSubmit.org$apache$spark$deploy$SparkSubmit$$runMain(SparkSubmit.scala:898)
    at org.apache.spark.deploy.SparkSubmit.doRunMain$1(SparkSubmit.scala:180)
    at org.apache.spark.deploy.SparkSubmit.submit(SparkSubmit.scala:203)
    at org.apache.spark.deploy.SparkSubmit.doSubmit(SparkSubmit.scala:90)
    at org.apache.spark.deploy.SparkSubmit$$anon$2.doSubmit(SparkSubmit.scala:1043)
    at org.apache.spark.deploy.SparkSubmit$.main(SparkSubmit.scala:1052)
    at org.apache.spark.deploy.SparkSubmit.main(SparkSubmit.scala)
Caused by: java.lang.ClassNotFoundException: Class com.google.cloud.hadoop.fs.gcs.GoogleHadoopFileSystem not found
    at org.apache.hadoop.conf.Configuration.getClassByName(Configuration.java:2571)
    at org.apache.hadoop.conf.Configuration.getClass(Configuration.java:2665)

What needs to be done to debug/fix this ?
tia!

Body:
You are trying to access a Google storage bucket gs:// from your local host.

It does not see it because spark-submit assumes that it is a local file system on the host which is not.

You need to mount gs:// bucket as a local file system.

You can use the tool called gcsfuse https://cloud.google.com/storage/docs/gcs-fuse . Cloud Storage FUSE is an open source FUSE adapter that allows you to mount Cloud Storage buckets as file systems on Linux or macOS systems. You can download gcsfuse from https://github.com/GoogleCloudPlatform/gcsfuse

Pretty simple.

It will be installed as /usr/bin/gcsfuse and you can mount it by creating a local mount file like /mnt/gs as root and give permission to others to use it.

As a normal user that needs to access gs:// bucket (not as root), use gcsfuse to mount it. For example I am mounting a gcs bucket called spark-jars-karan here

Just use the bucket name itself

gcsfuse spark-jars-karan /mnt/gs

Then you can refer to it as /mnt/gs in spark-submit from on-premise host

spark-submit --packages org.apache.spark:spark-sql-kafka-0-10_2.12:3.2.0 --jars /mnt/gs/spark-bigquery-with-dependencies_2.12-0.23.2.jar


问:
Extremely slow Sequelize PostGis query with ST_DistanceSphere
So I'm using Sequelize to query for items within a certain radius, i.e:

```<code>const radius = 10000 // metres

const location = sequelize.literal(`ST_GeomFromText('POINT(${longitude} ${latitude})')`)
const distance = sequelize.fn('ST_DistanceSphere', sequelize.col('item.coordinates'), location)

console.time("test")

const nearbyItems = await models.Item.findAll({
    limit: 20,
    where: sequelize.where(distance, { [Op.lte]: radius }),
})

const response = []

console.timeEnd("test")
</code>```

But this query takes neary 7 seconds to run (on a database with around 100 items in it). This seems bizarrely slow - can anyone see any issues with the code above that'd result in it being so slow? Is there a faster alternative anyone knows about?

答:
You definitely need to create a proper index on geometry column like this:

CREATE INDEX idx_items_coordinates
  ON items
  USING GIST (coordinates);
```

See PostGIS indexing

Body:
So I'm using Sequelize to query for items within a certain radius, i.e:

const radius = 10000 // metres

const location = sequelize.literal(`ST_GeomFromText('POINT(${longitude} ${latitude})')`)
const distance = sequelize.fn('ST_DistanceSphere', sequelize.col('item.coordinates'), location)

console.time("test")

const nearbyItems = await models.Item.findAll({
    limit: 20,
    where: sequelize.where(distance, { [Op.lte]: radius }),
})

const response = []

console.timeEnd("test")

But this query takes neary 7 seconds to run (on a database with around 100 items in it). This seems bizarrely slow - can anyone see any issues with the code above that'd result in it being so slow? Is there a faster alternative anyone knows about?

Body:
You definitely need to create a proper index on geometry column like this:

CREATE INDEX idx_items_coordinates
  ON items
  USING GIST (coordinates);

See PostGIS indexing


问:
CAP theorem or Brewer's therom in plain english?
I have read the wiki, and I understand sentences explaining the  Consistency Availability and Partition tolerance but grasping  CAP/Brewer's theorem  is like holding a fish.

I believe there exist a better intuitive way  explaining and understanding CAP theorem.

Any good text ?

{
Before someone think question formed as Plain-English-Explanation are nonconstructive, here is a list of all other great Plain-English-Explanations question.

What is a plain English explanation of "Big O" notation?

Ukkonen's suffix tree algorithm in plain English?

What is SOA "in plain english"?

Can you explain what "git reset" does in plain english?

}

答:
CAP theorem says that in case of Network Partition(P) in a distributed data store, one needs to sacrifice either Consistency(C) or Availability(A).

The two out of three terminology (CA/CP/AP) often used is confusing as it seems that each of C, A and P are some characteristics of a system but P actually is a situation which forces to pick only one of the characteristics out of C and A.

ContentLicense: CC BY-SA 3.0


问:
Android save View position on orientation changed

Possible Duplicate:

  Android - disable landscape mode?

I can't save position of view when orientation changes.
I think it's because with orientation it also changes and I want that view stayed on the same position. For example of it was in the upper left corner of screen it stayed there and it doesn't matter what orientation of the device.
I'm using some kind of Absolute layout. Because I need to manage few screens at the same time.
So, i have x/y coordinate system. I think it's the main problem, but I can't solve it :(

I've attached images that you could see my problem.
As you can see first screen is portrait mode and View is located in upper-left corner, but when I changed to landscape mode position of view is also changed to upper-right corner.
And I need that position of view stayed always in left-upper corner.

http://imgur.com/qo19E&u2K0hl

http://imgur.com/qo19El&u2K0h

Sorry to bad screen. I'm still developing of an application and can't provide better screens :)

Ps: If you need some code, just say what part of code do you need.

答:
It would be nice if you could provide some code or screenshots.

Anyway, when the orientation changes, your activity is destroyed and recreated.
If you have a well designed xml layout file (using linearlayout, relativelayout and properties like "wrap_content", "fill_parent"...) it will reload it in the onCreate() method, so all the resizing should be done automatically.

If your views can be moved by the user or are loaded from runtime values, you can save it. Look at this post for exemple : Override Orientation Change But NOT Restart The Activity AND Pass State Data


问:
In Processing, how can I save part of the window as an image?
I am using Processing under Fedora 20, and I want to display an image of the extending tracks of objects moving across part of the screen, with each object displayed at its current position at the end of the track. To avoid having to record all the co-ordinates of the tracks, I usesave("image.png"); to save the tracks so far, then draw the objects. In the next frame I use img = loadImage("image.png"); to restore the tracks made so far, without the objects, which would still be in their previous positions.. I extend the tracks to their new positions, then usesave("image.png"); to save the extended tracks, still without the objects, ready for the next loop round. Then I draw the objects in their new positions at the end of their extended tracks. In this way successive loops show the objects advancing, with their previous positions as tracks behind them.

This has worked well in tests where the image is the whole frame, but now I need to put that display in a corner of the whole frame, and leave the rest unchanged. I expect that createImage(...) will be the answer, but I cannot find any details of how to to so.

A similar question asked here has this recommendation: "The PImage class contains a save() function that exports to file. The API should be your first stop for questions like this." Of course I've looked at that API, but I don't think it helps here, unless I have to create the image to save pixel by pixel, in which case I would expect it to slow things down a lot.

So my question is: in Processing can I save and restore just part of the frame as an image, without affecting the rest of the frame?

答:
Old news, but here's an answer: you can use the pixel array and math.

Let's say that this is your viewport:

You can use loadPixels(); to fill the pixels[] array with the current content of the viewport, then fish the pixels you want from this array.

In the given example, here's a way to filter the unwanted pixels:

```<code>void exportImage() {
  // creating the image to the "desired size"
  PImage img = createImage(600, 900, RGB);

  loadPixels();
  int index = 0;
  for(int i=0; i<pixels.length; i++) {
    // filtering the unwanted first 200 pixels on every row
    // remember that the pixels[] array is 1 dimensional, so some math are unavoidable. For this simple example I use the modulo operator.
    if (i % width >= 200) { // "magic numbers" are bad, remember. This is only a simplification.
      img.pixels[index] = pixels[i];
      index++;
    }
  }
  img.updatePixels();
  img.save("test.png");
}
</code>```

It may be too late to help you, but maybe someone else will need this. Either way, have fun!

Body:
Old news, but here's an answer: you can use the pixel array and math.

Let's say that this is your viewport:

You can use loadPixels(); to fill the pixels[] array with the current content of the viewport, then fish the pixels you want from this array.

In the given example, here's a way to filter the unwanted pixels:

void exportImage() {
  // creating the image to the "desired size"
  PImage img = createImage(600, 900, RGB);

  loadPixels();
  int index = 0;
  for(int i=0; i<pixels.length; i++) {
    // filtering the unwanted first 200 pixels on every row
    // remember that the pixels[] array is 1 dimensional, so some math are unavoidable. For this simple example I use the modulo operator.
    if (i % width >= 200) { // "magic numbers" are bad, remember. This is only a simplification.
      img.pixels[index] = pixels[i];
      index++;
    }
  }
  img.updatePixels();
  img.save("test.png");
}

It may be too late to help you, but maybe someone else will need this. Either way, have fun!


问:
Writing a function that returns a list with the name and content of subfolders in r
I'm trying to write a function that displays the subfolder names and contents. I have the following written code. However when I call the function, only the names of the subfolders are returned.

```<code>My_file <- function (Folder_name){

  My_list <- list.files(path =  "/Users/user/Desktop/task/Data/Data")

return(My_list)

}

</code>```

The folder "Data" contains 2 subfolders "House" and "Cars". I want the function to return the name of the subfolder and the contents of each subfolder.

For example output should be:

```<code>$House

Bungalow.extension

$Car

Porsche.extension
</code>```

Thank you!

答:
Does this work?

```<code>path =  "/Users/user/Desktop/task/Data/Data"
lapply(list.files(path), function(i) list.files(paste0(path, "/", i)))
</code>```

Edit:
Suppose this is your current  path :

```<code>path = "/Users/user/Desktop/task/Data"
</code>```

You want to look into Folder_name (which is a folder inside path) and get the list of subfolders as well as their contents.

```<code>My_file <- function (Folder_name){
  newpath <- paste0(path, "/", Folder_name)
  lapply(list.files(newpath), function(i) list.files(paste0(newpath, "/", i)))
}
</code>```

Try My_file("Data").

Body:
I'm trying to write a function that displays the subfolder names and contents. I have the following written code. However when I call the function, only the names of the subfolders are returned.

My_file <- function (Folder_name){

  My_list <- list.files(path =  "/Users/user/Desktop/task/Data/Data")

return(My_list)

}

The folder "Data" contains 2 subfolders "House" and "Cars". I want the function to return the name of the subfolder and the contents of each subfolder.

For example output should be:

$House

Bungalow.extension

$Car

Porsche.extension

Thank you!

Body:
Does this work?

path =  "/Users/user/Desktop/task/Data/Data"
lapply(list.files(path), function(i) list.files(paste0(path, "/", i)))

Edit:
Suppose this is your current  path :

path = "/Users/user/Desktop/task/Data"

You want to look into Folder_name (which is a folder inside path) and get the list of subfolders as well as their contents.

My_file <- function (Folder_name){
  newpath <- paste0(path, "/", Folder_name)
  lapply(list.files(newpath), function(i) list.files(paste0(newpath, "/", i)))
}

Try My_file("Data").


问:
Rails: Param is missing or the value is empty in ManagerController#addtoproject
I have been trying to add project_id and user_id to the following

```<code> create_table "project_users", force: :cascade do |t|
    t.integer "project_id"
    t.integer "user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end
</code>```

Model project_user.rb

```<code>class ProjectUser < ApplicationRecord
  has_many :users
  has_many :projects
end
</code>```

This is my controller that is supposed to add data in the table:

```<code>def addtoproject
    @emp_id = params[:eid]
    @project_id = params[:pid]

    @add_user = ProjectUser.new(params.require(:projectuser).permit(:project_id, :user_id))
    @add_user.project_id = @project_id
    @add_user.user_id = @emp_id
    @add_user.save
  end
</code>```

@emp_id and @project_id both contain valid values.
Rails is throwing the error on the line

```<code>@add_user = ProjectUser.new(params.require(:projectuser).permit(:project_id, :user_id))
</code>```

Error screenshot:

Any clues how this error can be fixed? As the table name is "project_users", I reckon I maybe missing an "_" somewhere?

Update 1
Clicking Add to Project invokes the method addtoproject inside controller.

addusers.html.erb:

```<code><table id='employee-table' class="table table-hover">
    <thead  class="thead-light">
      <tr>
        <th>Employee ID</th>
        <th>Name</th>
        <th>Role</th>
        <th colspan="2"></th>
      </tr>
    </thead>

    <tbody>
      <% @employees.each_with_index do |employee, index| %>
        <tr>
          <td><%= employee.id %></td>
          <td><%= employee.firstname + ' ' + employee.lastname %></td>
          <td><%= employee.user_type %></td>
          <td><%= link_to "Add to Project", add_to_project_path(eid: employee, pid: @project_id), :class => "btn btn-success", :style => "float:right"%></td>
        </tr>
      <% end %>
    </tbody>
  </table>
</code>```

答:
It turns out that if the parameters are not passed using form_with as in my case, there is no need for params.require or params.permit (as quoted by @Cjmarkham these attributes are not present).

Just initialising an empty instance of the model and saving it worked for me.

```<code>@add_user = ProjectUser.new
@add_user.project_id = @project_id
@add_user.user_id = @emp_id
@add_user.save
</code>```

Body:
I have been trying to add project_id and user_id to the following

 create_table "project_users", force: :cascade do |t|
    t.integer "project_id"
    t.integer "user_id"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
  end

Model project_user.rb

class ProjectUser < ApplicationRecord
  has_many :users
  has_many :projects
end

This is my controller that is supposed to add data in the table:

def addtoproject
    @emp_id = params[:eid]
    @project_id = params[:pid]

    @add_user = ProjectUser.new(params.require(:projectuser).permit(:project_id, :user_id))
    @add_user.project_id = @project_id
    @add_user.user_id = @emp_id
    @add_user.save
  end

@emp_id and @project_id both contain valid values.
Rails is throwing the error on the line

@add_user = ProjectUser.new(params.require(:projectuser).permit(:project_id, :user_id))

Error screenshot:

Any clues how this error can be fixed? As the table name is "project_users", I reckon I maybe missing an "_" somewhere?

Update 1
Clicking Add to Project invokes the method addtoproject inside controller.

addusers.html.erb:

        Employee ID
        Name
        Role

      <% @employees.each_with_index do |employee, index| %>

          <%= employee.id %>
          <%= employee.firstname + ' ' + employee.lastname %>
          <%= employee.user_type %>
          <%= link_to "Add to Project", add_to_project_path(eid: employee, pid: @project_id), :class => "btn btn-success", :style => "float:right"%>

      <% end %>

Body:
It turns out that if the parameters are not passed using form_with as in my case, there is no need for params.require or params.permit (as quoted by @Cjmarkham these attributes are not present).

Just initialising an empty instance of the model and saving it worked for me.

@add_user = ProjectUser.new
@add_user.project_id = @project_id
@add_user.user_id = @emp_id
@add_user.save


问:
Creating a list of existing dictionaries in python
I need to get a list of some dictionaries that I defined before.The dictionaries look like these:
dic1={"D":1.4,"SD":1.4} dic2={"D":1.2,"SD":1.2,"L":1.6,"LR":1.6,"LR0.5":1.6,"LP":1.6,"LRF":0.5} dic3={"D":1.2,"SD":1.2,"L":1,"LR":1,"LR0.5":1,"LP":1,"LRF":1.6}
And I expect a list like this:

```<code>list=[{"D":1.4,"SD":1.4},{"D":1.2,"SD":1.2,"L":1.6,"LR":1.6,"LR0.5":1.6,"LP":1.6,"LRF":0.5},                                                                               {"D":1.2,"SD":1.2,"L":1,"LR":1,"LR0.5":1,"LP":1,"LRF":1.6}]
</code>```

How can I create it using a loop in python?

答:
If you don't want to include all the dictionaries, do something like this:

```<code>lyst = []

# Define dic1
dic1 = {}
lyst += [dic1]

# Code

dic2 = {}
lyst += [dic2]

# etc...
</code>```

Append the dictionaries to the list as you create them.

Of course, if you want to include all the dictionaries in the script, use @Daniil Ryzhkov's answer.

Body:
I need to get a list of some dictionaries that I defined before.The dictionaries look like these:
dic1={"D":1.4,"SD":1.4} dic2={"D":1.2,"SD":1.2,"L":1.6,"LR":1.6,"LR0.5":1.6,"LP":1.6,"LRF":0.5} dic3={"D":1.2,"SD":1.2,"L":1,"LR":1,"LR0.5":1,"LP":1,"LRF":1.6}
And I expect a list like this:

list=[{"D":1.4,"SD":1.4},{"D":1.2,"SD":1.2,"L":1.6,"LR":1.6,"LR0.5":1.6,"LP":1.6,"LRF":0.5},                                                                               {"D":1.2,"SD":1.2,"L":1,"LR":1,"LR0.5":1,"LP":1,"LRF":1.6}]

How can I create it using a loop in python?

Body:
If you don't want to include all the dictionaries, do something like this:

lyst = []

# Define dic1
dic1 = {}
lyst += [dic1]

# Code

dic2 = {}
lyst += [dic2]

# etc...

Append the dictionaries to the list as you create them.

Of course, if you want to include all the dictionaries in the script, use @Daniil Ryzhkov's answer.


问:
Dynamically building WHERE clauses in SQL statements
I have a question regarding SQL. I have the following SQL statement:

```<code>SELECT id, First, Last, E_Mail, Notes
FROM mytable
WHERE SOMETHING_SHOULD_BE_HERE IS NOT NULL;
</code>```

I know that the SOMETHING_SHOULD_BE_HERE should be a column(attribute) in my table. Is their a way I can put a variable that can refer to the column I'm trying to access? In my case their are 30 columns. Can I have a string for SOMETHING_SHOULD_BE_HERE that can be assigned in my program to the column in which I want to search?

Thanks

答:
In JDBC program, yes,the select statement can be composed like string operation.</p>

```<code>for(String colName: colList)
{
String sql="Select id, First, Last, E_Mail, Notes From mytable where "+colName+" IS NOT NULL";
//execute the sql statement
 }
</code>```

Body:
I have a question regarding SQL. I have the following SQL statement:

SELECT id, First, Last, E_Mail, Notes
FROM mytable
WHERE SOMETHING_SHOULD_BE_HERE IS NOT NULL;

I know that the SOMETHING_SHOULD_BE_HERE should be a column(attribute) in my table. Is their a way I can put a variable that can refer to the column I'm trying to access? In my case their are 30 columns. Can I have a string for SOMETHING_SHOULD_BE_HERE that can be assigned in my program to the column in which I want to search?

Thanks

Body:
In JDBC program, yes,the select statement can be composed like string operation.

for(String colName: colList)
{
String sql="Select id, First, Last, E_Mail, Notes From mytable where "+colName+" IS NOT NULL";
//execute the sql statement
 }


问:
Opening Word Document From Excel
I am trying to use VBA  to open a specific word document when I click on a button in my excel spreadsheet.  I want to actually go into the document. I then want to  change the size of the window to "Restore Down". Essentially the word window should be the size of a popup box. When I run the VBA, I am only sometimes taken to the word document. The rest of the time the Word Icon just shows up on my windows menu bar and flashes. My VBA in Word does absolutely nothing. I have displayed my Word and Excel VBA below.</p>
```<code>My VBA in Excel

Private Sub CommandButton3_Click()
Set wordapp = CreateObject("word.Application")
wordapp.documents.Open "C:\Users\rossy\OneDrive\Work In Progress\Payroll and Billing
Spreadsheet\Newest 148\Code\1.docx"
wordapp.Visible = True
wordapp.Application.Activate
End Sub

My VBA In Word

Private Sub Document_Open()
With Application
.WindowState = wdWindowStateNormal
.Resize Width:=InchesToPoints(5), Height:=InchesToPoints(5)
End With
End Sub
</code>```

答:
If all you want to do is to resize the Word window, I would get rid of the vba code in your Word document, and add it to Excel vba code as follows:

```<code>Private Sub CommandButton3_Click()
    Set wordapp = CreateObject("word.Application")

    On Error GoTo OpenedErr

    Set doc = wordapp.documents.Open("C:\Users\rossy\OneDrive\Work In Progress\Payroll and Billing Spreadsheet\Newest 148\Code\1.docx")

    wordapp.Application.WindowState = wdWindowStateNormal
    wordapp.Application.Resize Width:=400, Height:=400

    wordapp.Visible = True
    wordapp.Application.Activate

OpenedErr:
    ' Don´t forget to clean memory once done
    Set doc = Nothing
    Set wordapp = Nothing
End Sub
</code>```

Please try this and see if it opens correctly without flashing (In my PC it opens the Word app and activates it, I couldn´t reproduce the flashing behavior you mentioned).

If this solves your problem, please mark this as an answer.

Title: Opening Word Document From Excel

Body:
I am trying to use VBA  to open a specific word document when I click on a button in my excel spreadsheet.  I want to actually go into the document. I then want to  change the size of the window to "Restore Down". Essentially the word window should be the size of a popup box. When I run the VBA, I am only sometimes taken to the word document. The rest of the time the Word Icon just shows up on my windows menu bar and flashes. My VBA in Word does absolutely nothing. I have displayed my Word and Excel VBA below.

My VBA in Excel

Private Sub CommandButton3_Click()
Set wordapp = CreateObject("word.Application")
wordapp.documents.Open "C:\Users\rossy\OneDrive\Work In Progress\Payroll and Billing
Spreadsheet\Newest 148\Code\1.docx"
wordapp.Visible = True
wordapp.Application.Activate
End Sub

My VBA In Word

Private Sub Document_Open()
With Application
.WindowState = wdWindowStateNormal
.Resize Width:=InchesToPoints(5), Height:=InchesToPoints(5)
End With
End Sub

Body:
If all you want to do is to resize the Word window, I would get rid of the vba code in your Word document, and add it to Excel vba code as follows:

Private Sub CommandButton3_Click()
    Set wordapp = CreateObject("word.Application")

    On Error GoTo OpenedErr

    Set doc = wordapp.documents.Open("C:\Users\rossy\OneDrive\Work In Progress\Payroll and Billing Spreadsheet\Newest 148\Code\1.docx")

    wordapp.Application.WindowState = wdWindowStateNormal
    wordapp.Application.Resize Width:=400, Height:=400

    wordapp.Visible = True
    wordapp.Application.Activate

OpenedErr:
    ' Don´t forget to clean memory once done
    Set doc = Nothing
    Set wordapp = Nothing
End Sub

Please try this and see if it opens correctly without flashing (In my PC it opens the Word app and activates it, I couldn´t reproduce the flashing behavior you mentioned).

If this solves your problem, please mark this as an answer.


问:
Run scheduled task inside Pod in Kubernetes
I have a small instance of influxdb running in my kubernetes cluster.

The data of that instance is stored in a persistent storage.

But I also want to run the backup command from influx at scheduled interval.

```<code>influxd backup -portable /backuppath
</code>```

What I do now is exec into the pod and run it manually.

Is there a way that I can do this automatically?

答: You can either run it as a cronjob and setup the image to be able to connect to the DB, or you can sidecar it alongside your db pod, and set it to run the cron image (i.e. will run as a mostly-idle container in the same pod as your DB)

Body:
I have a small instance of influxdb running in my kubernetes cluster.

The data of that instance is stored in a persistent storage.

But I also want to run the backup command from influx at scheduled interval.

influxd backup -portable /backuppath

What I do now is exec into the pod and run it manually.

Is there a way that I can do this automatically?


问:
How to filter results with sed using today's date
I'm asking because I can't find how to correctly use the sed function with the date function.

Context: I am concatenating log files into one with the cat function. So far so good.
The date formats in the concatenated file might be: Feb 6, or 2022-02-07.
I would like with the sed -i function to keep only the lines of the current date.
I tried using the date function in the sed function:

sed -i '/^$(date +%b)d/;/$(date +%d)/d' XYZ.log

sed -i '/"$(date +%b)"/ from XYZ.log

I tried to use a variable in the sed function:

MONTH=$(date '+%b')

sed -i '/^"$MONTH"/ !d' XYZ.log

Both don't work.

Request: How to use the date function with the sed function in order to have in the XYZ.log file only the logs of the day?

答:
The sed command is used to change text input; if you want to filter text you typically use the grep command, for instance like this:

```<code>grep "^$(date +%Y-%m-%d)" XYZ.log
</code>```

Body:
The sed command is used to change text input; if you want to filter text you typically use the grep command, for instance like this:

grep "^$(date +%Y-%m-%d)" XYZ.log


问:
Is there a way of displaying my data on Vue Component?
I'm working on a project which i need to fetch "clients" data on a table.
The data actually comes, but i can't manage to display it. Here's my template part, where i call for info with a v-for.

```<code><tbody>
 <tr v-for="item in clients" v-bind:key="item.id">
            <td>{{ item.id }}</td>
            <td>{{ item.name }}</td>
            <td>{{ item.email }}</td>
            <td>{{ item.documents.cpf || item.documents.cnpj }}</td>
            <td>{{ item.documents.celular }}</td>
            <td>{{ item.status }}</td>
            <td v-if="item.address">
              {{ `${item.address.localidade} / ${item.address.uf}` }}
            </td>
            <td v-else>-</td>

            <td>
              <a :href="`/ver-cliente/${item.id}`"
                ></a>
            </td>
</tr>
</tbody>
</code>```

On my DevTools, the data is shown:

Full DevTools with all errors (some of them are from other pages)

My script part:

```<code>export default {
  data: () => ({
    clients: [],
    paginationData: {
      lastPage: 0,
      currentPage: 1,
    },
    loading: false,
  }),

  methods: {
    getClients(page = 1) {
      this.loading = true;
      this.$api
        .get("/api_v1/clientes", {
          params: { page },
        })
        .then(({ data }) => {
          console.log(data);
          if (data.success) {
            const {
              data: result,
              per_page,
              total,
              last_page,
              current_page,
            } = data.data;
            this.clients = result;
            this.paginationData = {
              perPage: per_page,
              total,
              lastPage: last_page,
              currentPage: current_page,
            };
          }
        })
        .finally(() => (this.loading = false));
    },
  },

  mounted() {
    this.getClients();
  },
};
</code>```

That' what i managed to do, but it isn't working.
Can anyone give me a hint of what am I doing wrong? Sorry for any rookie mistakes.

答:
It can't find the property cnjp in the item.documents object, so it throws an error. To get rid of that error you can do
item.documents?.cnpj so if the property is not in the object, if will be null instead of throwing an error.

Body:
I'm working on a project which i need to fetch "clients" data on a table.
The data actually comes, but i can't manage to display it. Here's my template part, where i call for info with a v-for.

            {{ item.id }}
            {{ item.name }}
            {{ item.email }}
            {{ item.documents.cpf || item.documents.cnpj }}
            {{ item.documents.celular }}
            {{ item.status }}

              {{ `${item.address.localidade} / ${item.address.uf}` }}

            -

              <a :href="`/ver-cliente/${item.id}`"
                >

On my DevTools, the data is shown:

Full DevTools with all errors (some of them are from other pages)

My script part:

export default {
  data: () => ({
    clients: [],
    paginationData: {
      lastPage: 0,
      currentPage: 1,
    },
    loading: false,
  }),

  methods: {
    getClients(page = 1) {
      this.loading = true;
      this.$api
        .get("/api_v1/clientes", {
          params: { page },
        })
        .then(({ data }) => {
          console.log(data);
          if (data.success) {
            const {
              data: result,
              per_page,
              total,
              last_page,
              current_page,
            } = data.data;
            this.clients = result;
            this.paginationData = {
              perPage: per_page,
              total,
              lastPage: last_page,
              currentPage: current_page,
            };
          }
        })
        .finally(() => (this.loading = false));
    },
  },

  mounted() {
    this.getClients();
  },
};

That' what i managed to do, but it isn't working.
Can anyone give me a hint of what am I doing wrong? Sorry for any rookie mistakes.


问:
Memory allocation in c problem
I'm nearing the end of an introductory book on c programming called "C programming in easy steps" by Mike McGrath. I think I'll have a lot more to learn after this book by the looks of things though. Anyways, I'm working with memory allocation and I wrote this demo program, but it errors closed when I try to run it:

```<code>#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i, *arr;

    arr = calloc(5, sizeof(int));
    if(arr!=NULL)
    {
        printf("Enter 5 integers, seperated by a space:");
        for(i=0; i<5; i++) scanf("%d", &arr[i]);
        printf("Adding more space...\n");
        arr = realloc(8, sizeof(int));
        printf("Enter 3 more integers seperated by a space:");
        for(i=5; i<8; i++) scanf("%d", &arr[i]);
        printf("Thanks.\nYour 8 entries were: ");
        for(i=0; i<8; i++) printf("%d, ", arr[i]);
        printf("\n");
        free(arr);
        return 0;
        }
    else {printf("!!! INSUFFICIENT MEMORY !!!\n"); return 1; }
}
</code>```

Warning message:

```<code>|13|warning: passing argument 1 of 'realloc' makes pointer from integer without a cast|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\stdlib.h|365|note: expected 'void *' but argument is of type 'int'|
||=== Build finished: 0 errors, 1 warnings ===|
</code>```

The resulting compilation asks for 5 integers and prints "Adding more space..." at which point the program terminates, instead of asking for the additional three integers and printing the input.

Any help would be nice. :) Thanks!

答:
You're not using realloc the way you should:

```<code>/* 8 is not valid here. You need to pass the previous pointer. */
arr = realloc(8, sizeof(int));
</code>```

Try:

```<code>tmp = realloc(arr, 8 * sizeof(*arr));
if (NULL != tmp)
    arr = tmp;
</code>```

As an aside, your program looks really crammed which makes it hard to read. Maybe leave an empty line once in a while ?

Title: Memory allocation in c problem

Body:
I'm nearing the end of an introductory book on c programming called "C programming in easy steps" by Mike McGrath. I think I'll have a lot more to learn after this book by the looks of things though. Anyways, I'm working with memory allocation and I wrote this demo program, but it errors closed when I try to run it:

#include <stdio.h>
#include <stdlib.h>
int main()
{
    int i, *arr;

    arr = calloc(5, sizeof(int));
    if(arr!=NULL)
    {
        printf("Enter 5 integers, seperated by a space:");
        for(i=0; i<5; i++) scanf("%d", &arr[i]);
        printf("Adding more space...\n");
        arr = realloc(8, sizeof(int));
        printf("Enter 3 more integers seperated by a space:");
        for(i=5; i<8; i++) scanf("%d", &arr[i]);
        printf("Thanks.\nYour 8 entries were: ");
        for(i=0; i<8; i++) printf("%d, ", arr[i]);
        printf("\n");
        free(arr);
        return 0;
        }
    else {printf("!!! INSUFFICIENT MEMORY !!!\n"); return 1; }
}

Warning message:

|13|warning: passing argument 1 of 'realloc' makes pointer from integer without a cast|
c:\program files\codeblocks\mingw\bin\..\lib\gcc\mingw32\4.4.1\..\..\..\..\include\stdlib.h|365|note: expected 'void *' but argument is of type 'int'|
||=== Build finished: 0 errors, 1 warnings ===|

The resulting compilation asks for 5 integers and prints "Adding more space..." at which point the program terminates, instead of asking for the additional three integers and printing the input.

Any help would be nice. :) Thanks!

Body:
You're not using realloc the way you should:

/* 8 is not valid here. You need to pass the previous pointer. */
arr = realloc(8, sizeof(int));

Try:

tmp = realloc(arr, 8 * sizeof(*arr));
if (NULL != tmp)
    arr = tmp;

As an aside, your program looks really crammed which makes it hard to read. Maybe leave an empty line once in a while ?


问:
JOOQ Record toString print a summary instead of ASCII table?
Using JOOQ version 3.13.4

I don't like the ASCII table formatting that the Record.toString() method does.

It's particularly unhelpful in the IDEA debugger view:

But I also don't like dumping needless multi-line strings into my prod logs - which I usually avoid doing; partially for obvious speed/size reasons, but also because they're ugly and hard to read in most log viewer apps (CloudWatch etc.)

I found the Github issue that implemented the ASCII table: https://github.com/jOOQ/jOOQ/issues/1806

I know I can write code to customise this, but I'm wondering if there's a simple flag/config I'm missing to get a simple summary (if I ever got around to writing my own, I'll use JSON)?

答:
The current formatted ASCII table is quite useful for most debugging purposes, which include simple println() calls, Eclipse's debugging view (see below), etc. This includes showing only the first 5 records in a Result for a quick overview, and Record classes work the same.

The feedback from the community has generally been good for these defaults, but if you want to challenge them, try your luck here, and see if your feature request gets community upvotes: https://github.com/jOOQ/jOOQ/issues/new/choose

Eclipse's variable view:

As you can see, with the detail view, it's much less of a problem in Eclipse. I've always found it surprising IntelliJ didn't copy this very useful feature from Eclipse. Maybe, request it?

I know I can write code to customise this

I'll document it here nonetheless, as future visitors will no doubt find this useful.

IntelliJ has a lot of "smartness" in its debugger's variables view, sometimes a bit excessive. For example, an org.jooq.Result just displays its size(), because a Result is a List. I guess it's smart to hedge against excessive efforts if JDK lists are too long, though jOOQ results can handle it, and otherwise it would be possible to display list.subList(0, Math.min(list.size(), 5)) + "...".

Luckily, you can easily specify your own type renderers in IntelliJ, for example this one:

It uses this code to render a jOOQ Record:

formatJSON(new JSONFormat()
    .header(false)
    .recordFormat(JSONFormat.RecordFormat.OBJECT)
)
```

The output might look like this:

You might even suggest this as a default to IntelliJ?

but I'm wondering if there's a simple flag/config I'm missing to get a simple summary (if I ever got around to writing my own, I'll use JSON)?

No, there isn't, and I doubt that kind of configurability is reasonable. People will start requesting 100s of flags to get their preferred way of debugging, when in fact, this can be very easily achieved in the IDE as shown above.

Again, you can try your luck with a change request to change it for everyone, but a configuration for this is unlikely to be implemented.

Body:
The current formatted ASCII table is quite useful for most debugging purposes, which include simple println() calls, Eclipse's debugging view (see below), etc. This includes showing only the first 5 records in a Result for a quick overview, and Record classes work the same.

The feedback from the community has generally been good for these defaults, but if you want to challenge them, try your luck here, and see if your feature request gets community upvotes: https://github.com/jOOQ/jOOQ/issues/new/choose

Eclipse's variable view:

As you can see, with the detail view, it's much less of a problem in Eclipse. I've always found it surprising IntelliJ didn't copy this very useful feature from Eclipse. Maybe, request it?

I know I can write code to customise this

I'll document it here nonetheless, as future visitors will no doubt find this useful.

IntelliJ has a lot of "smartness" in its debugger's variables view, sometimes a bit excessive. For example, an org.jooq.Result just displays its size(), because a Result is a List. I guess it's smart to hedge against excessive efforts if JDK lists are too long, though jOOQ results can handle it, and otherwise it would be possible to display list.subList(0, Math.min(list.size(), 5)) + "...".

Luckily, you can easily specify your own type renderers in IntelliJ, for example this one:

It uses this code to render a jOOQ Record:

formatJSON(new JSONFormat()
    .header(false)
    .recordFormat(JSONFormat.RecordFormat.OBJECT)
)

The output might look like this:

You might even suggest this as a default to IntelliJ?

but I'm wondering if there's a simple flag/config I'm missing to get a simple summary (if I ever got around to writing my own, I'll use JSON)?

No, there isn't, and I doubt that kind of configurability is reasonable. People will start requesting 100s of flags to get their preferred way of debugging, when in fact, this can be very easily achieved in the IDE as shown above.

Again, you can try your luck with a change request to change it for everyone, but a configuration for this is unlikely to be implemented.


问:
gwt - celltable - adding extra row
enter code hereI have a celltable and the columns contains some numbers. I want to add an extra row at the end of the table which will hold the total for each column. Is there any way to do this?

Following is my code:

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

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.view.client.ListDataProvider;

public class TestProject implements EntryPoint
{

 private static int totalSalary=0;
 private static class Contact
 {
        private final String salary;
        private final String name;

        public Contact(String name, String salary)
        {
          this.name = name;
          this.salary = salary;
        }
 }

private static List<Contact> CONTACTS = Arrays.asList(new Contact("John","100000"),
                                                      new Contact("Mary", "200000"),
                                                      new Contact("Zander", "300000"));
/**
 * This is the entry point method.
 */
public void onModuleLoad()
{
    final CellTable<Contact> table = new CellTable<Contact>();

    // Create name column.
    TextColumn<Contact> nameColumn = new TextColumn<Contact>()
    {
      @Override
      public String getValue(Contact contact)
      {
        return contact.name;
      }
    };

    // Create address column.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>()
    {
      @Override
      public String getValue(Contact contact)
      {
        totalSalary+=Integer.parseInt(contact.salary);
        return contact.salary;
      }
    };

    // Add the columns.
    table.addColumn(nameColumn, "Name");
    table.addColumn(addressColumn, "Salary");

    // Create a data provider.
    ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);

    // Add the data to the data provider, which automatically pushes it to the
    // widget.
    final List<Contact> list = dataProvider.getList();
    for (Contact contact : CONTACTS) {
      list.add(contact);
    }

    // We know that the data is sorted alphabetically by default.
    table.getColumnSortList().push(nameColumn);

    Contact total = new Contact("Total: ",totalSalary+"");
    list.add(total);

    // Add it to the root panel.
    RootPanel.get().add(table);
    //RootPanel.get().add(add);
}
</code>```

}

答:
When you mean totals im not quite sure what you mean but this is similiar to your code but I have added a button that will add the row you howeve can take this out and just add the row.

```<code>/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TestGwt implements EntryPoint {

     private static class Contact {
            private final String address;
            private final String name;

            public Contact(String name, String address) {
              this.name = name;
              this.address = address;
            }
          }

    private static List<Contact> CONTACTS = Arrays.asList(new Contact("John",
    "123 Fourth Road"), new Contact("Mary", "222 Lancer Lane"), new Contact(
    "Zander", "94 Road Street"));
    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
         // Create a CellTable.
        final CellTable<Contact> table = new CellTable<Contact>();

        // Create name column.
        TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
          @Override
          public String getValue(Contact contact) {
            return contact.name;
          }
        };

        // Make the name column sortable.
        nameColumn.setSortable(true);

        // Create address column.
        TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
          @Override
          public String getValue(Contact contact) {
            return contact.address;
          }
        };

        // Add the columns.
        table.addColumn(nameColumn, "Name");
        table.addColumn(addressColumn, "Address");

        // Create a data provider.
        ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

        // Connect the table to the data provider.
        dataProvider.addDataDisplay(table);

        // Add the data to the data provider, which automatically pushes it to the
        // widget.
        final List<Contact> list = dataProvider.getList();
        for (Contact contact : CONTACTS) {
          list.add(contact);
        }

        // We know that the data is sorted alphabetically by default.
        table.getColumnSortList().push(nameColumn);

        Button add = new Button("Add Row");
        add.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                list.add(new Contact(Integer.toString(table.getRowCount()),Integer.toString(table.getRowCount())));
            }
        });

        // Add it to the root panel.
        RootPanel.get().add(table);
        RootPanel.get().add(add);

      }

}
</code>```

Hopefully this will help I am not sure what you mean by total though anything can be added to that final field in the Guise of a contact even though it isnt neccessarily one , the better approach would be to use Generics for the data provider but this will achieve same effects with minimal code

Title: gwt - celltable - adding extra row

Body:
enter code hereI have a celltable and the columns contains some numbers. I want to add an extra row at the end of the table which will hold the total for each column. Is there any way to do this?

Following is my code:

   import java.util.*;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.cellview.client.CellTable;
import com.google.gwt.user.cellview.client.TextColumn;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.view.client.ListDataProvider;

public class TestProject implements EntryPoint
{

 private static int totalSalary=0;
 private static class Contact
 {
        private final String salary;
        private final String name;

        public Contact(String name, String salary)
        {
          this.name = name;
          this.salary = salary;
        }
 }

private static List<Contact> CONTACTS = Arrays.asList(new Contact("John","100000"),
                                                      new Contact("Mary", "200000"),
                                                      new Contact("Zander", "300000"));
/**
 * This is the entry point method.
 */
public void onModuleLoad()
{
    final CellTable<Contact> table = new CellTable<Contact>();

    // Create name column.
    TextColumn<Contact> nameColumn = new TextColumn<Contact>()
    {
      @Override
      public String getValue(Contact contact)
      {
        return contact.name;
      }
    };

    // Create address column.
    TextColumn<Contact> addressColumn = new TextColumn<Contact>()
    {
      @Override
      public String getValue(Contact contact)
      {
        totalSalary+=Integer.parseInt(contact.salary);
        return contact.salary;
      }
    };

    // Add the columns.
    table.addColumn(nameColumn, "Name");
    table.addColumn(addressColumn, "Salary");

    // Create a data provider.
    ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

    // Connect the table to the data provider.
    dataProvider.addDataDisplay(table);

    // Add the data to the data provider, which automatically pushes it to the
    // widget.
    final List<Contact> list = dataProvider.getList();
    for (Contact contact : CONTACTS) {
      list.add(contact);
    }

    // We know that the data is sorted alphabetically by default.
    table.getColumnSortList().push(nameColumn);

    Contact total = new Contact("Total: ",totalSalary+"");
    list.add(total);

    // Add it to the root panel.
    RootPanel.get().add(table);
    //RootPanel.get().add(add);
}

}

Body:
When you mean totals im not quite sure what you mean but this is similiar to your code but I have added a button that will add the row you howeve can take this out and just add the row.

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TestGwt implements EntryPoint {

     private static class Contact {
            private final String address;
            private final String name;

            public Contact(String name, String address) {
              this.name = name;
              this.address = address;
            }
          }

    private static List<Contact> CONTACTS = Arrays.asList(new Contact("John",
    "123 Fourth Road"), new Contact("Mary", "222 Lancer Lane"), new Contact(
    "Zander", "94 Road Street"));
    /**
     * This is the entry point method.
     */
    public void onModuleLoad() {
         // Create a CellTable.
        final CellTable<Contact> table = new CellTable<Contact>();

        // Create name column.
        TextColumn<Contact> nameColumn = new TextColumn<Contact>() {
          @Override
          public String getValue(Contact contact) {
            return contact.name;
          }
        };

        // Make the name column sortable.
        nameColumn.setSortable(true);

        // Create address column.
        TextColumn<Contact> addressColumn = new TextColumn<Contact>() {
          @Override
          public String getValue(Contact contact) {
            return contact.address;
          }
        };

        // Add the columns.
        table.addColumn(nameColumn, "Name");
        table.addColumn(addressColumn, "Address");

        // Create a data provider.
        ListDataProvider<Contact> dataProvider = new ListDataProvider<Contact>();

        // Connect the table to the data provider.
        dataProvider.addDataDisplay(table);

        // Add the data to the data provider, which automatically pushes it to the
        // widget.
        final List<Contact> list = dataProvider.getList();
        for (Contact contact : CONTACTS) {
          list.add(contact);
        }

        // We know that the data is sorted alphabetically by default.
        table.getColumnSortList().push(nameColumn);

        Button add = new Button("Add Row");
        add.addClickHandler(new ClickHandler() {

            @Override
            public void onClick(ClickEvent event) {
                list.add(new Contact(Integer.toString(table.getRowCount()),Integer.toString(table.getRowCount())));
            }
        });

        // Add it to the root panel.
        RootPanel.get().add(table);
        RootPanel.get().add(add);

      }

}

Hopefully this will help I am not sure what you mean by total though anything can be added to that final field in the Guise of a contact even though it isnt neccessarily one , the better approach would be to use Generics for the data provider but this will achieve same effects with minimal code


问:
Displaying loading icon if a value is not available in Angular JS
I have a page in AngularJS where I am showing some data inside a variable. Now, this data often takes sometime to load, so I want that if variable is empty, I show a spinner, otherwise if variable has some value, I show the value in variable. Can I do it directly in the div tag?

For example:

```<code>  <div [hidden]="reviewable && !suggestionIsRejected" class="oppia-suggestion-review-message">
    <strong>Review message: </strong>{{ reviewMessage }}
  </div>
</code>```

How can I Add a condition on this variable reviewMessage?

答:
Add two div tags using ng-show or ng-if

Or you can use condition inside string interpolation

Body:
I have a page in AngularJS where I am showing some data inside a variable. Now, this data often takes sometime to load, so I want that if variable is empty, I show a spinner, otherwise if variable has some value, I show the value in variable. Can I do it directly in the div tag?

For example:

    Review message: {{ reviewMessage }}

How can I Add a condition on this variable reviewMessage?


问:
wso2 access token validation API call from POSTMAN fails
I found that we can make this call

curl -k -u admin:admin -H 'Content-Type: application/x-www-form-urlencoded' -X POST --data 'token=fbc4e794-23db-3394-b1e5-f2c3e511d01f' https://localhost:9443/oauth2/introspect

to check the validity of an access token

This works perfectly as a curl command, but when i import this into postman and make calls,it fails

it doesnt work from nodejs code also

```<code>var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
  'token': 'ff744c77-53a6-46f2-ae4c-1da72cab52ab'
});
var config = {
  method: 'post',
  url: 'https://localhost:9443/oauth2/introspect',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': 'Basic YWRtaW46YWRtaW4='
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});
</code>```

答:
Can you try importing the following curl to postman</p>
```<code>curl --location --request POST 'https://localhost:9443/oauth2/introspect' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'token=ff744c77-53a6-46f2-ae4c-1da72cab52ab'
</code>```

Body:
I found that we can make this call

curl -k -u admin:admin -H 'Content-Type: application/x-www-form-urlencoded' -X POST --data 'token=fbc4e794-23db-3394-b1e5-f2c3e511d01f' https://localhost:9443/oauth2/introspect

to check the validity of an access token

This works perfectly as a curl command, but when i import this into postman and make calls,it fails

it doesnt work from nodejs code also

var axios = require('axios');
var qs = require('qs');
var data = qs.stringify({
  'token': 'ff744c77-53a6-46f2-ae4c-1da72cab52ab'
});
var config = {
  method: 'post',
  url: 'https://localhost:9443/oauth2/introspect',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Authorization': 'Basic YWRtaW46YWRtaW4='
  },
  data : data
};

axios(config)
.then(function (response) {
  console.log(JSON.stringify(response.data));
})
.catch(function (error) {
  console.log(error);
});

Body:
Can you try importing the following curl to postman

curl --location --request POST 'https://localhost:9443/oauth2/introspect' \
--header 'Authorization: Basic YWRtaW46YWRtaW4=' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'token=ff744c77-53a6-46f2-ae4c-1da72cab52ab'


问:
Pods stuck in Terminating status
I tried to delete a ReplicationController with 12 pods and I could see that some of the pods are stuck in Terminating status.

My Kubernetes cluster consists of one control plane node and three worker nodes installed on Ubuntu virtual machines.

What could be the reason for this issue?

```<code>NAME        READY     STATUS        RESTARTS   AGE
pod-186o2   1/1       Terminating   0          2h
pod-4b6qc   1/1       Terminating   0          2h
pod-8xl86   1/1       Terminating   0          1h
pod-d6htc   1/1       Terminating   0          1h
pod-vlzov   1/1       Terminating   0          1h
</code>```

答:
I had to same issue in a production Kubernetes cluster.

A pod was stuck in Terminating phase for a while:

```<code>pod-issuing   mypod-issuing-0   1/1     Terminating   0  27h
</code>```

I tried checking the logs and events using the command:

```<code>kubectl describe pod mypod-issuing-0 --namespace pod-issuing
kubectl logs mypod-issuing-0 --namespace pod-issuing
</code>```

but none was available to view

How I fixed it:

I ran the command below to forcefully delete the pod:

```<code>kubectl delete pod <PODNAME> --grace-period=0 --force --namespace <NAMESPACE>
</code>```

This deleted the pod immediately and started creating a new one. However, I ran into the error below when another pod was being created:

Unable to attach or mount volumes: unmounted volumes=[data], unattached volumes=[data mypod-issuing-token-5swgg aws-iam-token]: timed out waiting for the condition

I had to wait for 7 to 10 minutes for the volume to become detached from the previous pod I deleted so that it can become available for this new pod I was creating.

Title: Pods stuck in Terminating status

Body:
I tried to delete a ReplicationController with 12 pods and I could see that some of the pods are stuck in Terminating status.

My Kubernetes cluster consists of one control plane node and three worker nodes installed on Ubuntu virtual machines.

What could be the reason for this issue?

NAME        READY     STATUS        RESTARTS   AGE
pod-186o2   1/1       Terminating   0          2h
pod-4b6qc   1/1       Terminating   0          2h
pod-8xl86   1/1       Terminating   0          1h
pod-d6htc   1/1       Terminating   0          1h
pod-vlzov   1/1       Terminating   0          1h

Body:
I had to same issue in a production Kubernetes cluster.

A pod was stuck in Terminating phase for a while:

pod-issuing   mypod-issuing-0   1/1     Terminating   0  27h

I tried checking the logs and events using the command:

kubectl describe pod mypod-issuing-0 --namespace pod-issuing
kubectl logs mypod-issuing-0 --namespace pod-issuing

but none was available to view

How I fixed it:

I ran the command below to forcefully delete the pod:

kubectl delete pod <PODNAME> --grace-period=0 --force --namespace <NAMESPACE>

This deleted the pod immediately and started creating a new one. However, I ran into the error below when another pod was being created:

Unable to attach or mount volumes: unmounted volumes=[data], unattached volumes=[data mypod-issuing-token-5swgg aws-iam-token]: timed out waiting for the condition

I had to wait for 7 to 10 minutes for the volume to become detached from the previous pod I deleted so that it can become available for this new pod I was creating.


问:
In App Purchase seems to be called multiple times
I implemented an In-App Purchase with the Play Billing Library 1.0 according to Google's tutorial.
I have only 1 item for purchase and when it gets unlocked, I show a Toast message with the length Toast.LENGTH_SHORT. However, the Toast stays there for like 10 seconds, so I assume it gets called multiple times. It does NOT happen when I unlock it via queryPurchases (if someone bought it earlier and reinstalled the app in the meantime).

Anyone have an idea why the Toast stays so long / why it gets called multiple times?

Inside my BillingManager class:

```<code>@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
    if (responseCode == BillingClient.BillingResponse.OK) {
        for (Purchase purchase : purchases) {
            handlePurchases(purchase);
        }
        mBillingUpdatesListener.onPurchasesUpdated(mPurchases);
    } else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {

    } else {

    }
}

public void handlePurchases(Purchase purchase) {
    //here could be validation on own server

    mPurchases.add(purchase);
}
</code>```

Main Activity implements BillingUpdatesListener:

```<code>@Override
public void onPurchasesUpdated(List<Purchase> purchases) {
    for (Purchase purchase : purchases) {
        switch (purchase.getSku()) {
            case "premium":
                unlockPremium();
                break;
        }
    }
}

public void unlockPremium() {
    mPremiumUnlocked = true;
    savePremiumUnlocked();
    Toast.makeText(this, getResources().getString(R.string.premium_congrats), Toast.LENGTH_SHORT).show();
    mAdView.setVisibility(GONE);
}
</code>```

答:
If your subscription activity was closed and reopened multiple times within the same application process, then onPurchasesUpdated may be called multiple times if the PurchasesUpdatedListener somehow stays attached to the previous instances of billingClient and if the previous connections are still alive. I noticed that the number of times I closed and reopened the subscription activity, onPurchasesUpdated was called for the same amount after a successful launchBillingFlow.

To fix this I needed to end the connection when the activity is destroying, like this -

```<code>@Override
protected void onDestroy() {
    super.onDestroy();
    if (billingClient!= null) {
        billingClient.endConnection();
    }
}
</code>```

Body:
I implemented an In-App Purchase with the Play Billing Library 1.0 according to Google's tutorial.
I have only 1 item for purchase and when it gets unlocked, I show a Toast message with the length Toast.LENGTH_SHORT. However, the Toast stays there for like 10 seconds, so I assume it gets called multiple times. It does NOT happen when I unlock it via queryPurchases (if someone bought it earlier and reinstalled the app in the meantime).

Anyone have an idea why the Toast stays so long / why it gets called multiple times?

Inside my BillingManager class:

@Override
public void onPurchasesUpdated(int responseCode, @Nullable List<Purchase> purchases) {
    if (responseCode == BillingClient.BillingResponse.OK) {
        for (Purchase purchase : purchases) {
            handlePurchases(purchase);
        }
        mBillingUpdatesListener.onPurchasesUpdated(mPurchases);
    } else if (responseCode == BillingClient.BillingResponse.USER_CANCELED) {

    } else {

    }
}

public void handlePurchases(Purchase purchase) {
    //here could be validation on own server

    mPurchases.add(purchase);
}

Main Activity implements BillingUpdatesListener:

@Override
public void onPurchasesUpdated(List<Purchase> purchases) {
    for (Purchase purchase : purchases) {
        switch (purchase.getSku()) {
            case "premium":
                unlockPremium();
                break;
        }
    }
}

public void unlockPremium() {
    mPremiumUnlocked = true;
    savePremiumUnlocked();
    Toast.makeText(this, getResources().getString(R.string.premium_congrats), Toast.LENGTH_SHORT).show();
    mAdView.setVisibility(GONE);
}

Body:
If your subscription activity was closed and reopened multiple times within the same application process, then onPurchasesUpdated may be called multiple times if the PurchasesUpdatedListener somehow stays attached to the previous instances of billingClient and if the previous connections are still alive. I noticed that the number of times I closed and reopened the subscription activity, onPurchasesUpdated was called for the same amount after a successful launchBillingFlow.

To fix this I needed to end the connection when the activity is destroying, like this -

@Override
protected void onDestroy() {
    super.onDestroy();
    if (billingClient!= null) {
        billingClient.endConnection();
    }
}