Dataset Viewer
Auto-converted to Parquet Duplicate
text
stringlengths
352
54.6k
meta
dict
Q: How can I decode this string which is represented as unicode? I get s when trying to parse a web page by readability(Python 2.7 on Windows 10, Sublime Text 2/cmd) >>> import requests >>> from readability import Document >>> >>> response = requests.get('http://www.gamersky.com/news/201806/1064930.shtml') >>> doc = Document(response.text.encode("utf-8")) >>> print doc.title() Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'gbk' codec can't encode character u'\xe3' in position 0: illegal multibyte sequence >>> print doc.title().encode("utf-8") lots of messy codes >>> print doc.title().encode("utf-16") lots of messy codes >>> print doc.title().encode("gbk") Traceback (most recent call last): File "<stdin>", line 1, in <module> UnicodeEncodeError: 'gbk' codec can't encode character u'\xe3' in position 0: illegal multibyte sequence I found I can never print out doc.title(), so I looked into doc.title() by running s = repr(doc.title()) print type(doc.title()) print s The result is very strange <type 'unicode'> u'\xe3\x80\x8a\xe5\xa5\x87\xe5\xbc\x82\xe4\xba\xba\xe7\x94\x9f\xe3\x80\x8b\xe5\x9b\xa2\xe9\x98\x9f\xe6\x96\xb0\xe4\xbd\x9c\xe3\x80\x8a\xe8\xb6 \xe8\x83\xbd\xe9\x98\x9f\xe9\x95\xbf\xe3\x80\x8b\xe5 \x8d\xe8\xb4\xb9\xe4\xb8\x8b\xe8\xbd\xbd \xe5\xb0\x8f\xe7\x94\xb7\xe5\xad\xa9\xe7\x9a\x84\xe8\x8b\xb1\xe9\x9b\x84\xe6\xa2\xa6\xe6\x83\xb3 _ \xe6\xb8\xb8\xe6\xb0\x91\xe6\x98\x9f\xe7\xa9\xba GamerSky.com' It seem that s is actually encoded in multibytes, because when I run print '\xe3\x80...' And it prints 《奇异人生》团队新作《? 能队长》? ?费下载 小男孩的英雄梦想 _ 游民星空 GamerSky.com Where the accurate title is 《奇异人生》团队新作《超能队长》免费下载 小男孩的英雄梦想 _ 游民星空 GamerSky.com Though there are some characters still missing, but the result convince me that the \xe3 should not be represented as a unicode form. After some searching, I found the following code helps, but there are still some missing characters. >>> print s.encode("raw_unicode_escape") 《奇异人生》团队新作《? 能队长》? ?费下载 小男孩的英雄梦想 _ 游民星空 GamerSky.com My questions are: Why is this problem probably happen? Is the encode("raw_unicode_escape") solution neat? When I run the following codes, it works >>> import requests >>> from readability import Document >>> >>> response = requests.get('https://zh.wikipedia.org/wiki/Wikipedia:%E9%A6%96%E9%A1%B5') >>> doc = Document(response.text.encode("utf-8")) >>> print doc.title() 维基百科,自由的百科全书 How to handle the missing characters? A: The problem is that when you use response.text, it makes a guess at what the encoding is when decoding response.content into unicode. In this case its guess is incorrect. You have to force the encoding by setting response.encoding to 'utf-8', per documentation. import requests from readability import Document response = requests.get('http://www.gamersky.com/news/201806/1064930.shtml') response.encoding = 'utf-8' doc = Document(response.text) print doc.title() And this prints: 《奇异人生》团队新作《超能队长》免费下载 小男孩的英雄梦想 _ 游民星空 GamerSky.com
{ "pile_set_name": "StackExchange" }
Q: Transform a 9x9 Matrix so that each row is a 3x3 Block I have the following example data: [0] = {01,02,03, 04,05,06, 07,08,09} [1] = {11,12,13, 14,15,16, 17,18,19} [2] = {21,22,23, 24,25,26, 27,28,29} [3] = {31,32,33, 34,35,36, 37,38,39} [4] = {41,42,43, 44,45,46, 47,48,49} [5] = {51,52,53, 54,55,56, 57,58,59} [6] = {61,62,63, 64,65,66, 67,68,69} [7] = {71,72,73, 74,75,76, 77,78,79} [8] = {81,82,83, 84,85,86, 87,88,89} To create the new matrix I did this, Knowing it static 9x9 var grid2=[[],[]]; grid2.push([grid[0][0],grid[0][1], grid[0][2],grid[1][0],grid[1][1], grid[1][2],grid[2][0],grid[2][1], grid[2][2]]); grid2.push([grid[3][0],grid[3][1], grid[3][2],grid[4][0],grid[4][1], grid[4][2],grid[5][0],grid[5][1], grid[5][2]]); grid2.push([grid[6][0],grid[6][1], grid[6][2],grid[7][0],grid[7][1], grid[7][2],grid[8][0],grid[8][1], grid[8][2]]); grid2.push([grid[0][3],grid[0][4], grid[0][5],grid[1][3],grid[1][4], grid[1][5],grid[2][3],grid[2][4], grid[2][5]]); grid2.push([grid[3][3],grid[3][4], grid[3][5],grid[4][3],grid[4][4], grid[4][5],grid[5][3],grid[5][4], grid[5][5]]); grid2.push([grid[6][3],grid[6][4], grid[6][5],grid[7][3],grid[7][4], grid[7][5],grid[8][3],grid[8][4], grid[8][5]]); grid2.push([grid[0][6],grid[0][7], grid[0][8],grid[1][6],grid[1][7], grid[1][8],grid[2][6],grid[2][7], grid[2][8]]); grid2.push([grid[3][6],grid[3][7], grid[3][8],grid[4][6],grid[4][7], grid[4][8],grid[5][6],grid[5][7], grid[5][8]]); grid2.push([grid[6][6],grid[6][7], grid[6][8],grid[7][6],grid[7][7], grid[7][8],grid[2][6],grid[8][7], grid[8][8]]); This works, but my question is, can this be done more efficiently / elegantly. The point of this, is part of a larger code base, that takes the matrix and validates if it is a Sudoku solution. A: You can use a simple algorithm for this let idx = [0, 1, 2], idy = [0, 1, 2]; let result = []; for(let i=0; i<9; i+=3){ for(let j=0; j<9; j+=3){ idx.forEach(e => { idy.forEach(f => { result.push(arr[i+e][j+f]); }) }) } }
{ "pile_set_name": "StackExchange" }
Q: url param not getting properly I have a two server.I am passing 4 variable in url ssid(36),rawstring(1024),sample_id,user_id. I simplely want to get parameter passed in url.When I hit my first server I am getting param,but same url(Only change server name),I get 3 parameters(not getting raw string). In my controller I am testing like this echo "<pre>"; print_r($_REQUEST); echo "</pre>"; echo $_REQUEST['rawstring'];die(); this is my desired output Array ( [ssid] => d41d8cd98f00b204e9800998ecf8427e [rawstring] => 303330363036422031333235353030323039ffffffffffffffffffffffffffff33333030302041202046542031333238203030303030323831ffffffffffffff31362f30372f323031332d2d313035343031ffffffffffffffffffffffffffff0ba504d203430aeeffffffffffffffff00db00db02ca00db02caffffffffffff00000000ffffffffffffffffffffffffbe51ffffffffffffffffffffffffffff8000ffffffffffffffffffffffffffff00ec856cffffffffffffffffffffffff2ea495a82eaa959dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff30303031303030350000000900000bbf0013ac9e0013aca300003504fffffffb06b706ae06aa06a2069c06990690068e0000086a00000ad80013acc60013acc70013acc90013accd000034f7fffffffb06b206ae06a806a1069f0697068e068a0000086f00000ac6000000020013acd7000000000000000000000000000008c400000000000000000000000000000773ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e656e64 [readerid] => admin [sample_id] => 1111 ) But i am getting this Array ( [ssid] => d41d8cd98f00b204e9800998ecf8427e [readerid] => admin [sample_id] => 1111 ) I have gone through this.But i don't think its working for me.I have seen htaccess file also.Its fine. My url is like <server_name>/Nfc/test/fromXML?ssid=d41d8cd98f00b204e9800998ecf8427e&rawstring=303330363036422031333235353030323039ffffffffffffffffffffffffffff33333030302041202046542031333238203030303030323831ffffffffffffff31362f30372f323031332d2d313035343031ffffffffffffffffffffffffffff0ba504d203430aeeffffffffffffffff00db00db02ca00db02caffffffffffff00000000ffffffffffffffffffffffffbe51ffffffffffffffffffffffffffff8000ffffffffffffffffffffffffffff00ec856cffffffffffffffffffffffff2ea495a82eaa959dffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff30303031303030350000000900000bbf0013ac9e0013aca300003504fffffffb06b706ae06aa06a2069c06990690068e0000086a00000ad80013acc60013acc70013acc90013accd000034f7fffffffb06b206ae06a806a1069f0697068e068a0000086f00000ac6000000020013acd7000000000000000000000000000008c400000000000000000000000000000773ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff2e656e64&readerid=admin&sample_id=1111 I am using zend.Please someone help me. A: Well I found this solution if(@$_REQUEST['rawstring']=='' || !(@$_REQUEST['rawstring'])){ $str=($_SERVER['QUERY_STRING']); // print_r(parse_str($str)); $new=explode("&rawstring=",$str); $raw=explode("&readerid",$new[1]); $_REQUEST['rawstring']=$raw[0]; } Is there some better way to parse $_SERVER['QUERY_STRING']?
{ "pile_set_name": "StackExchange" }
Q: Matching data in 2 data frame in R? I have 2 data frame, one has time stamp and temperature and the other has time stamps. I wanna copy the temperature data from first data set to second one if the time stamp is identical ! I have checked this and this likns. But they are different to my question. Can someone help me on this ? Here is a sample of my data : data1 date t 1 19.11.2016 06:20 22.1 2 19.11.2016 06:30 22.4 3 19.11.2016 06:40 22.6 4 19.11.2016 06:50 22.8 5 19.11.2016 07:00 23.2 6 19.11.2016 07:10 23.3 7 19.11.2016 07:20 23.7 8 19.11.2016 07:30 23.9 9 19.11.2016 07:40 24.0 10 19.11.2016 07:50 24.4 11 19.11.2016 08:00 24.5 12 19.11.2016 08:10 24.7 13 19.11.2016 08:20 25.0 14 19.11.2016 08:30 25.3 15 19.11.2016 08:40 25.4 16 19.11.2016 08:50 25.7 17 19.11.2016 09:00 25.8 18 19.11.2016 09:10 25.9 19 19.11.2016 09:20 25.9 20 19.11.2016 09:30 26.1 21 19.11.2016 09:40 26.3 22 19.11.2016 09:50 26.4 23 19.11.2016 10:00 26.6 24 19.11.2016 10:10 26.5 25 19.11.2016 10:20 26.5 26 19.11.2016 10:30 NA 27 19.11.2016 10:40 NA 28 21.11.2016 06:30 NA 29 21.11.2016 06:40 NA 30 21.11.2016 06:50 NA 31 21.11.2016 07:00 NA 32 21.11.2016 07:10 NA 33 21.11.2016 07:20 20.9 34 21.11.2016 07:30 21.0 35 21.11.2016 07:40 21.0 36 21.11.2016 07:50 21.1 37 21.11.2016 08:00 21.2 38 21.11.2016 08:10 21.3 39 21.11.2016 08:20 21.5 40 21.11.2016 08:30 21.8 41 21.11.2016 08:40 22.1 42 21.11.2016 08:50 22.2 43 21.11.2016 09:00 22.6 44 21.11.2016 09:10 22.9 45 21.11.2016 09:20 22.7 46 21.11.2016 09:30 22.6 47 21.11.2016 09:40 22.6 48 21.11.2016 09:50 22.7 49 21.11.2016 10:00 22.8 50 21.11.2016 10:10 23.1 51 21.11.2016 10:20 23.6 data2 date 1 19.11.2016 06:20 2 19.11.2016 06:30 3 19.11.2016 06:40 4 19.11.2016 06:50 5 19.11.2016 07:00 6 19.11.2016 07:10 7 19.11.2016 07:20 8 19.11.2016 07:30 9 19.11.2016 07:40 10 19.11.2016 07:50 11 19.11.2016 08:00 12 19.11.2016 08:10 13 19.11.2016 08:20 14 19.11.2016 08:30 15 19.11.2016 08:40 16 19.11.2016 08:50 17 19.11.2016 09:00 18 19.11.2016 09:10 19 19.11.2016 09:20 20 19.11.2016 09:30 21 19.11.2016 09:40 22 19.11.2016 09:50 23 19.11.2016 10:00 24 19.11.2016 10:10 25 19.11.2016 10:20 26 21.11.2016 07:20 27 21.11.2016 07:30 28 21.11.2016 07:40 29 21.11.2016 07:50 30 21.11.2016 08:00 31 21.11.2016 08:10 32 21.11.2016 08:20 33 21.11.2016 08:30 34 21.11.2016 08:40 35 21.11.2016 08:50 36 21.11.2016 09:00 37 21.11.2016 09:10 38 21.11.2016 09:20 39 21.11.2016 09:30 40 21.11.2016 09:40 41 21.11.2016 09:50 42 21.11.2016 10:00 43 21.11.2016 10:10 44 21.11.2016 10:20 45 21.11.2016 10:30 46 21.11.2016 10:40 47 21.11.2016 10:50 48 21.11.2016 11:00 49 21.11.2016 11:10 50 21.11.2016 11:20 51 21.11.2016 11:30 A: Simple solution using base R merge: merge(data2, data1, all.x = TRUE)
{ "pile_set_name": "StackExchange" }
Q: constructing a Data Frame in Rcpp I want to construct a data frame in an Rcpp function, but when I get it, it doesn't really look like a data frame. I've tried pushing vectors etc. but it leads to the same thing. Consider: RcppExport SEXP makeDataFrame(SEXP in) { Rcpp::DataFrame dfin(in); Rcpp::DataFrame dfout; for (int i=0;i<dfin.length();i++) { dfout.push_back(dfin(i)); } return dfout; } in R: > .Call("makeDataFrame",mtcars,"myPkg") [[1]] [1] 21.0 21.0 22.8 21.4 18.7 18.1 14.3 24.4 22.8 19.2 17.8 16.4 17.3 15.2 10.4 [16] 10.4 14.7 32.4 30.4 33.9 21.5 15.5 15.2 13.3 19.2 27.3 26.0 30.4 15.8 19.7 [31] 15.0 21.4 [[2]] [1] 6 6 4 6 8 6 8 4 4 6 6 8 8 8 8 8 8 4 4 4 4 8 8 8 8 4 4 4 8 6 8 4 [[3]] [1] 160.0 160.0 108.0 258.0 360.0 225.0 360.0 146.7 140.8 167.6 167.6 275.8 [13] 275.8 275.8 472.0 460.0 440.0 78.7 75.7 71.1 120.1 318.0 304.0 350.0 [25] 400.0 79.0 120.3 95.1 351.0 145.0 301.0 121.0 [[4]] [1] 110 110 93 110 175 105 245 62 95 123 123 180 180 180 205 215 230 66 52 [20] 65 97 150 150 245 175 66 91 113 264 175 335 109 [[5]] [1] 3.90 3.90 3.85 3.08 3.15 2.76 3.21 3.69 3.92 3.92 3.92 3.07 3.07 3.07 2.93 [16] 3.00 3.23 4.08 4.93 4.22 3.70 2.76 3.15 3.73 3.08 4.08 4.43 3.77 4.22 3.62 [31] 3.54 4.11 [[6]] [1] 2.620 2.875 2.320 3.215 3.440 3.460 3.570 3.190 3.150 3.440 3.440 4.070 [13] 3.730 3.780 5.250 5.424 5.345 2.200 1.615 1.835 2.465 3.520 3.435 3.840 [25] 3.845 1.935 2.140 1.513 3.170 2.770 3.570 2.780 [[7]] [1] 16.46 17.02 18.61 19.44 17.02 20.22 15.84 20.00 22.90 18.30 18.90 17.40 [13] 17.60 18.00 17.98 17.82 17.42 19.47 18.52 19.90 20.01 16.87 17.30 15.41 [25] 17.05 18.90 16.70 16.90 14.50 15.50 14.60 18.60 [[8]] [1] 0 0 1 1 0 1 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 1 0 1 0 0 0 1 [[9]] [1] 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 [[10]] [1] 4 4 4 3 3 3 3 4 4 4 4 3 3 3 3 3 3 4 4 4 3 3 3 3 3 4 5 5 5 5 5 4 [[11]] [1] 4 4 1 1 2 1 4 2 2 4 4 3 3 3 4 4 4 1 2 1 1 2 2 4 2 1 2 2 4 6 8 2 A: Briefly: DataFrames are indeed just like lists with the added restriction of having to have a common length, so they are best constructed column by column. The best way is often to look for our unit tests. Her inst/unitTests/runit.DataFrame.R regroups tests for the DataFrame class. You also found the .push_back() member function in Rcpp which we added for convenience and analogy with the STL. We do warn that it is not recommended: due to differences with the way R objects are constructed, we essentially always need to do full copies .push_back is not very efficient. Despite me answering here frequently, the rcpp-devel list a better place for Rcpp questions. A: It seems Rcpp can return a proper data.frame, provided you supply the names explicitely. I'm not sure how to adapt this to your example with arbitrary names mkdf <- ' Rcpp::DataFrame dfin(input); Rcpp::DataFrame dfout; for (int i=0;i<dfin.length();i++) { dfout.push_back(dfin(i)); } return Rcpp::DataFrame::create( Named("x")= dfout(1), Named("y") = dfout(2)); ' library(inline) test <- cxxfunction( signature(input="data.frame"), mkdf, plugin="Rcpp") test(input=head(iris)) A: Using the information from @baptiste's answer, this is what finally does give a well formed data frame: RcppExport SEXP makeDataFrame(SEXP in) { Rcpp::DataFrame dfin(in); Rcpp::DataFrame dfout; Rcpp::CharacterVector namevec; std::string namestem = "Column Heading "; for (int i=0;i<2;i++) { dfout.push_back(dfin(i)); namevec.push_back(namestem+std::string(1,(char)(((int)'a') + i))); } dfout.attr("names") = namevec; Rcpp::DataFrame x; Rcpp::Language call("as.data.frame",dfout); x = call.eval(); return x; } I think the point remains that this might be inefficient due to push_back (as suggested by @Dirk) and the second Language call evaluation. I looked up the rcpp unitTests, and haven't been able to come up with something better yet. Anybody have any ideas? Update: Using @Dirk's suggestions (thanks!), this seems to be a simpler, efficient solution: RcppExport SEXP makeDataFrame(SEXP in) { Rcpp::DataFrame dfin(in); Rcpp::List myList(dfin.length()); Rcpp::CharacterVector namevec; std::string namestem = "Column Heading "; for (int i=0;i<dfin.length();i++) { myList[i] = dfin(i); // adding vectors namevec.push_back(namestem+std::string(1,(char)(((int)'a') + i))); // making up column names } myList.attr("names") = namevec; Rcpp::DataFrame dfout(myList); return dfout; }
{ "pile_set_name": "StackExchange" }
Q: Issue with Json file for Highstock I'm actually be doing a project in my studies and i will take json data from webservice for set it in highstock. My webservice (file in php language) return actually this json format [{"jour":"22","mois":"1","an":"10","heure":"10","minute":"0","p_ac":"143"},{"jour":"22","mois":"1","an":"10","heure":"11","minute":"0","p_ac":"827"},{"jour":"22","mois":"1","an":"10","heure":"12","minute":"0","p_ac":"965"},{"jour":"22","mois":"1","an":"10","heure":"13","minute":"0","p_ac":"1025"},{"jour":"22","mois":"1","an":"10","heure":"14","minute":"0","p_ac":"1003"},{"jour":"22","mois":"1","an":"10","heure":"15","minute":"0","p_ac":"635"},{"jour":"22","mois":"1","an":"10","heure":"16","minute":"0","p_ac":"385"},{"jour":"22","mois":"1","an":"10","heure":"17","minute":"0","p_ac":"54"},{"jour":"22","mois":"1","an":"10","heure":"18","minute":"0","p_ac":"0"},{"jour":"22","mois":"1","an":"10","heure":"19","minute":"0","p_ac":"0"},{"jour":"22","mois":"1","an":"10","heure":"20","minute":"0","p_ac":"0"},{"jour":"23","mois":"1","an":"10","heure":"9","minute":"0","p_ac":"204"},{"jour":"23","mois":"1","an":"10","heure":"10","minute":"0","p_ac":"468"},{"jour":"23","mois":"1","an":"10","heure":"11","minute":"0","p_ac":"815"},{"jour":"23","mois":"1","an":"10","heure":"12","minute":"0","p_ac":"933"},{"jour":"23","mois":"1","an":"10","heure":"13","minute":"0","p_ac":"1062"},{"jour":"23","mois":"1","an":"10","heure":"14","minute":"0","p_ac":"332"},{"jour":"23","mois":"1","an":"10","heure":"15","minute":"0","p_ac":"536"},{"jour":"23","mois":"1","an":"10","heure":"16","minute":"0","p_ac":"348"},{"jour":"23","mois":"1","an":"10","heure":"17","minute":"0","p_ac":"73"},{"jour":"23","mois":"1","an":"10","heure":"18","minute":"0","p_ac":"0"},{"jour":"23","mois":"1","an":"10","heure":"19","minute":"0","p_ac":"0"},{"jour":"23","mois":"1","an":"10","heure":"20","minute":"0","p_ac":"0"},{"jour":"23","mois":"1","an":"10","heure":"21","minute":"0","p_ac":"0"}] I need to re-format it for Highstock The correct and complete file for highstock : Here's the correct code How can i do it please ? Ps : Sorry for my bad english A: This code resolve my problem ! :)
{ "pile_set_name": "StackExchange" }
Q: convert image to byte literal in python I'm trying to store an image as text, so that I can do something like this example of a transparent icon for a Tk gui: import tempfile # byte literal code for a transparent icon, I think ICON = (b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00' b'\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00' b'\x08\x00\x00\x00\x00\x00@\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' b'\x00\x01\x00\x00\x00\x01') + b'\x00'*1282 + b'\xff'*64 # makes a temp file for the transparent icon and saves it _, ICON_PATH = tempfile.mkstemp() with open(ICON_PATH, 'wb') as icon_file: icon_file.write(ICON) I've tried base 64 encoding, decoding with utf8, converting to bytes and bytearray, and some answers from another post: (Python Script to convert Image into Byte array) import tempfile, base64, io # byte literal code for a transparent icon, I think ICON = (b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00' b'\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00' b'\x08\x00\x00\x00\x00\x00@\x05\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00' b'\x00\x01\x00\x00\x00\x01') + b'\x00'*1282 + b'\xff'*64 # makes a temp file for the transparent icon and saves it _, ICON_PATH = tempfile.mkstemp() with open(ICON_PATH, 'wb') as icon_file: icon_file.write(ICON) a = open(ICON_PATH, 'rb').read() b = base64.b64encode(a) print b # output does not match what ICON equals above # doesn't work; gives error # UnicodeDecodeError: 'utf8' codec can't decode byte 0xff in position 1342: invalid start byte # b = bytes(a).decode('utf-8') c = bytearray(a) print c # prints garbled junk # gives error AttributeError: __exit__ on Image.open(ICON_PATH) line with io.BytesIO() as output: from PIL import Image with Image.open(ICON_PATH) as img: img.convert('RGB').save(output, 'BMP') data = output.getvalue()[14:] print data It also doesn't work for b.decode('utf-8') or b.encode('utf-8') A: I think you're looking for print(repr(a)) For a as defined in your code, this will print b'\x00\x00\x01\x00\x01\x00\x10\x10\x00\x00\x01\x00\x08\x00h\x05\x00\x00\x16\x00\x00\x00(\x00\x00\x00\x10\x00\x00\x00 \x00\x00\x00\x01\x00\x08 and so on, similar to your original ICON definition, but quite large because all the \x00s and \xffs at the end are written out. In your code, you have included some ad hoc compression (namely + b'\x00'*1282 + b'\xff'*64). To get compression automatically, so the ICON definition in your source file doesn't have to be so large, leverage an existing compression library, like zlib: import zlib print(repr(zlib.compress(a))) On my machine, this prints 'x\x9cc``\x04B\x01\x01\x06 \xc9\xc1\x90\xc1\xca\xc0 \xc6\xc0\xc0\xa0\x01\xc4@!\x06\x05\x06\x888\x088\xb02 \x00#\x14\x8f\x82Q0\nF\xc1\x08\x05\xff)\x04\x00U\xf1A\x17', which is quite small. To decompress, use zlib.decompress: import zlib ICON = zlib.decompress(b'x\x9cc``\x04B\x01\x01\x06 \xc9\xc1\x90\xc1\xca\xc0 ' b'\xc6\xc0\xc0\xa0\x01\xc4@!\x06\x05\x06\x888\x088\xb02 \x00#\x14\x8f\x82' b'Q0\nF\xc1\x08\x05\xff)\x04\x00U\xf1A\x17') ICON now has the same value as in your original example. If you now want a representation that's still more compact in your source file, it is time to apply base 64 encoding, which gets rid of the verbose binary encoding in python (the \x..-format). To encode: import base64, zlib print(repr(base64.b64encode(zlib.compress(a)))) This gives me 'eJxjYGAEQgEBBiDJwZDBysAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4JRMApGwQgF/ykEAFXxQRc=' To decode: import base64, zlib ICON = zlib.decompress(base64.b64decode('eJxjYGAEQgEBBiDJwZDBy' 'sAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4JRMApGwQgF/ykEAFXxQRc=')) And again, ICON has the same value as originally specified. The final strategy as presented is good for ico files. I see that you also mention png files. These already have compression applied, so you should probably prefer to use only base 64 encoding: import base64 print(base64.b64encode(png_icon)) and PNG_ICON = base64.b64decode( ** insert literal here ** ) As it turns out, these encodings are also available through the str.encode and str.decode APIs. This lets you off without writing the imports. For completeness, here they are: Encoding: print(repr(a.encode('zlib').encode('base64'))) Decoding: ICON = ('eJxjYGAEQgEBBiDJwZDBysAgxsDAoAHEQCEGBQaIOAg4sDIgACMUj4J' 'RMApGwQgF/ykEAFXxQRc=').decode('base64').decode('zlib')
{ "pile_set_name": "StackExchange" }
Q: java script newline replacement I finished a JavaScript beginners course and tried to solve the JS challenges in hackthissite.org. in last challenge the obfuscation decryption done correctly but the for loop i executed, output letters below each other instead of beside each other. var puzzle = [0x3c, 0x62, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x20, 0x6f, 0x6e, 0x63, 0x6c, 0x69, 0x63, 0x6b, 0x3d, 0x27, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x3a, 0x69, 0x66, 0x20, 0x28, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x42, 0x79, 0x49, 0x64, 0x28, 0x22, 0x70, 0x61, 0x73, 0x73, 0x22, 0x29, 0x2e, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x3d, 0x22, 0x6a, 0x30, 0x30, 0x77, 0x31, 0x6e, 0x22, 0x29, 0x7b, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x28, 0x22, 0x59, 0x6f, 0x75, 0x20, 0x57, 0x49, 0x4e, 0x21, 0x22, 0x29, 0x3b, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x2b, 0x3d, 0x20, 0x22, 0x3f, 0x6c, 0x76, 0x6c, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3d, 0x22, 0x2b, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x42, 0x79, 0x49, 0x64, 0x28, 0x22, 0x70, 0x61, 0x73, 0x73, 0x22, 0x29, 0x2e, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x7d, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x7b, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x28, 0x22, 0x57, 0x52, 0x4f, 0x4e, 0x47, 0x21, 0x20, 0x54, 0x72, 0x79, 0x20, 0x61, 0x67, 0x61, 0x69, 0x6e, 0x21, 0x22, 0x29, 0x7d, 0x27, 0x3e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3c, 0x2f, 0x62, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x3e], i; for (i = 0; i < puzzle.length; i++) { console.log(String.fromCharCode(puzzle[i]).replace(/(\r\n|\n|\r)/gm, "")); } Any trick could solve that !! A: Instead of logging the result of each character, concatenate them to a result variable, and then output that, once: var puzzle = [0x3c, 0x62, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x20, 0x6f, 0x6e, 0x63, 0x6c, 0x69, 0x63, 0x6b, 0x3d, 0x27, 0x6a, 0x61, 0x76, 0x61, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x3a, 0x69, 0x66, 0x20, 0x28, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x42, 0x79, 0x49, 0x64, 0x28, 0x22, 0x70, 0x61, 0x73, 0x73, 0x22, 0x29, 0x2e, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3d, 0x3d, 0x22, 0x6a, 0x30, 0x30, 0x77, 0x31, 0x6e, 0x22, 0x29, 0x7b, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x28, 0x22, 0x59, 0x6f, 0x75, 0x20, 0x57, 0x49, 0x4e, 0x21, 0x22, 0x29, 0x3b, 0x77, 0x69, 0x6e, 0x64, 0x6f, 0x77, 0x2e, 0x6c, 0x6f, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x2b, 0x3d, 0x20, 0x22, 0x3f, 0x6c, 0x76, 0x6c, 0x5f, 0x70, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3d, 0x22, 0x2b, 0x64, 0x6f, 0x63, 0x75, 0x6d, 0x65, 0x6e, 0x74, 0x2e, 0x67, 0x65, 0x74, 0x45, 0x6c, 0x65, 0x6d, 0x65, 0x6e, 0x74, 0x42, 0x79, 0x49, 0x64, 0x28, 0x22, 0x70, 0x61, 0x73, 0x73, 0x22, 0x29, 0x2e, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x7d, 0x65, 0x6c, 0x73, 0x65, 0x20, 0x7b, 0x61, 0x6c, 0x65, 0x72, 0x74, 0x28, 0x22, 0x57, 0x52, 0x4f, 0x4e, 0x47, 0x21, 0x20, 0x54, 0x72, 0x79, 0x20, 0x61, 0x67, 0x61, 0x69, 0x6e, 0x21, 0x22, 0x29, 0x7d, 0x27, 0x3e, 0x43, 0x68, 0x65, 0x63, 0x6b, 0x20, 0x50, 0x61, 0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x3c, 0x2f, 0x62, 0x75, 0x74, 0x74, 0x6f, 0x6e, 0x3e], i, result = ''; for (i = 0; i < puzzle.length; i++) { result += String.fromCharCode(puzzle[i]).replace(/(\r\n|\n|\r)/gm, ""); } console.log(result); Depending on the result you expect: maybe the replacement of newlines is now no longer necessary?
{ "pile_set_name": "StackExchange" }
Q: having problems with for loop in javascript I have a table with numbers but they are stored as string so I am trying to use the function parseFloat to convert it into a table of ints. However, no matter how I do the for loops it gives me a blank table. I can parse the row and it will give me a single int. I can parse a single int as well but cant seem to parse a row or the table. here is what I have so far. This is just trying to convert one row. I tried two for loops for the entire table but that didn't work either. thanks. var c =[]; var entries = $.parseJSON('<?php print(json_encode($try, true)); ?>'); for (var j = 0; j < 12; j++) { for (var i = 0; i < 7; i++) { c [j][i] = parseFloat(entries[j][i]); } } alert(c); here is entries json encodes [["-248","-163","-455","-1413","-1294","-1296","-1089"],["-172","-219","-1186","-1368","-1480","-1079","-845"],["-98","-198","-703","-996","-1100","-585","-616"],["-116","-241","-498","-642","-704","-354","-430"],["-137","-117","-264","-525","-533","-269","-476"],["-12","87","-257","-463","-551","-302","-535"],["170","61","-250","-472","-659","-220","-605"],["159","96","-234","-513","-617","-196","-710"],["185","117","-272","-521","-610","-258","-798"],["208","95","-234","-534","-696","-280","-854"],["192","151","-188","-641","-739","-279","-957"],["249","223","-235","-684","-763","-339","-978"]] A: You have to initialize the second dimension of your array to also be an array. As it stands now, c[j] is just a single value so you can't do c[j][i] on it. There is also an error in your first for loop where you need to compare the value of j, not i. See this fixed code: var c = []; var entries = $.parseJSON('<?php print(json_encode($try, true)); ?>'); for (var j = 0; j < 12; j++) { c[j] = []; for (var i = 0; i < 7; i++) { c [j][i] = parseFloat(entries[j][i]); } } alert(c);
{ "pile_set_name": "StackExchange" }
Q: How to test whether $e^{3x^{2}} + \frac {1}{1+3x^2} - 2\cos(x^2)$ is $o(x^3)$? From what I learned, $\lim_{x \rightarrow 0} \frac {f(x)}{x^3} = 0$ tells $f(x) = o(x^3)$ In this case, I have tried to compute $\lim_{x \rightarrow 0} \frac {e^{3x^{2}}}{x^3}$, but the limit seems not to exist. Then I tried to combine these terms to make it available to use L'Hospital's Rule, i.e. $\lim_{x \rightarrow 0} \frac {e^{3x^{2}}}{x^3}-\cos(x^2)$ , $\lim_{x \rightarrow 0} \frac {1}{1+3x^2}-\cos(x^2)$ . However, they all failed. Any hints or suggestions? Edit: The definition of little-oh should be $\lim_{x \rightarrow \infty} \frac {f(x)}{g(x)} = 0$ tells $f(x) = o(g)$ rahter than $x \rightarrow 0$ A: We have $$f(x) = e^{3x^{2}} + \frac{1}{1 + 3x^{2}} - 2\cos(x^{2})$$ and clearly we have \begin{align} L &= \lim_{x \to 0}\frac{f(x)}{x^{3}}\notag\\ &= \lim_{x \to 0}\dfrac{e^{3x^{2}} + \dfrac{1}{1 + 3x^{2}} - 2}{x^{3}} + 2\cdot\frac{1 - \cos(x^{2})}{x^{3}}\notag\\ &= \lim_{x \to 0}\dfrac{(e^{3x^{2}} - 2)(1 + 3x^{2}) + 1}{x^{3}(1 + 3x^{2})} + 2\cdot\frac{1 - \cos(x^{2})}{x^{4}}\cdot x\notag\\ &= \lim_{x \to 0}\dfrac{e^{3x^{2}} + 3x^{2}e^{3x^{2}} - 6x^{2} - 1}{x^{3}} + 2\cdot\frac{1}{2}\cdot 0\notag\\ &= \lim_{x \to 0}\dfrac{e^{3x^{2}} - 3x^{2} - 1 + 3x^{2}e^{3x^{2}} - 3x^{2}}{x^{3}}\notag\\ &= \lim_{x \to 0}\dfrac{e^{3x^{2}} - 3x^{2} - 1}{x^{3}} + 9x\cdot\frac{e^{3x^{2}} - 1}{3x^{2}}\notag\\ &= \lim_{x \to 0}\dfrac{e^{3x^{2}} - 3x^{2} - 1}{x^{3}} + 9\cdot 0\cdot 1\notag\\ &= \lim_{x \to 0}\dfrac{e^{3x^{2}} - 3x^{2} - 1}{x^{3}}\notag\\ &= \lim_{x \to 0}\dfrac{e^{3x^{2}} - 3x^{2} - 1}{9x^{4}}\cdot 9x\notag\\ &= 9\lim_{x \to 0}x\cdot\lim_{t \to 0}\frac{e^{t} - t - 1}{t^{2}}\text{ (putting }t = 3x^{2})\notag\\ &= 9\lim_{x \to 0}x\cdot\lim_{t \to 0}\frac{e^{t} - 1}{2t}\text{ (via L'Hospital's Rule)}\notag\\ &= 9 \cdot 0\cdot\frac{1}{2} = 0\notag \end{align} and hence $f(x) = o(x^{3})$ as $x \to 0$. Update: The notation $o(g(x)), O(g(x))$ is relevant only in case we are trying to describe behavior of some function $f(x)$ in the neighborhood of a point $a$ (or when $x \to \infty$). Thus is is better to mention the point under consideration when using this notation. Thus if $$f(x)/g(x) \to 0 \text{ as } x \to a$$ then we write $$f(x) = o(g(x))\text{ as }x \to a$$ and if $$f(x)/g(x) \to 0\text{ as }x \to \infty$$ then we write $$f(x) = o(g(x)) \text{ as }x \to \infty$$
{ "pile_set_name": "StackExchange" }
Q: Am I solving the system of differential equations the right way? I have the following equations: $$ y_1'(t)=4y_1(t)-y_2(t)+f_1(t) $$ $$ y_2'(t)=2y_1(t)+2y_2(t)+f_2(t) $$ where: $$f_1(t)=\frac{e^{4t}\cos{t}}{e^{2t}+1}$$ $$f_2(t)=\frac{e^{4t}(\cos{t}+\sin{t})}{e^{2t}+1}$$ $$y_1(0)=y_2(0)=\frac{\pi}{4}$$ I tried to solve it like this: $y_2 = 4y_1 -y_1' -f_1 $ $ y_2' = 4y_1' -y_1'' -f_1'$ then I got that: $4y_1' -y_1'' -f_1' = 2y_1 +2\cdot(4y_1-y_1'-f_1) +f_2$ and from here I got that: $y_1''-6y_1' +10y_1 = 2f_1 -f_1' -f_2$ where $$ f_1'(t)=\frac{(e^{2t}+1)(-\sin{t}\cdot e^{4t}+4\cos{t} \cdot e^{4t})-\cos{t}\cdot e^{4t} \cdot 2 e^{2t}}{(e^{2t}+1)^2}$$ and from here I got that: $2f_1(t) - f_1'(t) -f_2(t) = \frac{2\cos{t} \cdot e^{4t} \cdot (e^{2t}+1) + (e^{4t}\sin{t} -4e^{4t}\cos{t})\cdot(e^{2t}+1)+\cos{t}\cdot e^{4t} \cdot 2 e^{2t}-e^{4t}\cdot(e^{2t}+1)\cdot(\cos{t}+\sin{t})}{(e^{2t}+1)^2}$ and from here I got that: $$y_1''-6y_1' +10y_1 = -\frac{e^{4t}\cdot\cos{t}\cdot(e^{2t}+3)}{(e^{2t}+1)^2}$$ and this is where I got stuck. Am I on the right path? If yes, how do you I continue from here? if no, how else should I solve this? Thanks! A: I don't think you're doing it in quite the right way. You can express it in matrix form. The methods for linear second order constant coefficient differential equations that you tried to use are analogous to those used for systems of first order linear differential equations (your case), but aren't quite the same. You start by writing your system $$\mathbf{y}' = A\mathbf{y} + \mathbf{f}(t)$$ where $$\begin{align} A &= \left(\begin{array}{rr}4&-1\\2&2 \end{array}\right)\\ \mathbf{f}(t) &= \left(\begin{array}{cc} \frac{e^{4t}\cos{t}}{e^{2t}+1}\\ \frac{e^{4t}(\cos{t}+\sin{t})}{e^{2t}+1} \end{array}\right) \end{align}$$ This is an inhomogeneous equation, because $\mathbf{f}(t) \neq \mathbf{0}$. However you can use the principle of superposition: i.e. find the general solution of the homogeneous equation $\mathbf{y}' = A\mathbf{y}$ and find a particular integral $\mathbf{p}(t)$ that satisfies the inhomogeneous equation, and add them together to get the general solution to your inhomogeneous equation. The solutions to the homogeneous equation are given by the eigenvalues $\lambda_1$ and $\lambda_2$ and eigenvectors $\mathbf{v}_1, \mathbf{v}_2$ of $A$. The general solution to the homogeneous equation, known as the complementary function, is $$ \mathbf{y} = C_1\mathbf{v}_1e^{\lambda_1t} + C_2\mathbf{v}_2e^{\lambda_2t} $$ where $C_1,C_2$ are arbitrary complex constants. In your case the eigenvalues are complex: $3 \pm i$. To restrict yourself to real solutions you need to do some trickery, which (because the constants can be complex) comes down to looking at just one eigenvector and eigenvalue, applying Euler's equation $e^{i\theta} = \cos\theta + i\sin\theta$ to convert the exponentials to trigonometric functions, and then doing the algebra to separate out the real and imaginary parts. You can then write the general solution to the homogeneous equation as: $$ \mathbf{y} = C_1\mathrm{Re}(\mathbf{v}_1e^{\lambda_1t}) + C_2\mathrm{Im}(\mathbf{v}_1e^{\lambda_1t}) $$ where $C_1,C_2$ are real. Armed with a general solution, you would then look for a particular integral. I agree with the other answer that this isn't at all obvious, because of the complexity of $\mathbf{f}(t)$. As the other answer said, your best bet is to try to find a $\mathbf{f}$ in a similar form. I would just try some things out and try to get a feel for what the particular integral might be. Overall, this is a complex subject that can only be introduced in this answer. You could search for "solving systems of first order linear differential equations" on the web: Pauls Online Notes seem very good. It will also be covered in plenty of textbooks.
{ "pile_set_name": "StackExchange" }
Q: Svg Slider in console but not showing I'm trying to build a slider svg template which I can use to switch from light theme to dark theme, The original idea is to try and replicate a design that I've seen that has a moon, then when it slides position it turns into a sun. I have build a basic template (without any graphics yet). Which I could then animate through JavaScript. However I can't even get the basic template to show in the browser. <?xml version="1.0" encoding="UTF-8" standalone="no"?><!-- xml:lang='en' lang='en'--> <!DOCTYPE svg [ <!-- entities etc. here --> ]> <svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" preserveAspectRatio="xMidYMid meet" viewBox="0 0 145 145" width="145" height="145" stroke="#ffffff"> <path class="" id="a2aBdbnHKq" fill="black" stroke="" d="M359.91 269.76C363.84 269.76 367.03 272.95 367.03 276.88C367.03 299.29 367.03 359.4 367.03 381.81C367.03 385.75 363.84 388.93 359.91 388.93C323.48 388.93 221.3 388.93 184.87 388.93C180.94 388.93 177.75 385.75 177.75 381.81C177.75 359.4 177.75 299.29 177.75 276.88C177.75 272.95 180.94 269.76 184.87 269.76C221.3 269.76 323.48 269.76 359.91 269.76Z"> </path> <path class="circ1" id="C1" fill="#c744f0" stroke="" d="M242.59 329.35C242.59 362.23 214.59 388.93 180.09 388.93C145.59 388.93 117.58 362.23 117.58 329.35C117.58 296.46 145.59 269.76 180.09 269.76C214.59 269.76 242.59 296.46 242.59 329.35Z"> </path> <path class="rnd_rect" id="Box1" fill="#c744f0" stroke="" d="M418.51 329.35C418.51 362.23 390.5 388.93 356 388.93C321.5 388.93 293.49 362.23 293.49 329.35C293.49 296.46 321.5 269.76 356 269.76C390.5 269.76 418.51 296.46 418.51 329.35Z"> </path> <path class="circ2" id="C2" fill="#c744f0" stroke="" d="M234.71 329.35C234.71 357.72 210.23 380.76 180.09 380.76C149.94 380.76 125.46 357.72 125.46 329.35C125.46 300.97 149.94 277.94 180.09 277.94C210.23 277.94 234.71 300.97 234.71 329.35Z"> </path> <defs> </defs> </svg> Using W3 Document Markup Checker, the file validates and shows no errors. What have I missed? The latest svg docs state not to use a doctype declaration, but regardless it doesn't work with or without them. It is being shown in the console, but no graphics on screen. I know there are many questions similar to this, but every svg is different and their solutions are not working. Also as a side question: would anyone explain what these 3 attributes are: xmlns:sketch="?" baseProfile="full" filterUnits="objectBoundingBox" A: I can't even get the basic template to show in the browser. I uploaded your svg file to a vector editor. The picture shows that your figure is outside the svg canvas It is located below and to the right and its size exceeds the size of the canvas svg Therefore, it is necessary to reduce the size of the figure and move it to the left and up transform="scale(0.5) translate(-120, -183)" Note The upper left corner is the origin of the SVG. The positive direction along the axis X - to the right, along the axisY - to the down <svg version="1.1" baseProfile="full" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:ev="http://www.w3.org/2001/xml-events" preserveAspectRatio="xMidYMid meet" viewBox="0 0 145 145" width="50vw" height="50vh" stroke="#ffffff" style="border:1px solid red;"> <!-- Reduce the size of the figure and move it to the left and up --> <g transform="scale(0.5) translate(-120, -183)"> <path class="" id="a2aBdbnHKq" fill="black" stroke="" d="M359.91 269.76C363.84 269.76 367.03 272.95 367.03 276.88C367.03 299.29 367.03 359.4 367.03 381.81C367.03 385.75 363.84 388.93 359.91 388.93C323.48 388.93 221.3 388.93 184.87 388.93C180.94 388.93 177.75 385.75 177.75 381.81C177.75 359.4 177.75 299.29 177.75 276.88C177.75 272.95 180.94 269.76 184.87 269.76C221.3 269.76 323.48 269.76 359.91 269.76Z"> </path> <path class="circ1" id="C1" fill="#c744f0" stroke="" d="M242.59 329.35C242.59 362.23 214.59 388.93 180.09 388.93C145.59 388.93 117.58 362.23 117.58 329.35C117.58 296.46 145.59 269.76 180.09 269.76C214.59 269.76 242.59 296.46 242.59 329.35Z"> </path> <path class="rnd_rect" id="Box1" fill="#c744f0" stroke="" d="M418.51 329.35C418.51 362.23 390.5 388.93 356 388.93C321.5 388.93 293.49 362.23 293.49 329.35C293.49 296.46 321.5 269.76 356 269.76C390.5 269.76 418.51 296.46 418.51 329.35Z"> </path> <path class="circ2" id="C2" fill="#c744f0" stroke="" d="M234.71 329.35C234.71 357.72 210.23 380.76 180.09 380.76C149.94 380.76 125.46 357.72 125.46 329.35C125.46 300.97 149.94 277.94 180.09 277.94C210.23 277.94 234.71 300.97 234.71 329.35Z"> </path> </g> <defs> </defs> </svg> The red frame shows the borders of the svg canvas. Red frame can be removed after debugging the positioning.
{ "pile_set_name": "StackExchange" }
Q: Show $ \int_0^\infty\left(1-x\sin\frac 1 x\right)dx = \frac\pi 4 $ How to show that $$ \int_0^\infty\left(1-x\sin\frac{1}{x}\right)dx=\frac{\pi}{4} $$ ? A: Use $$ \int \left(1-x \sin\left(\frac{1}{x}\right)\right) \mathrm{d} x = x - \int \sin\left(\frac{1}{x}\right) \mathrm{d} \frac{x^2}{2} = x - \frac{x^2}{2}\sin\left(\frac{1}{x}\right) - \frac{1}{2} \int \cos\left(\frac{1}{x}\right) \mathrm{d}x $$ Integrating by parts again $\int \cos\left(\frac{1}{x}\right) \mathrm{d}x = x \cos\left(\frac{1}{x}\right) - \int \sin\left(\frac{1}{x}\right) \frac{\mathrm{d}x}{x} $: $$ \int \left(1-x \sin\left(\frac{1}{x}\right)\right) \mathrm{d} x = x - \frac{x^2}{2}\sin\left(\frac{1}{x}\right) - \frac{x}{2} \cos\left(\frac{1}{x}\right) + \frac{1}{2} \int \sin\left(\frac{1}{x}\right) \frac{\mathrm{d}x}{x} $$ Thus: $$ \begin{eqnarray} \int_0^\infty \left(1-x \sin\left(\frac{1}{x}\right)\right) \mathrm{d} x &=& \left[x - \frac{x^2}{2}\sin\left(\frac{1}{x}\right) - \frac{x}{2} \cos\left(\frac{1}{x}\right)\right]_{0}^{\infty} + \frac{1}{2} \int_0^\infty\sin\left(\frac{1}{x}\right) \frac{\mathrm{d}x}{x} = \\ &=& 0 + \frac{1}{2} \int_0^\infty \frac{\sin{u}}{u} \mathrm{d} u = \frac{\pi}{4} \end{eqnarray} $$ where the last integral is the Dirichlet integral. A: Sasha's answer concisely gets the answer in terms of the Dirichlet integral, so I will evaluate this integral in the same way that the Dirichlet integral is evaluated with contour integration. First, change variables to $z=1/x$: $$ \int_0^\infty\left(1-x\sin\left(\frac1x\right)\right)\,\mathrm{d}x =\int_0^\infty\frac{z-\sin(z)}{z^3}\,\mathrm{d}z\tag{1} $$ Since the integrand on the right side of $(1)$ is even, entire, and vanishes as $t\to\infty$ within $1$ of the real axis, we can use symmetry to deduce that the integral is $\frac12$ the integral over the entire line and then shift the path of integration by $-i$: $$ \int_0^\infty\frac{z-\sin(z)}{z^3}\,\mathrm{d}z =\frac12\int_{-\infty-i}^{\infty-i}\frac{z-\sin(z)}{z^3}\,\mathrm{d}z\tag{2} $$ Consider the contours $\gamma^+$ and $\gamma^-$ below. Both pass a distance $1$ below the real axis and then circle back along circles of arbitrarily large radius. $\hspace{4.4cm}$ Next, write $\sin(z)=\frac1{2i}\left(e^{iz}-e^{-iz}\right)$ and split the integral as follows $$ \frac12\int_{-\infty-i}^{\infty-i}\frac{z-\sin(z)}{z^3}\,\mathrm{d}z =\frac12\int_{\gamma^-}\left(\frac1{z^2}+\frac{e^{-iz}}{2iz^3}\right)\,\mathrm{d}z -\frac12\int_{\gamma^+}\frac{e^{iz}}{2iz^3}\,\mathrm{d}z\tag{3} $$ $\gamma^-$ contains no singularities so the integral around $\gamma^-$ is $0$. The integral around $\gamma^+$ is $\color{#00A000}{2\pi i}$ times $\color{#00A000}{-\dfrac{1}{4i}}$ times the residue of $\color{#C00000}{\dfrac{e^{iz}}{z^3}}$ at $\color{#C00000}{z=0}$; that is, $\color{#00A000}{-\dfrac\pi2}$ times the coefficient of $\color{#C00000}{\dfrac1z}$ in $$ \frac{1+iz\color{#C00000}{-z^2/2}-iz^3/6+\dots}{\color{#C00000}{z^3}}\tag{4} $$ Thus, the integral around $\gamma^+$ is $\color{#00A000}{\left(-\dfrac\pi2\right)}\color{#C00000}{\left(-\dfrac12\right)}=\dfrac\pi4$. Therefore, combining $(1)$, $(2)$, and $(3)$ yields $$ \int_0^\infty\left(1-x\sin\left(\frac1x\right)\right)\,\mathrm{d}x=\frac\pi4\tag{5} $$ As complicated as that may look at first glance, with a bit of practice, it is easy enough to do in your head. A: Let's start out with the variable change $\displaystyle x=\frac{1}{u}$ and then turn the integral into a double integral: $$\int_{0}^{\infty} {\left( {1 - \frac{\sin u}{u}} \right)\frac{1}{u^2}} \ du=$$ $$ \int_{0}^{\infty}\left(\int_{0}^{1} 1 - \cos (u a) \ da \right)\frac{1}{u^2} \ du=$$ By changing the integration order we get $$ \int_{0}^{1}\left(\int_{0}^{\infty} \frac{1 - \cos (a u)}{u^2} \ du \right)\ \ da=\int_{0}^{1} a \frac{\pi}{2} \ da=\frac{\pi}{4}.$$ Note that by using a simple integration by parts at $\displaystyle \int_{0}^{\infty} \frac{1 - \cos (a u)}{u^2} \ du$ we immediately get $\displaystyle a\int_{0}^{\infty} \frac{\sin(au)}{u} \ du = a\int_{0}^{\infty} \frac{\sin(u)}{u}\ du$ that is $\displaystyle a\frac{\pi}{2}$. The last integral is the famous Dirichlet integral. Hence the result follows and the proof is complete. Q.E.D. (Chris)
{ "pile_set_name": "StackExchange" }
Q: RSA decryption with large keys My problem: I already know the private and public key of an RSA system and I have an encrypted message but I can't decrypt it, because my private exponent is about 1024 bit. My data is following if it is needed for details but the question is how to decrypt a message with long keys on a simple home PC. N = 0xb197d3afe713816582ee988b276f635800f728f118f5125de1c7c1e57f2738351de8ac643c118a5480f867b6d8756021911818e470952bd0a5262ed86b4fc4c2b7962cd197a8bd8d8ae3f821ad712a42285db67c85983581c4c39f80dbb21bf700dbd2ae9709f7e307769b5c0e624b661441c1ddb62ef1fe7684bbe61d8a19e7 e = 65537 p = 0xc315d99cf91a018dafba850237935b2d981e82b02d994f94db0a1ae40d1fc7ab9799286ac68d620f1102ef515b348807060e6caec5320e3dceb25a0b98356399 q = 0xe90bbb3d4f51311f0b7669abd04e4cc48687ad0e168e7183a9de3ff9fd2d2a3a50303a5109457bd45f0abe1c5750edfaff1ad87c13eed45e1b4bd2366b49d97f d = 0x496747c7dceae300e22d5c3fa7fd1242bda36af8bc280f7f5e630271a92cbcbeb7ae04132a00d5fc379274cbce8c353faa891b40d087d7a4559e829e513c97467345adca3aa66550a68889cf930ecdfde706445b3f110c0cb4a81ca66f8630ed003feea59a51dc1d18a7f6301f2817cb53b1fb58b2a5ad163e9f1f9fe463b901 c = 0x58ae101736022f486216e290d39e839e7d02a124f725865ed1b5eea7144a4c40828bd4d14dcea967561477a516ce338f293ca86efc72a272c332c5468ef43ed5d8062152aae9484a50051d71943cf4c3249d8c4b2f6c39680cc75e58125359edd2544e89f54d2e5cbed06bb3ed61e5ca7643ebb7fa04638aa0a0f23955e5b5d9 where c is ciphertext, N is module, e and d are public and private exponents respectively and p and q are primes (I suppose so, but it is hard to check). I already tried to use online services like this and several others. Also on my PC I have used python rsa library but it fails with errors. I suppose the following formula is used everywhere (suppose m stands for plaintext): m = c**d % N or m = 1 for i in xrange(d): m = (m * c) % N So maybe there is a more clever way from a mathematical point of view to calculate this m faster, or an online service that can solve it, or a library. Or it is possible only for supercomputers to calculate 1024 bit exponent RSA decryption? Data is taken from CTF context picoctf. A: First of all, I really hope that (a) this isn't important information and (b) you're not going to ever use this key pair again, because I can now decrypt this ciphertext and any other encrypted message sent to you with it. We can decode the message in python (resulting in a hex-encoded string) as follows: m = hex(pow(c, d, N)).rstrip("L") Which gives 0x436f6e67726174756c6174696f6e73206f6e2064656372797074696e6720616e20525341206d6573736167652120596f757220666c6167206973206d6f64756c61725f61726974686d65746963735f6e6f745f736f5f6261645f61667465725f616c6c The builtin pow function uses exponentiation by squaring to efficently compute large powers modulo an integer. Without exponentiation by squaring and its variants, the use of any asymmetric key algorithm which relies on the Discrete Logarithm problem (which is most, but not all, of them) is infeasible. It's actually quite easy to implement, and I strongly recommend that you do so. Read the wikipedia article for more information.
{ "pile_set_name": "StackExchange" }
Q: Why is the creation of multi-dimensional arrays so slow in Scala? Consider this code: Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array(Array()))))))))))))))))))))))))))))))))))))))))))))))))))))))))))) I aborted the REPL after several minutes. Should I expect such long compilation times or is this a problem/bug of the compiler? A: Misleading title, I think, at least with respect to the actual code you're trying. Let's help the type inferencer... object A extends App { val x = Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Array[Nothing]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]() println(x) } That compiles just fine and runs just fine (I don't even have to modify JVM options): $ time scalac -d classes A.scala real 0m5.179s $ time scala -cp classes A [[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[Ljava.lang.Object;@872380 real 0m2.461s So it's more about compilation and type inference including in the REPL (which rewrites the code and recompiles). The REPL seems to struggle somewhere after the explicitrouter phase (tried using scala -Xprint:all). A: On Scala 2.9.0.1 this compiles (and runs) just fine as long as you give scalac enough stack space: export JAVA_OPTS="-ss128M" scalac arrays.scala It doesn't seem to work in the REPL though, but that doesn't really surprise me anymore...
{ "pile_set_name": "StackExchange" }
Q: mysql how can I query a database table by day and month and produce totals I have the following database table "id","date_occurred","country","town","quantity" "1","2012-06-01","England","Andover","82" "2","2012-06-01","England","Colchester","569" "3","2012-06-01","England","Farnham","1" "4","2012-06-01","England","England","4" "5","2012-06-01","England","America","13" "6","2012-06-01","America","England","114" "7","2012-06-02","England","Andover","4" "8","2012-06-02","England","Colchester","207" "9","2012-06-02","America","England","14" "10","2012-06-03","England","Andover","3" "11","2012-06-03","England","Colchester","72" "12","2012-06-03","England","America","1" "13","2012-06-03","America","England","15" "14","2012-07-04","England","Andover","1" "15","2012-07-04","England","Colchester","309" "16","2012-07-04","England","America","4" "17","2012-07-04","America","England","11" "18","2012-08-05","England","Andover","2" "19","2012-08-05","England","Colchester","319" "20","2012-08-05","England","Farnham","1" "21","2012-08-05","England","America","4" "22","2012-08-05","America","England","25" "23","2012-08-06","England","Andover","93" "24","2013-06-06","England","Colchester","542" "25","2013-06-06","England","Farnham","1" "26","2013-06-06","England","England","4" "27","2013-06-06","England","America","7" "28","2013-06-06","America","England","115" I would like to produce the following output from a query Total sales per day per country for a given month 2012-06-01 England 669 2012-06-01 America 114 2012-06-02 England 211 Total sales per day per town for a given month 2012-06-01 Andover 82 2012-06-02 Andover 4 I have been trying various queries with group by, sum, and count, but can't get the correct output. any simple solutions or guidance welcome. Thanks in advance A: Try this: Total sales per day per country for a given month: SELECT date_occurred, country, SUM(quantity) FROM tableA WHERE YEAR(date_occurred) = 2013 AND MONTH(date_occurred) = 6 GROUP BY date_occurred, country Total sales per day per town for a given month: SELECT date_occurred, town, SUM(quantity) FROM tableA WHERE YEAR(date_occurred) = 2013 AND MONTH(date_occurred) = 6 GROUP BY date_occurred, town
{ "pile_set_name": "StackExchange" }
Q: WPF Rounded Corners background bleeding through I'm making my first foray into WPF - I have a simple form with a popup defined for inline help. I'm using rounded corners, and for some reason a black background is bleeding through around the corners. I don't understand which element is causing the problem. alt text http://www.awbrey.net/rounded.jpg I assume it's something blindingly obvious which I'm just not seeing. Here's the XAML I'm using: <Window x:Class="Consent.Client.SubjectNumberEntry" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" FontSize="24" Title="SubjectNumberEntry" WindowStyle="None" WindowState="Maximized" xmlns:h="clr-namespace:Consent.Client" KeyDown="windowOuter_KeyDown" Background="White" Name="windowOuter" AllowsTransparency="true" Loaded="Window_Loaded"> <StackPanel Height="400" DockPanel.Dock="Top" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="10"> <StackPanel Height="60" Orientation="Horizontal" VerticalAlignment="Center"> <TextBox Name="txtSubjectNumber" Margin="10" Width="400" KeyDown="txtSubjectNumber_KeyDown" h:HelpProvider.HelpString="Enter the subject identifier, or scan their wristband"> <TextBox.ToolTip>This is a textbox</TextBox.ToolTip> </TextBox> <Button Name="btnEnter" Margin="10" Width="100" Click="btnEnter_Click">Enter</Button> <Button Width="50" Name="btnHelp" Margin="10" Click="btnHelp_Click">?</Button> <Button Width="50" Name="btnExit" Margin="10" Click="btnExit_Click">Exit</Button> </StackPanel> <Label Name="lblValue" Margin="10"></Label> <Popup Placement="Bottom" HorizontalAlignment="Center" VerticalOffset="10" MouseDown="popHelp_MouseDown" PopupAnimation="Fade" Name="popHelp" PlacementTarget="{Binding ElementName=txtSubjectNumber}"> <Border Padding="10" Margin="10" BorderBrush="CornflowerBlue" BorderThickness="1" CornerRadius="10" Background="CornflowerBlue"> <TextBlock FontSize="12" Background="CornflowerBlue">This is the content of the help box.</TextBlock> </Border> </Popup> </StackPanel> </Window> A: I think it is the Popup that is causing the problem. Try setting AllowsTransparency to True on the popup. Popup.AllowsTransparency When set to False, any transparent colors are "merged" with black.
{ "pile_set_name": "StackExchange" }
Q: ftruncate() not emptying my file I have a file in which I write <timestamp>hashedcertificate <timestamp>hashedcertificate <timestamp>hashedcertificate (etc.) On a certain request, I'm reading out all timestamps in an array and all hash strings in an array. $valid = fopen("./valid", "r+"); if (!$valid) { log::Write("Could not open file. Exiting..", DEBUG); exit(1); } $isLocked = flock($valid, LOCK_EX); while (!$isLocked) $isLocked = flock($valid, LOCK_EX); while (!feof($valid)) { $pos_begin = strpos($line, "<"); $pos_end = strpos($line, ">", $pos_begin); $timestamp = substr($line, $pos_begin+1, $pos_end - $pos_begin - 1); $timestamps[] = $timestamp; $storedCert = substr($line, $pos_end + 1); $storedCerts[] = $storedCert; log::Write(sprintf("Read: %s with timestamp %s", $storedCert, $timestamp), DEBUG); $line = fgets($valid); } After checking them (remove if timestamp is too old), I want to write back the remaining, valid hashes back into the file. ftruncate($valid, 0); $counter = 0; foreach ($timestamps as $timestamp) { $toWrite = "<" . $timestamp . ">" . $storedCerts[$counter] . "\n"; log::Write(sprintf("Writing: \n%s", $toWrite), DEBUG); fputs($valid, $toWrite); $counter += 1; } flock($valid, LOCK_UN); fclose($valid); But my file does always look like this: (after the ftruncate I think, because when I open the file to append the timestamps+hash, it does that without strange stuff; only when the reading from file + remove array elements + ftruncate + write back into file stuff comes) (please ignore the first hash; i changed it temporary to crc32 to have it shorter): ^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@^@<1378903136>9f71fb266d96afa161c1e52e8b65031c08997bdb5f215f7d <1378903666>b0e15296 <1378903671>6b4132b9 <1378903695>b0e15296 What am I doing wrong? A: Shouldn't you do a rewind() after the truncate to reset the pointer to the beginning of the file again?
{ "pile_set_name": "StackExchange" }
Q: Project Euler Number 24 Python 2.7.9 Hello I'm experiencing some problems with how python is handling my permutations algorithm. So I want my function to take the set_list=[1,2,3,4] and return all the permutations of that list. This was my idea. Move from left to right, starting at the index values 0,1 of set_list, flip the value of set_list[index] with the value of set_list[index+1], with the understanding that when you reach an end point you flip set_list[0] with set_list[-1]. I thought this was gucci. Solution Forward 1234 2134 2314 2341 1342 3142 3412 3421 1423 4123 4213 4231 The idea then being to just to a reverse sort of the previous sub-lists to derive all the possible permutations. Solution Reverse 4321 4312 4132 1432 2431 2413 2143 1243 3241 3214 3124 1324 My python notes x = [1,2,3,4] print(x) j k k j x[0],x[1] = x[1],x[0] print(x) x[1],x[2] = x[2],x[1] print(x) x[2],x[3] = x[3],x[2] print(x) x[3],x[0] = x[0],x[3] print(x) x[0],x[1] = x[1],x[0] print(x) x[1],x[2] = x[2],x[1] print(x) x[2],x[3] = x[3],x[2] print(x) x[3],x[0] = x[0],x[3] print(x) x[0],x[1] = x[1],x[0] print(x) x[1],x[2] = x[2],x[1] print(x) x[2],x[3] = x[3],x[2] print(x) x[3],x[0] = x[0],x[3] print(x) Code returns: [1, 2, 3, 4] [2, 1, 3, 4] [2, 3, 1, 4] [2, 3, 4, 1] [1, 3, 4, 2] [3, 1, 4, 2] [3, 4, 1, 2] [3, 4, 2, 1] [1, 4, 2, 3] [4, 1, 2, 3] [4, 2, 1, 3] [4, 2, 3, 1] [1, 2, 3, 4] So for a lot of reasons recursively using this function doesn't work (I have no idea why): def set_return(__LIST__,j,k): __LIST__[j],__LIST__[k]=__LIST__[k],__LIST__[j] return(__LIST__) So I decided to try and sudo-bullshit-hack a solution together, and have only successfully succeed in pulling my hair out. Step 1) Create lists containing values from vertical lists of j,k based on characteristics of list x shouldn't be that hard right? x = [1,2,3,4] set_0 = range(0,len(x))*(len(x)-1) set_1 = set_0[1:len(set_0)]+[set_0[0]] Code Returns: >>> set_0 [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3] >>> set_1 [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0] >>> Step 2) def shift(__LIST__,a,b): j = int(__LIST__[a]) k = int(__LIST__[b]) __LIST__[a] = k __LIST__[b] = j return(__LIST__) Code Output: >>> [1, 2, 3, 4] [2, 1, 3, 4] [2, 3, 1, 4] [2, 3, 4, 1] [1, 3, 4, 2] [3, 1, 4, 2] [3, 4, 1, 2] [3, 4, 2, 1] [1, 4, 2, 3] [4, 1, 2, 3] [4, 2, 1, 3] [4, 2, 3, 1] [1, 2, 3, 4] >>> set_0 [0, 1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3] >>> set_1 [1, 2, 3, 0, 1, 2, 3, 0, 1, 2, 3, 0] >>> shift([1, 2, 3, 4],0,1) [2, 1, 3, 4] >>> shift([2, 1, 3, 4],1,2) [2, 3, 1, 4] >>> shift([2, 3, 1, 4],2,3) [2, 3, 4, 1] >>> shift([2, 3, 4, 1],3,0) [1, 3, 4, 2] >>> So then I use this: chi = [1,2,3,4] set_0 = range(0,len(chi))*(len(chi)-1) set_1 = set_0[1:len(set_0)]+[set_0[0]] to_return=[] x = [1,2,3,4] for i in range(len(set_0)): insert=shift(x,set_0[i],set_1[i]) to_return.append(insert) x = insert And get: [[1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4], [1, 2, 3, 4]] Are there easier ways...yes. Can I "protect" x or insert or hell maybe even both with list() ...face palm. Posting anyway. Enjoy. A: The issue you are having at the end of your code is that all your insert values are references to the same list x, which gets modified in place by the shift function. You only see [1, 2, 3, 4] values in your to_return list because that's the final value of x. If you printed x while the loop was running you'd see the other permutations, but storing a reference in to_return doesn't preserve the value when x is modified later. Compare with this: x = [1, 2] y = [x, x, x, x] # y contains several references to the list x print(y) # prints [[1, 2], [1, 2], [1, 2], [1, 2]] x[0] = 0 # modify x in place print(y) # prints [[0, 2], [0, 2], [0, 2], [0, 2]], all the 1's are gone! To fix this issue you can copy the list before appending it to to_return. The copy won't change when you modify x again later. (An alternative solution would be to change shift to return a new list without changing the old one, but I'll leave exploring that option up to you.) When you're storing a copy, you don't even need to care about shift's return value, you can just keep using x directly: for i in range(len(set_0)): shift(x,set_0[i],set_1[i]) # ignore the return value, which is another reference to x to_return.append(x[:]) # append a copy of x The slice x[:] is a compact way of copying the list. You could use list(x) if you wanted to be a bit more explicit (at the cost of a few extra characters). Either version would be easily understood as a copy by experienced Python programmers. Before I finish this answer, I want to make a few additional suggestions which are somewhat unrelated to the issue you were asking about. First off, your algorithm doesn't actually find all the permutations of the list you're giving it. For instance, [4, 3, 2, 1] never appears (nor indeed any permutation where 4 appears directly before 3). So even if the code I suggest above "works" in terms of doing what you want it to do, it may not be doing the right thing in a larger sense. Second is a matter of style. Python lets you name your variables whatever you like, but it's a very bad idea to use some kinds of names. In several of your functions you're using the name __LIST__ which is a really bad name for an argument. For one thing, double-underscore names are reserved for the interpreter. In some future version, Python might store some special value in the name __LIST__ (overwriting whatever you're using it for). Or it might expect that name to hold some specific kind of value, and break in some way if you store something else in it. So don't use double underscores for arbitrary variables! Even if we ignore the double underscores, __LIST__ is not a great name because it's really long and hard to type. While a name that's more explicit is often good (e.g. number_of_things may be better than n), you have to balance that with being easy enough to read and type. It's probably not wise to use list, since that's the name of the builtin type, but lst is a pretty common abbreviation of it. When it comes to names, above all, be consistent. It doesn't really matter if you use a and b for throwaway variables, but it's much more confusing when you sometimes use those, and other times use j, and k (without any obvious distinction between their meanings).
{ "pile_set_name": "StackExchange" }
Q: How do I force cabal to give me more meaningful error messages? On trying to install Pandoc, I see: .... /usr/local/bin/ghc --make -o dist/build/pandoc/pandoc -hide-all-packages -fbuilding-cabal-package -package-conf dist/package.conf.inplace -i -idist/build/pandoc/pandoc-tmp -isrc -idist/build/autogen -Idist/build/autogen -Idist/build/pandoc/pandoc-tmp -optP-include -optPdist/build/autogen/cabal_macros.h -odir dist/build/pandoc/pandoc-tmp -hidir dist/build/pandoc/pandoc-tmp -stubdir dist/build/pandoc/pandoc-tmp -package-id HTTP-4000.2.2-b514c58971c354891f971c2309e33000 -package-id base-4.5.0.0-f76ceb9607ba9bd4fcfb9c7b92d8cfe1 -package-id base64-bytestring-0.1.1.0-9a13565ae6900096f49fed9275055262 -package-id blaze-html-0.4.3.1-5d598387646df0193836b494a162a2d4 -package-id bytestring-0.9.2.1-4adca9710b1386944aaca5a7886ef98f -package-id citeproc-hs-0.3.4-cbb3e9b1b273d47e103e907ec1bdc35b -package-id containers-0.4.2.1-7c54595400348f577b3b4a45691c5afd -package-id directory-1.1.0.2-8b4f1910e60eb4e736abc40d5bcff870 -package-id extensible-exceptions-0.1.1.4-d27a1ac47e54880cae007cceceb41580 -package-id filepath-1.3.0.0-674b8a582fb49f1c9724f50a6a5d5768 -package-id highlighting-kate-0.5.0.5-a1ba824bf441c42c048d12abbb7076f2 -package-id json-0.5-95bdbc43daf81b2bce0748d1aaa9c3a3 -package-id mtl-2.0.1.0-e356d8b8100adb575c81fb037ade5369 -package-id network-2.3.0.11-aad575b3bc998a0814d4406663f72a07 -package-id old-locale-1.0.0.4-29bd50ed2bb4a20928338f52e4ab1b71 -package-id pandoc-types-1.9.1-861bbcdbc020a96a664261e3dea501f4 -package-id parsec-3.1.2-ddd167c649705555d9a0c4e2b3751077 -package-id process-1.1.0.1-91185c964ab744c1f3cbca1863d2ba45 -package-id random-1.0.1.1-3bece392c9f5221263ed25c90c28e1ec -package-id syb-0.3.6-05925f4440bc3fbb54d5c12bac109e49 -package-id tagsoup-0.12.6-57ca8a2db7339ea6237481f4729e5e0f -package-id temporary-1.1.2.3-e69a9bd7a2d9d49de929e9a0be4ed42a -package-id texmath-0.6.0.3-2e5a17474805a2f6b73558e3a71ad38b -package-id time-1.4-3e186a51d3674e5d65b5a7925db3d3a7 -package-id utf8-string-0.3.7-528cea24d4cad2c1cb19a75d1ad8976c -package-id xml-1.3.12-d665e5a084b52511c150438a3c9fb8d1 -package-id zip-archive-0.1.1.7-463904d956f1052cc58a2c9e5deeee2c -package-id zlib-0.5.3.3-9ed15628a121b3b57f97b7acc02bf5d9 -O -O2 -Wall -fno-warn-unused-do-bind -dno-debug-output -XHaskell98 -XCPP src/pandoc.hs [39 of 42] Compiling Text.Pandoc.Readers.Markdown ( src/Text/Pandoc/Readers/Markdown.hs, dist/build/pandoc/pandoc-tmp/Text/Pandoc/Readers/Markdown.o ) cabal: Error: some packages failed to install: pandoc-1.9.1.1 failed during the building phase. The exception was: ExitFailure 11 If I try to run that command, it works without any problems. So why do I see ExitFailure 11? How do I get cabal to give me a decent error message? As a side note: I love Haskell, but cabal is awful. We need a better package manager. A: Try using the --verbose=3 flag.
{ "pile_set_name": "StackExchange" }
Q: aggregate function produces daily instead of hourly mean I have a data.frame with 15 minute time steps in the first column and 16 more columns full of data. I want to get the hourly mean for each column. I am using aggregate and it works perfectly fine for 1 min data. mydata <- list() for(j in colnames(data_frame)){ data_mean <- aggregate(data_frame[j], list(hour=cut(as.POSIXct(data_frame$TIME), "hour")), mean, na.rm=TRUE) mydata[[j]] <- data_mean } When I use this same setup for a 15 min data set it gives me the daily mean instead of the hourly mean. Any idea why? My data looks like this for 1 min data: "TIME","Tair","RH" 2016-01-01 00:01:00,5.9,82 2016-01-01 00:02:00,5.9,82 2016-01-01 00:03:00,5.9,82 2016-01-01 00:04:00,5.89,82 2016-01-01 00:05:00,5.8,82 2016-01-01 00:06:00,5.8,82 2016-01-01 00:07:00,5.8,82 2016-01-01 00:08:00,5.8,82 2016-01-01 00:09:00,5.8,82 2016-01-01 00:10:00,5.8,82 2016-01-01 00:11:00,5.8,82 2016-01-01 00:12:00,5.8,82 2016-01-01 00:13:00,5.8,82 2016-01-01 00:14:00,5.8,82 2016-01-01 00:15:00,5.8,82 2016-01-01 00:16:00,5.8,82 2016-01-01 00:17:00,5.8,82 2016-01-01 00:18:00,5.8,82 2016-01-01 00:19:00,5.8,82 2016-01-01 00:20:00,5.8,82 2016-01-01 00:21:00,5.75,82 2016-01-01 00:22:00,5.78,82 2016-01-01 00:23:00,5.78,83 2016-01-01 00:24:00,5.8,82 2016-01-01 00:25:00,5.73,82 2016-01-01 00:26:00,5.7,82 2016-01-01 00:27:00,5.7,82 2016-01-01 00:28:00,5.7,82 2016-01-01 00:29:00,5.7,82 2016-01-01 00:30:00,5.7,82 2016-01-01 00:31:00,5.7,83 2016-01-01 00:32:00,5.76,83 2016-01-01 00:33:00,5.8,83 2016-01-01 00:34:00,5.8,82 2016-01-01 00:35:00,5.8,82 2016-01-01 00:36:00,5.8,83 2016-01-01 00:37:00,5.79,83 2016-01-01 00:38:00,5.7,82 And for 15 min data: "TIME","Tair","RH" 2016-01-01 00:15:00,6.228442,80.40858 2016-01-01 00:30:00,6.121088,81.00000 2016-01-01 00:45:00,6.075000,NA 2016-01-01 01:00:00,5.951910,NA 2016-01-01 01:15:00,5.844144,NA 2016-01-01 01:30:00,5.802242,NA 2016-01-01 01:45:00,5.747619,NA 2016-01-01 02:00:00,5.742889,NA 2016-01-01 02:15:00,5.752584,81.12135 2016-01-01 02:30:00,5.677753,81.00000 2016-01-01 02:45:00,5.500224,81.61435 2016-01-01 03:00:00,5.225282,82.29797 2016-01-01 03:15:00,5.266441,83.00000 2016-01-01 03:30:00,5.200448,83.32584 2016-01-01 03:45:00,5.098876,84.00000 2016-01-01 04:00:00,5.081061,83.76894 2016-01-01 04:15:00,5.230769,82.88664 2016-01-01 04:30:00,5.300000,82.06742 2016-01-01 04:45:00,5.300000,NA 2016-01-01 05:00:00,5.399776,NA A: Your code works for me. However, your loop is slightly wasteful in that it repeatedly computes the cut of the TIME column for every column of the data.frame. You could precompute it, but there's a better solution. You can produce the same result but in a simpler, more conventional, and more useful form with a single call to aggregate(): aggregate(df1[names(df1)!='TIME'],list(hour=cut(df1$TIME,'hour')),mean,na.rm=T); ## hour Tair RH ## 1 2016-01-01 5.786316 82.15789 aggregate(df15[names(df15)!='TIME'],list(hour=cut(df15$TIME,'hour')),mean,na.rm=T); ## hour Tair RH ## 1 2016-01-01 00:00:00 6.141510 80.70429 ## 2 2016-01-01 01:00:00 5.836479 NaN ## 3 2016-01-01 02:00:00 5.668362 81.24523 ## 4 2016-01-01 03:00:00 5.197762 83.15595 ## 5 2016-01-01 04:00:00 5.227957 82.90767 ## 6 2016-01-01 05:00:00 5.399776 NaN Data df1 <- data.frame(TIME=as.POSIXct(c('2016-01-01 00:01:00','2016-01-01 00:02:00', '2016-01-01 00:03:00','2016-01-01 00:04:00','2016-01-01 00:05:00','2016-01-01 00:06:00', '2016-01-01 00:07:00','2016-01-01 00:08:00','2016-01-01 00:09:00','2016-01-01 00:10:00', '2016-01-01 00:11:00','2016-01-01 00:12:00','2016-01-01 00:13:00','2016-01-01 00:14:00', '2016-01-01 00:15:00','2016-01-01 00:16:00','2016-01-01 00:17:00','2016-01-01 00:18:00', '2016-01-01 00:19:00','2016-01-01 00:20:00','2016-01-01 00:21:00','2016-01-01 00:22:00', '2016-01-01 00:23:00','2016-01-01 00:24:00','2016-01-01 00:25:00','2016-01-01 00:26:00', '2016-01-01 00:27:00','2016-01-01 00:28:00','2016-01-01 00:29:00','2016-01-01 00:30:00', '2016-01-01 00:31:00','2016-01-01 00:32:00','2016-01-01 00:33:00','2016-01-01 00:34:00', '2016-01-01 00:35:00','2016-01-01 00:36:00','2016-01-01 00:37:00','2016-01-01 00:38:00')), Tair=c(5.9,5.9,5.9,5.89,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.8,5.75, 5.78,5.78,5.8,5.73,5.7,5.7,5.7,5.7,5.7,5.7,5.76,5.8,5.8,5.8,5.8,5.79,5.7),RH=c(82L,82L,82L, 82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,82L,83L,82L,82L,82L, 82L,82L,82L,82L,83L,83L,83L,82L,82L,83L,83L,82L)); df15 <- data.frame(TIME=as.POSIXct(c('2016-01-01 00:15:00','2016-01-01 00:30:00', '2016-01-01 00:45:00','2016-01-01 01:00:00','2016-01-01 01:15:00','2016-01-01 01:30:00', '2016-01-01 01:45:00','2016-01-01 02:00:00','2016-01-01 02:15:00','2016-01-01 02:30:00', '2016-01-01 02:45:00','2016-01-01 03:00:00','2016-01-01 03:15:00','2016-01-01 03:30:00', '2016-01-01 03:45:00','2016-01-01 04:00:00','2016-01-01 04:15:00','2016-01-01 04:30:00', '2016-01-01 04:45:00','2016-01-01 05:00:00')),Tair=c(6.228442,6.121088,6.075,5.95191, 5.844144,5.802242,5.747619,5.742889,5.752584,5.677753,5.500224,5.225282,5.266441,5.200448, 5.098876,5.081061,5.230769,5.3,5.3,5.399776),RH=c(80.40858,81,NA,NA,NA,NA,NA,NA,81.12135,81, 81.61435,82.29797,83,83.32584,84,83.76894,82.88664,82.06742,NA,NA));
{ "pile_set_name": "StackExchange" }
Q: How to change the accordion menu icon with JS? I have a menu (accordion) that uses Bootstrap 3.3.7 and Font Awesome 5.0.1 What I am looking for : When the menu is closed, a "plus" icon is displayed. When the menu is open, a "minus" icon is displayed. The "plus" icon is displayed on the menu but does not change. I think there is a problem with my JS code. <div class="panel-group" id="accordion"> <div class="panel panel-default"> <div class="panel-heading panel-like"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse1" aria-expanded="false"> <h4 class="panel-title"> <svg class="svg-inline--fa fa-heart fa-w-18 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="heart" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" data-fa-i2svg=""><path fill="currentColor" d="M414.9 24C361.8 24 312 65.7 288 89.3 264 65.7 214.2 24 161.1 24 70.3 24 16 76.9 16 165.5c0 72.6 66.8 133.3 69.2 135.4l187 180.8c8.8 8.5 22.8 8.5 31.6 0l186.7-180.2c2.7-2.7 69.5-63.5 69.5-136C560 76.9 505.7 24 414.9 24z"></path></svg><!-- <i class="fas fa-heart fa-lg"></i> --> Ses pages préférées <span class="badge">0</span> <span class="collapse-change-icon"><svg class="svg-inline--fa fa-plus-circle fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="plus-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg><!-- <i class="fas fa-plus-circle fa-lg"></i> --></span> </h4> </a> </div> <div id="collapse1" class="panel-collapse collapse" aria-expanded="false" style="height: 0px;"> <div class="panel-body"> <div class="panel-help"> L'utilisateur peut montrer ou cacher ce qu'il aime.<br> Les badges verts affichent le nombre total de j'aime (même les cachés).<br> Les résultats affichent uniquement ce que l'utilisateur souhaite montrer. </div> </div> <div class="panel-body"><dd><div class="views-element-container form-group"><div class="view view-profile-page-like view-id-profile_page_like view-display-id-block_1 js-view-dom-id-9c91349966910a86b1ba6a9c66ae52b7b92568e7856bfc40d447149fed9dc49f"> <div class="view-header"> Résultat trouvé 0 </div> <div class="view-empty"> <p>Cet utilisateur n'a mis aucune mention j'aime.</p> </div> </div> </div> </dd></div> </div> </div> <div class="panel panel-default"> <div class="panel-heading panel-contest"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse2" aria-expanded="false"> <h4 class="panel-title"> <svg class="svg-inline--fa fa-trophy fa-w-18 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="trophy" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" data-fa-i2svg=""><path fill="currentColor" d="M552 64H448V24c0-13.3-10.7-24-24-24H152c-13.3 0-24 10.7-24 24v40H24C10.7 64 0 74.7 0 88v56c0 35.7 22.5 72.4 61.9 100.7 31.5 22.7 69.8 37.1 110 41.7C203.3 338.5 240 360 240 360v72h-48c-35.3 0-64 20.7-64 56v12c0 6.6 5.4 12 12 12h296c6.6 0 12-5.4 12-12v-12c0-35.3-28.7-56-64-56h-48v-72s36.7-21.5 68.1-73.6c40.3-4.6 78.6-19 110-41.7 39.3-28.3 61.9-65 61.9-100.7V88c0-13.3-10.7-24-24-24zM99.3 192.8C74.9 175.2 64 155.6 64 144v-16h64.2c1 32.6 5.8 61.2 12.8 86.2-15.1-5.2-29.2-12.4-41.7-21.4zM512 144c0 16.1-17.7 36.1-35.3 48.8-12.5 9-26.7 16.2-41.8 21.4 7-25 11.8-53.6 12.8-86.2H512v16z"></path></svg><!-- <i class="fas fa-trophy fa-lg"></i> --> Les concours remportés <span class="badge">0</span> <span class="collapse-change-icon"><svg class="svg-inline--fa fa-plus-circle fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="plus-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg><!-- <i class="fas fa-plus-circle fa-lg"></i> --></span> </h4> </a> </div> <div id="collapse2" class="panel-collapse collapse" aria-expanded="false"> <div class="panel-body"><dd><div class="views-element-container form-group"><div class="view view-profil-page-concours view-id-profil_page_concours view-display-id-block_1 js-view-dom-id-c93650dc04dbe389c2eebfbc710083ad849dc98a77b48f8161cbae68609b76fa"> <div class="view-header"> Résultat trouvé 0 </div> <div class="view-empty"> <p>Cet utilisateur n'a remporté aucun concours.</p> </div> </div> </div> </dd></div> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <a class="" data-toggle="collapse" data-parent="#accordion" href="#collapse3" aria-expanded="true"> <h4 class="panel-title"> <svg class="svg-inline--fa fa-object-group fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="object-group" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M480 128V96h20c6.627 0 12-5.373 12-12V44c0-6.627-5.373-12-12-12h-40c-6.627 0-12 5.373-12 12v20H64V44c0-6.627-5.373-12-12-12H12C5.373 32 0 37.373 0 44v40c0 6.627 5.373 12 12 12h20v320H12c-6.627 0-12 5.373-12 12v40c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12v-20h384v20c0 6.627 5.373 12 12 12h40c6.627 0 12-5.373 12-12v-40c0-6.627-5.373-12-12-12h-20V128zM96 276V140c0-6.627 5.373-12 12-12h168c6.627 0 12 5.373 12 12v136c0 6.627-5.373 12-12 12H108c-6.627 0-12-5.373-12-12zm320 96c0 6.627-5.373 12-12 12H236c-6.627 0-12-5.373-12-12v-52h72c13.255 0 24-10.745 24-24v-72h84c6.627 0 12 5.373 12 12v136z"></path></svg><!-- <i class="fas fa-object-group fa-lg"></i> --> Ses contenus <span class="badge">0</span> <span class="collapse-change-icon"><svg class="svg-inline--fa fa-plus-circle fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="plus-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg><!-- <i class="fas fa-plus-circle fa-lg"></i> --></span> </h4> </a> </div> <div id="collapse3" class="panel-collapse collapse in" aria-expanded="true" style=""> <div class="panel-body"><dd><div class="views-element-container form-group"><div class="view view-profil-page-contenu view-id-profil_page_contenu view-display-id-block_1 js-view-dom-id-5046ef4a9eab21dfa4bd430068e0d74db0486d12515e1007257e88d26ed3b55b"> <div class="view-header"> Résultat trouvé 0 </div> <div class="view-empty"> <p>Select any filter and click on Apply to see results</p> </div> </div> </div> </dd></div> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse4" aria-expanded="false"> <h4 class="panel-title"> <svg class="svg-inline--fa fa-gift fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="gift" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M488 192h-64.512C438.72 175.003 448 152.566 448 128c0-52.935-43.065-96-96-96-41.997 0-68.742 20.693-95.992 54.15C226.671 50.192 199.613 32 160 32c-52.935 0-96 43.065-96 96 0 24.566 9.28 47.003 24.512 64H24c-13.255 0-24 10.745-24 24v80c0 13.255 10.745 24 24 24h8v112c0 26.51 21.49 48 48 48h352c26.51 0 48-21.49 48-48V320h8c13.255 0 24-10.745 24-24v-80c0-13.255-10.745-24-24-24zm-208-32c24-56 55.324-64 72-64 17.645 0 32 14.355 32 32s-14.355 32-32 32h-72zM160 96c16.676 0 48 8 72 64h-72c-17.645 0-32-14.355-32-32s14.355-32 32-32zm48 128h96v184c0 13.255-10.745 24-24 24h-48c-13.255 0-24-10.745-24-24V224z"></path></svg><!-- <i class="fas fa-gift fa-lg"></i> --> Ses produits <span class="badge">0</span> <span class="collapse-change-icon"><svg class="svg-inline--fa fa-plus-circle fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="plus-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg><!-- <i class="fas fa-plus-circle fa-lg"></i> --></span> </h4> </a> </div> <div id="collapse4" class="panel-collapse collapse" aria-expanded="false"> <div class="panel-body"><dd><div class="views-element-container form-group"><div class="view view-profil-page-produit view-id-profil_page_produit view-display-id-block_1 js-view-dom-id-769f9d711f4e8bc30f68415fc4e177720959cfa4d0d5f65a817079d4cb41eb47"> <div class="view-header"> Résultat trouvé 0 </div> <div class="view-empty"> <p>Aucun produit n'a était publié.</p> </div> </div> </div> </dd></div> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse5" aria-expanded="false"> <h4 class="panel-title"> <svg class="svg-inline--fa fa-users fa-w-20 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="users" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 512" data-fa-i2svg=""><path fill="currentColor" d="M320 64c57.99 0 105 47.01 105 105s-47.01 105-105 105-105-47.01-105-105S262.01 64 320 64zm113.463 217.366l-39.982-9.996c-49.168 35.365-108.766 27.473-146.961 0l-39.982 9.996C174.485 289.379 152 318.177 152 351.216V412c0 19.882 16.118 36 36 36h264c19.882 0 36-16.118 36-36v-60.784c0-33.039-22.485-61.837-54.537-69.85zM528 300c38.66 0 70-31.34 70-70s-31.34-70-70-70-70 31.34-70 70 31.34 70 70 70zm-416 0c38.66 0 70-31.34 70-70s-31.34-70-70-70-70 31.34-70 70 31.34 70 70 70zm24 112v-60.784c0-16.551 4.593-32.204 12.703-45.599-29.988 14.72-63.336 8.708-85.69-7.37l-26.655 6.664C14.99 310.252 0 329.452 0 351.477V392c0 13.255 10.745 24 24 24h112.169a52.417 52.417 0 0 1-.169-4zm467.642-107.09l-26.655-6.664c-27.925 20.086-60.89 19.233-85.786 7.218C499.369 318.893 504 334.601 504 351.216V412c0 1.347-.068 2.678-.169 4H616c13.255 0 24-10.745 24-24v-40.523c0-22.025-14.99-41.225-36.358-46.567z"></path></svg><!-- <i class="fas fa-users fa-lg"></i> --> Ses groupes <span class="badge">0</span> <span class="collapse-change-icon"><svg class="svg-inline--fa fa-plus-circle fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="plus-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg><!-- <i class="fas fa-plus-circle fa-lg"></i> --></span> </h4> </a> </div> <div id="collapse5" class="panel-collapse collapse" aria-expanded="false"> <div class="panel-body"><dd><div class="views-element-container form-group"><div class="view view-profil-page-groupe view-id-profil_page_groupe view-display-id-block_1 js-view-dom-id-2e32ce43b15b99287bc35ff057edd6a6016a6e24603ee3f32329be118964bc97"> <div class="view-header"> Résultat trouvé 0 </div> <div class="view-empty"> <p>Select any filter and click on Apply to see results</p> </div> </div> </div> </dd></div> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <a class="collapsed" data-toggle="collapse" data-parent="#accordion" href="#collapse6" aria-expanded="false"> <h4 class="panel-title"> <svg class="svg-inline--fa fa-shopping-bag fa-w-14 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="shopping-bag" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 448 512" data-fa-i2svg=""><path fill="currentColor" d="M352 160v-32C352 57.42 294.579 0 224 0 153.42 0 96 57.42 96 128v32H0v272c0 44.183 35.817 80 80 80h288c44.183 0 80-35.817 80-80V160h-96zm-192-32c0-35.29 28.71-64 64-64s64 28.71 64 64v32H160v-32zm160 120c-13.255 0-24-10.745-24-24s10.745-24 24-24 24 10.745 24 24-10.745 24-24 24zm-192 0c-13.255 0-24-10.745-24-24s10.745-24 24-24 24 10.745 24 24-10.745 24-24 24z"></path></svg><!-- <i class="fas fa-shopping-bag fa-lg"></i> --> Ses boutiques <span class="badge">0</span> <span class="collapse-change-icon"><svg class="svg-inline--fa fa-plus-circle fa-w-16 fa-lg" aria-hidden="true" data-prefix="fas" data-icon="plus-circle" role="img" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 512 512" data-fa-i2svg=""><path fill="currentColor" d="M256 8C119 8 8 119 8 256s111 248 248 248 248-111 248-248S393 8 256 8zm144 276c0 6.6-5.4 12-12 12h-92v92c0 6.6-5.4 12-12 12h-56c-6.6 0-12-5.4-12-12v-92h-92c-6.6 0-12-5.4-12-12v-56c0-6.6 5.4-12 12-12h92v-92c0-6.6 5.4-12 12-12h56c6.6 0 12 5.4 12 12v92h92c6.6 0 12 5.4 12 12v56z"></path></svg><!-- <i class="fas fa-plus-circle fa-lg"></i> --></span> </h4> </a> </div> <div id="collapse6" class="panel-collapse collapse" aria-expanded="false"> <div class="panel-body"><dd><div class="views-element-container form-group"><div class="view view-profil-page-boutique view-id-profil_page_boutique view-display-id-block_1 js-view-dom-id-9f21023e83a67893ad096dcbb218ba8b477f895466709aba0b5f909f705b740d"> <div class="view-header"> Résultat trouvé 0 </div> <div class="view-empty"> <p>Aucune boutique n'a était publiée.</p> </div> </div> </div> </dd></div> </div> </div> </div> Here is my JS code. Something is wrong with it. (function ($) { $('.collapse').on('shown.bs.collapse', function () { $(this).find('.collapse-change-icon svg').removeClass("fa-plus-circle").addClass("fa-minus-circle"); }); $('.collapse').on('hidden.bs.collapse', function () { $(this).find('.collapse-change-icon svg').removeClass("fa-minus-circle").addClass("fa-plus-circle"); }); })(window.jQuery); I added a class "collapse-change-icon", but I do not know if it's useful and if it's well placed. A: The icon that you want to change isn't inside the .collapse DOM element. It's inside the .panel-heading element. (function ($) { $('.collapse').on('shown.bs.collapse', function () { $(this).parent().find('.panel-heading .collapse-change-icon svg').removeClass("fa-plus-circle").addClass("fa-minus-circle"); }); $('.collapse').on('hidden.bs.collapse', function () { $(this).parent().find('.panel-heading .collapse-change-icon svg').removeClass("fa-minus-circle").addClass("fa-plus-circle"); }); })(window.jQuery);
{ "pile_set_name": "StackExchange" }
Q: How to convert many-valued logic into efficient boolean logic? Suppose that I have a set S consisting of {0₁, ¯1₂, 0₂, 1₂, ¯2₃, ¯1₃, 0₃, 1₃, 2₃, ¯3₄, ¯2₄, ¯1₄, 0₄, 1₄, 2₄, 3₄}. I want to define the following operations over S: S < 0 which returns one if and only if S is negative. ¯S which returns the negation of S. S + 0 which returns S plus zero, which is S unchanged. S + 1 which returns the absolute value of S plus one, modulo the subscript. For example: Both ¯1₃ + 1 and 1₃ + 1 evaluate to 2₃. Both ¯2₃ + 1 and 2₃ + 1 evaluate to 0₃. The expression 0₃ + 1 evaluates to 1₃. S ¢ 0 which returns the carry of S + 0, which is zero. S ¢ 1 which returns the carry of S + 1, which is one if and only if S + 1 = 0ₙ for n > 1. This information can be captured in the form of a truth table: S S<0 ¯S S+0 S+1 S¢0 S¢1 ┌───┬───┬───┬───┬───┬───┬───┐ │ 0₁│ 0 │ 0₁│ 0₁│ 0₁│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │¯1₂│ 1 │ 1₂│¯1₂│ 0₂│ 0 │ 1 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 0₂│ 0 │ 0₂│ 0₂│ 1₂│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 1₂│ 0 │¯1₂│ 1₂│ 0₂│ 0 │ 1 │ ├───┼───┼───┼───┼───┼───┼───┤ │¯2₃│ 1 │ 2₃│¯2₃│ 0₃│ 0 │ 1 │ ├───┼───┼───┼───┼───┼───┼───┤ │¯1₃│ 1 │ 1₃│¯1₃│ 2₃│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 0₃│ 0 │ 0₃│ 0₃│ 1₃│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 1₃│ 0 │¯1₃│ 1₃│ 2₃│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 2₃│ 0 │¯2₃│ 2₃│ 0₃│ 0 │ 1 │ ├───┼───┼───┼───┼───┼───┼───┤ │¯3₄│ 1 │ 3₄│¯3₄│ 0₄│ 0 │ 1 │ ├───┼───┼───┼───┼───┼───┼───┤ │¯2₄│ 1 │ 2₄│¯2₄│ 3₄│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │¯1₄│ 1 │ 1₄│¯1₄│ 2₄│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 0₄│ 0 │ 0₄│ 0₄│ 1₄│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 1₄│ 0 │¯1₄│ 1₄│ 2₄│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 2₄│ 0 │¯2₄│ 2₄│ 3₄│ 0 │ 0 │ ├───┼───┼───┼───┼───┼───┼───┤ │ 3₄│ 0 │¯3₄│ 3₄│ 0₄│ 0 │ 1 │ └───┴───┴───┴───┴───┴───┴───┘ What I want to do is convert this many-valued truth table into a boolean truth table so that I can implement the operations using bitwise operators for parallelization. Sounds simple enough. Assign 0000 to 0₁, 0001 to ¯1₂, ..., 1111 to 3₄. Solve the resulting Karnaugh map to get a CNF or DNF expression and call it a day. Unfortunately, the resulting CNF or DNF expressions might not be efficient with this naive mapping of S to boolean values. I want to find the most efficient way to represent this many-valued truth table as a boolean truth table. Here, efficient means using the fewest operators to implement the various operations with preference being given to addition, negation, carry and comparison in that order. However, the problem is that there are 16! or 20922789888000 ways to map S to boolean values. Is there a better way to find the solution than brute force? A: I can't think of a general solution to this problem but here's a specific solution for my problem. We begin by diving the set S into two disjoint sets, S₁ and S₂. The set S₁ would contain 0₁ and the subscript ₄ elements. The set S₂ would contain the subscript ₂ and subscript ₃ elements: S₁ = {0₁, ¯3₄, ¯2₄, ¯1₄, 0₄, 1₄, 2₄, 3₄} S₂ = {¯1₂, 0₂, 1₂, ¯2₃, ¯1₃, 0₃, 1₃, 2₃} S = S₁ ∪ S₂ Now, we can solve this problem separately for S₁ and S₂. However, we want to do it in such a way that the solutions are similar. Thus, when we combine them we can take advantage of the similarity to reduce the number of operations involved. Here's the solution that I came up with: There are two things to notice about my solution: All the zero elements belong to the C'D' column. Hence, it's easy to select the rest of the elements using C+D. This will come in handy later. The negative elements are always in the B row, and in the same column as the corresponding positive elements. This makes negation and checking whether negative easy. Anyway, here are the operations implemented using bitwise operators where (A, B, C, D) ∈ S: (A, B, C, D) < 0 = B (C + D) ¯(A, B, C, D) = (A, B ^ (C + D), C, D) (A, B, C, D) + M = E = C D N = M' (A, B N + M E, C N + M (A ^ C ^ D ^ A E), D N + M D' (B + C)) (A, B, C, D) ¢ M = M D (A + C) The number of operations required for addition, carry, negation and comparison are 18, 3, 2 and 2 respectively. Notice that for negation we only need to modify B and for addition we don't need to modify A. Common subexpression elimination and xor operations are used reduce operations. I don't know whether it's possible to do better than this. This is the best solution that I came up with.
{ "pile_set_name": "StackExchange" }
Q: JavaScript changing images with onmouseover and onmouseout I've looked at similar questions and answers on Stack Overflow which I can't get to work. everything is find when the page loads but when I mouse over it doesn't show the new gif. When inspecting the code in the browser it seems to be switching between the two images. <!DOCTYPE html> <html> <head> <script> function normalImg() { document.getElementById("smile").src = "/smiley.gif" } function singing() { document.getElementById("smile").src = "/sing.gif" } </script> </head> <body> <img onmouseout="normalImg()" border="0" src="smiley.gif" alt="Smiley" width="32" height="32" id="smile" onmouseover="singing()" border="0" src="sing.gif" alt="singing" width="32" height="32"> <p>onmouse out and onmouseover changing images</p> </body> </html> A: you should have only one src attribute inside < img /> tag, you could try the code below: <!DOCTYPE html> <html> <head> <script> function singing() { document.getElementById("smile").src = "https://upload.wikimedia.org/wikipedia/commons/0/06/180717_%EC%97%B4%EB%A6%B0%EC%9D%8C%EC%95%85%ED%9A%8C_%ED%8A%B8%EC%99%80%EC%9D%B4%EC%8A%A4_%2818%29.jpg" document.getElementById("smile").alt="smiling" } function crying() { document.getElementById("smile").src = "https://upload.wikimedia.org/wikipedia/commons/c/cd/Chou_Tzuyu_at_the_Golden_Disc_Awards_2019.png" document.getElementById("smile").alt="crying" } </script> </head> <body> <img onmouseover="singing()" onmouseout="crying()" src="https://upload.wikimedia.org/wikipedia/commons/c/cd/Chou_Tzuyu_at_the_Golden_Disc_Awards_2019.png" alt="singing" width="100" height="100" id="smile"> <p>onmouse out and onmouseover changing images</p> </body> </html>
{ "pile_set_name": "StackExchange" }
Q: Block header format Does anyone understand what each element of a block header represents? I have an example block header represented here: [ cd7bd64fba4cc782fe5474d3640882afece5887180591e72f80ce6916cf73526, 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347, f927a40c8b7f6e07c5af7fa2155b4864a4112b13, 30430d24554454b251003be3d027dea94397bf45cd34c6a06abcfec662242046, 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421, 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421, 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000, 3b32b8463f, 1780, 1388, "", 55ba9f2d, "Geth/v1.0.0/linux/go1.4.2", 437fa41b15c73334a947241ec885423a487d4401a0c3ec7c30550c1e039bccd7, c5317acb884dfc49, ] What do each of these elements represent? Is there an official source that also definitively says what each of these values mean? A: You can find the block header's structure in the Yellow paper, 4.4 (page 5). I don't have time to go through eveyrthing, but if I do not make any mistake, for example, you could bind the following: cd7bd64fba4cc782fe5474d3640882afece5887180591e72f80ce6916cf73526 --> Parent hash 1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347 --> ommersHash f927a40c8b7f6e07c5af7fa2155b4864a4112b13 --> beneficiary 30430d24554454b251003be3d027dea94397bf45cd34c6a06abcfec662242046 --> stateRoot 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 --> transactionsRoot 56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421 --> receiptsRoot 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000 --> logsBloom 3b32b8463f --> difficulty 1780 --> Number of ancestor blocks 1388 --> gasLimit "" --> gasUsed 55ba9f2d --> timestamp "Geth/v1.0.0/linux/go1.4.2" --> ExtraData 437fa41b15c73334a947241ec885423a487d4401a0c3ec7c30550c1e039bccd7 --> mixHash c5317acb884dfc49 --> nonce From what I read of your example, this matches pretty well.
{ "pile_set_name": "StackExchange" }
Q: Sending bz2-compressed data as utf-8 string via gunicorn with Python 2.7 I am trying to use gunicorn to send a utf-8 encoded string, which is the result a bz2 compression, as the response to a get request. Here is my code on gunicorn server side: def app(environ, start_response): data = "Hello, World!" * 10 compressed_data = bz2.compress(data) start_response("200 OK", [("Content-Type", "text/plain"), ('charset', 'utf-8'), ("Content-Length", str(len(compressed_data))), ('Access-Control-Allow-Headers', '*'), ('Access-Control-Allow-Origin', '*'), # ('Content-Transfer-Encoding', 'BASE64'), ]) return iter([compressed_data]) and when I try to get the request from client side using Python requests package like this import bz2 import requests res = requests.get('http://127.0.0.1:8000') bz2.decompress(res.text) it is raising an exception UnicodeEncodeError: 'ascii' codec can't encode character u'\xab' in position 11: ordinal not in range(128) saying the response cant not be decoded when trying to print the text of response print(res.text) >>u'BZh91AY&SYy\xabm\x99\x00\x00\x13\x97\x80`\x04\x00@\x00\x80\x06\x04\x90\x00 \x00\xa5P\xd0\xda\x10\x03\x0e\xd3\xd4\xdai4\x9bO\x93\x13\x13\xc2b~\x9c\x17rE8P\x90y\xabm\x99' when printing the encoded text import bz2 print(bz2.compress("Hello, World!" * 10)) >> 'BZh91AY&SYy\xabm\x99\x00\x00\x13\x97\x80`\x04\x00@\x00\x80\x06\x04\x90\x00 \x00\xa5P\xd0\xda\x10\x03\x0e\xd3\xd4\xdai4\x9bO\x93\x13\x13\xc2b~\x9c\x17rE8P\x90y\xabm\x99' the only difference is the unicode sign, I am solving this issue by tweaking the data on the client side to make the response string decodeable, but I am wondering how I can solve this problem on the server side? A: The problem is that the string comes in as unicode. You should not be trying to interpret bz2 compressed data as text. See request docs on how to interpret the data as raw data rather than text: res.content # not res.text Additionally, the data should not be sent as text/plain in the first place. BZ2 compressed data is not text, and should be sent as application/octet-stream (i.e. byte stream). Quick hack to reinterpret text as byte stream (since the default ascii codec will not cope with bytes out of the range 0-127, we use ISO-8859-1 to encode the data. >>> text = u'BZh91AY&SYy\xabm\x99\x00\x00\x13\x97\x80`\x04\x00@\x00\x80\x06\x04\x90\x00 \x00 \xa5P\xd0\xda\x10\x03\x0e\xd3\xd4\xdai4\x9bO\x93\x13\x13\xc2b~\x9c\x17rE8P\x90y\xabm\x99' >>> byte_string = text.encode('ISO-8859-1') >>> byte_string 'BZh91AY&SYy\xabm\x99\x00\x00\x13\x97\x80`\x04\x00@\x00\x80\x06\x04\x90\x00 \x00 \xa5P\xd0\xda\x10\x03\x0e\xd3\xd4\xdai4\x9bO\x93\x13\x13\xc2b~\x9c\x17rE8P\x90y\xabm\x99' >>> bz2.decompress(byte_string) 'Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!Hello, World!' But ideally you should fix your data type. A: You can't send bzip2 compressed data as utf-8. It is binary data, it is not text. If your http client accepts bzip2 content-encoding (bzip2 is not standard) then you could sent a utf-8 encoded text compressed using bzip2: #!/usr/bin/env python import bz2 def app(environ, start_response): status = '200 OK' headers = [('Content-type', 'text/plain; charset=utf-8')] data = (u'Hello \N{SNOWMAN}\n' * 10).encode('utf-8') if 'bzip2' in environ.get('HTTP_ACCEPT_ENCODING', ''): # use bzip2 only if requested data = bz2.compress(data) headers.append(('Content-Encoding', 'bzip2')) headers.append(('Content-Length', str(len(data)))) start_response(status, headers) return data Example Uncompressed response: $ http -v 127.0.0.1:8000 GET / HTTP/1.1 Accept: */* Accept-Encoding: gzip, deflate Connection: keep-alive Host: 127.0.0.1:8000 User-Agent: HTTPie/0.9.2 HTTP/1.1 200 OK Connection: close Content-Length: 100 Content-type: text/plain; charset=utf-8 Date: Sun, 17 May 2015 18:47:50 GMT Server: gunicorn/19.3.0 Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ bzip2 compressed response if the client specifies that it accepts bzip2: $ http -v 127.0.0.1:8000 Accept-Encoding:bzip2 GET / HTTP/1.1 Accept: */* Accept-Encoding: bzip2 Connection: keep-alive Host: 127.0.0.1:8000 User-Agent: HTTPie/0.9.2 HTTP/1.1 200 OK Connection: close Content-Encoding: bzip2 Content-Length: 65 Content-type: text/plain; charset=utf-8 Date: Sun, 17 May 2015 18:48:23 GMT Server: gunicorn/19.3.0 +-----------------------------------------+ | NOTE: binary data not shown in terminal | +-----------------------------------------+ Here's corresponding http client that uses requests library: #!/usr/bin/env python from __future__ import print_function import bz2 import requests # $ pip install requests r = requests.get('http://localhost:8000', headers={'Accept-Encoding': 'gzip, deflate, bzip2'}) content = r.content print(len(content)) if r.headers['Content-Encoding'].endswith('bzip2'): # requests doesn't understand bzip2 content = bz2.decompress(content) print(len(content)) text = content.decode(r.encoding) print(len(text)) print(text, end='') Output 65 100 80 Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Otherwise (no non-standard accept-encoding), you should send your data as application/octet-stream as @icedtrees suggested: #!/usr/bin/env python import bz2 def app(environ, start_response): status = '200 OK' headers = [('Content-type', 'application/octet-stream')] data = bz2.compress((u'Hello \N{SNOWMAN}\n' * 10).encode('utf-8')) headers.append(('Content-Length', str(len(data)))) start_response(status, headers) return data Example $ http 127.0.0.1:8000 HTTP/1.1 200 OK Connection: close Content-Length: 65 Content-type: application/octet-stream Date: Sun, 17 May 2015 18:53:55 GMT Server: gunicorn/19.3.0 +-----------------------------------------+ | NOTE: binary data not shown in terminal | +-----------------------------------------+ bzcat accepts bzip2 content: $ http 127.0.0.1:8000 | bzcat Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ Hello ☃ The data is shown correctly because the terminal uses utf-8 encoding.
{ "pile_set_name": "StackExchange" }
Q: Prevent narrow svg paths from forming a block I'm trying to draw a bunch of narrow spaced paths, but sadly they always seem to form a grey block. Example: jsfiddle <svg overflow="hidden" width="200" height="200" style="width: 200px; height: 200px;"> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 164L 200 164"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 166L 200 166"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 168L 200 168"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 170L 200 170"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 172L 200 172"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 174L 200 174"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 176L 200 176"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 178L 200 178"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 180L 200 180"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 182L 200 182"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 184L 200 184"></path> <path stroke="rgb(0, 0, 0)" stroke-opacity="1" stroke-width="1" path="" d="M 100 186L 200 186"></path> </svg> Increasing/Decreasing the stroke-width only changes the color a bit. Inspect Elment from Chrome claims that these lines have a width of 2px. How can I get clear black 1px lines spaced by 1 white line? A: The problem is that the lines are being drawn with "half" pixel on the top and the other half on the bottom of the y coordinate. You can enclose the lines in a group element and apply <g transform="translate(0,0.5)">[your paths]</g> or apply the following CSS declaration: path {shape-rendering: crispEdges;}
{ "pile_set_name": "StackExchange" }
Q: How do I calculate mean value for each month in the dataset? Sample wind dataset: `.................RPT VAL ROS KIL SHA BIR DUB CLA MUL CLO BEL MAL DATE 1961-01-04 10.58 6.63 11.75 4.58 4.54 2.88 8.63 1.79 5.83 5.88 5.46 10.88 1961-01-05 13.33 13.25 11.42 6.17 10.71 8.21 11.92 6.54 10.92 10.34 12.92 11.83 1961-01-06 13.21 8.12 9.96 6.67 5.37 4.50 10.67 4.42 7.17 7.50 8.12 13.17 1961-02-07 13.50 14.29 9.50 4.96 12.29 8.33 9.17 9.29 7.58 7.96 13.96 13.79 1961-02-08 10.96 9.75 7.62 5.91 9.62 7.29 14.29 7.62 9.25 10.46 16.62 16.46 1961-03-04 10.58 6.63 11.75 4.58 4.54 2.88 8.63 1.79 5.83 5.88 5.46 10.88 1962-03-05 13.33 13.25 11.42 6.17 10.71 8.21 11.92 6.54 10.92 10.34 12.92 11.83 1962-06-06 13.21 8.12 9.96 6.67 5.37 4.50 10.67 4.42 7.17 7.50 8.12 13.17 1968-07-07 13.50 14.29 9.50 4.96 12.29 8.33 9.17 9.29 7.58 7.96 13.96 13.79 1968-07-08 10.96 9.75 7.62 5.91 9.62 7.29 14.29 7.62 9.25 10.46 16.62 16.46 1976-08-04 10.58 6.63 11.75 4.58 4.54 2.88 8.63 1.79 5.83 5.88 5.46 10.88 1976-08-05 13.33 13.25 11.42 6.17 10.71 8.21 11.92 6.54 10.92 10.34 12.92 11.83 1978-09-06 13.21 8.12 9.96 6.67 5.37 4.50 10.67 4.42 7.17 7.50 8.12 13.17 1978-09-07 13.50 14.29 9.50 4.96 12.29 8.33 9.17 9.29 7.58 7.96 13.96 13.79 1978-12-08 10.96 9.75 7.62 5.91 9.62 7.29 14.29 7.62 9.25 10.46 16.62 16.46` The Complete Dataset is [here][1]. In this dataset, the columns are the locations and the values are wind speeds. I want to calculate the wind speed for each month in the dataset. But I want to treat January 1961 and January 1962 as different months. I tried doing it with the for-loop. First I created a column name 'Month' and then I assigned the values using for-loop like this: `for i in range(len(data.index)): if data.index[i].month == 1: if data.index[i].year == 1961: data['Month'][i] = 'January 61' elif data.index[i].year == 1962: data['Month'][i] = 'January 62' else: data['Month'][i] = 'January' elif data.index[i].month == 2: data['Month'][i] = 'February' elif data.index[i].month == 3: data['Month'][i] = 'March' elif data.index[i].month == 4: data['Month'][i] = 'April' elif data.index[i].month == 5: data['Month'][i] = 'May' elif data.index[i].month == 6: data['Month'][i] = 'June' elif data.index[i].month == 7: data['Month'][i] = 'July' elif data.index[i].month == 8: data['Month'][i] = 'August' elif data.index[i].month == 9: data['Month'][i] = 'September' elif data.index[i].month == 10: data['Month'][i] = 'October' elif data.index[i].month == 11: data['Month'][i] = 'November' elif data.index[i].month == 12: data['Month'][i] = 'December'` And then I would use groupby on data['Month'] and then find the mean. But it's taking forever to run and I don't wanna have to wait for so long every time I run this program. How else could I have solved this problem? Note- The Actual data set isn't quite the same as the sample data set. I combined the columns ['Yr', 'Mo', 'Dy'] into one column named 'DATE', and then I made 'DATE' the index. And I have also removed all the NaN values using data.dropna(inplace=True). [1]: A: Try: df.index = pd.to_datetime(df.index) df.groupby([df.index.year, df.index.month]).mean() RPT VAL ROS ... CLO BEL MAL DATE DATE ... 1961 1 12.373333 9.333333 11.043333 ... 7.906667 8.833333 11.960 2 12.230000 12.020000 8.560000 ... 9.210000 15.290000 15.125 3 10.580000 6.630000 11.750000 ... 5.880000 5.460000 10.880 1962 3 13.330000 13.250000 11.420000 ... 10.340000 12.920000 11.830 6 13.210000 8.120000 9.960000 ... 7.500000 8.120000 13.170 1968 7 12.230000 12.020000 8.560000 ... 9.210000 15.290000 15.125 1976 8 11.955000 9.940000 11.585000 ... 8.110000 9.190000 11.355 1978 9 13.355000 11.205000 9.730000 ... 7.730000 11.040000 13.480 12 10.960000 9.750000 7.620000 ... 10.460000 16.620000 16.460
{ "pile_set_name": "StackExchange" }
Q: how to add tag in soap response Using gsoap I have generated server C++ codes. Using SoapUI, I send a message to server and get the response. Until here every thing is fine. I wanted to add more tags on the response. To do that, I have manipulated server codes. Originally the code generated by gsoap that produces the response is: if (soap_end_count(soap) || soap_response(soap, SOAP_OK) || soap_envelope_begin_out(soap) || soap_putheader(soap) || soap_body_begin_out(soap) || tempuri__IsAliveResponse.soap_put(soap, "tempuri:IsAliveResponse", "") || soap_body_end_out(soap) || soap_envelope_end_out(soap) || soap_end_send(soap)) return soap->error; This gives me the response below: <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tempuri="http://tempuri.org/"> <SOAP-ENV:Header/> <SOAP-ENV:Body> <tempuri:IsAliveResponse/> </SOAP-ENV:Body> </SOAP-ENV:Envelope> But when I want to add some tag more in the response: if (soap_end_count(soap) || soap_response(soap, SOAP_OK) || soap_envelope_begin_out(soap) || soap_putheader(soap) || soap_body_begin_out(soap) || tempuri__IsAliveResponse.soap_put(soap, "tempuri:IsAliveResponse", "") || tempuri__IsAliveResponse.soap_put(soap, "newTag", "") || soap_body_end_out(soap) || soap_envelope_end_out(soap) || soap_end_send(soap)) return soap->error; Then I get a cut, partial response: <?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ser="http://schemas.microsoft.com/2003/10/Serialization/" xmlns:tempuri="http://tempuri.org/"> <SOAP-ENV:Header></SOAP-ENV:Header> <SOAP-ENV:Body> <tempuri:IsAliveResponse></tempuri:IsAliveResponse> <newTag></newTag> </SOAP-ENV:Body> </ Then I have discovered that Content-Length: is always 524. Moreover, every character that I add is counted as 2. I do not see where is decided this fixed 524 length. Does it come from a buffer size? If so, how could I generate the code with larger buffer size? How could I add more data on response in a gsoap generated C++ soap server code? A: To add more parameter tags to the response is easy. Just edit the interface .h file (generated by wsdl2h). This file has a tempuri__IsAliveResponse class. Add more members to this class to add the response parameters you want. Then let soapcpp2 generate fresh source code with the additional params. These tags will appear within the IsAliveResponse tag. To create a response with multiple tags that aren't nested in IsAliveResponse, define a class with two leading underscores to make that class "invisible" to the serializer, for example class __tempuri__MyResponse. Then add the member tempuri__IsAliveResponse tempuri__IsAliveResponse_ (note the ending _ here to avoid a name clash) and other members that you want as tags. Use the new class __tempuri__MyResponse as the response type for the service operation.
{ "pile_set_name": "StackExchange" }
Q: Filter column / row data in matrix through user input - matlab I have an N x 3 matrix (double) with values in third column going in the interval 1:4, and only those four values. This matrix is saved as 'data', and will be used for further analysis after this filtering with the same name. How can I through user input (not popup) sort the rows with several conditions, eg I want to filter for rows with third column values with numbers 1 and 3 (or 1 and 2, or 1 and 2 and 4, or only 3 and so on)? I also have to take care of displaying an error message on invalid input (eg input is empty or invalid number like '6' as well as combinations of wrong inputs like filtering for '1', '2' and '7') and letting the user retry the input. I am using matlab. The matrix could look something like this 42.34 0.73713 1 25.387 0.8774 1 57.187 0.388 2 37.458 0.7095 2 34.227 0.6929 2 47.837 0.61363 2 30.852 0.65929 2 51.329 0.50498 3 29.501 0.77894 3 34.895 0.80504 3 26.243 0.73048 3 22.311 0.65362 3 14.769 0.17958 4 17.326 0.23037 4 41.557 0.38979 4 A: I this could work. The input could be a number or a vector, for example 1, [1 2] or [1:3] filter=[]; while isempty(filter) || ~isvector(filter) || ischar(filter) filter=input('Enter rows to filter: ') end index=[]; m=[[42.34 0.73713 1]; [25.387 0.8774 1]; [57.187 0.388 2]; [37.458 0.7095 2]; [34.227 0.6929 2]; [47.837 0.61363 2]; [30.852 0.65929 2]; [51.329 0.50498 3]; [29.501 0.77894 3]; [34.895 0.80504 3]; [26.243 0.73048 3]; [22.311 0.65362 3]; [14.769 0.17958 4]; [17.326 0.23037 4]; [41.557 0.38979 4]] for i=1:numel(filter) index=[index find(m(:,3)==filter(i))']; end m2=m(index,:) You can change the matrix definition for any matrix loaded as you stated in your question.
{ "pile_set_name": "StackExchange" }
Q: Extracting file list from remote gzipped tar file without downloading tar (getting "embedded nuls" error) I'm trying to get a file list (and then extract specific files) from a large (300-600 MB) remotely-hosted tar.gz file -- without downloading the entire file. However, I don't quite understand whether my file should be treated as binary or not, or how to get rid of embedded nuls without manipulating the file. I've seen questions that address remote gzipped binary files or untarring local gzipped files but not untarring remotely-hosted gzipped tar files. I've tried using gzfile: example.url <- "https://neon-microbial-raw-seq-files.s3.data.neonscience.org/2017/BMI_B69RN_ITS_R1_fastq.tar.gz" con <- gzfile(example.url) test.list <- utils::untar( tarfile = con, list = T) which returns: Error in readBin(con, "raw", n = 512L) : can only read from a binary connection If I run open(con, "rb"), I get an error saying the file doesn't exist. Opening the connection as binary without gzfile() instead gives an error about embedded nulls: bcon <- url("https://neon-microbial-raw-seq-files.s3.data.neonscience.org/2017/BMI_B69RN_ITS_R1_fastq.tar.gz") open(bcon, "rb") test.list <- utils::untar( tarfile = bcon, list = T) which returns: Error in rawToChar(block[seq_len(ns)]) : embedded nul in string: '\037\x8b\b\0\x9e\x9c\xbbZ\0\003\xec[is䶙\x9e\xcf\xfe\025\xfe\xc8\003\xea\xe6\t\x9eM\022\004\001T\xaa\034'\xb1\xb9\x95\xfd65\xb5\xf1Ʈ\xb5=\x8e=\xaeڟ\xbf\xef\001\xb2[Rk\xd4s9\x9br \x89\r\002 \xc0\026\037>\xef\x89\xc3\xf1p\x9c\xbex\xfd\xe3\u07ff\xf8\xee\xc7\xffy\xf1iJ\xc2\xe5\xa9\xcf$K' Lastly, using gzcon returns a different error involving embedded nulls: test.list <- utils::untar( tarfile = gzcon(url(example.url)), list = T) which returns: Error in rawToChar(block[seq_len(ns)]) : embedded nul in string: '././@LongLink\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\00000000\00000000\00000000\000000000201\000000000000\0011556\0 L\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0ustar \0root\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0root' Any help is appreciated! A: You can get the contents of the tar.gz by opening a binary read connection, wrapping it with gzcon and then using untar, as shown below. However, this does download the whole archive, since untar needs to read the whole file to see what's in it. There is no master directory in a tar file for untar to read; each file always has its own 512-byte header block. You don't need to save it to your hard disk to read the directory, but it may be just as easy to do so. example.url <- "https://neon-microbial-raw-seq-files.s3.data.neonscience.org/2017/BMI_B69RN_ITS_R1_fastq.tar.gz" con <- file(example.url, open = "rb") gzcon_con <- gzcon(con) untar(gzcon_con, list = TRUE) #> [1] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA10_ITS_R1.fastq" #> [2] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA11_ITS_R1.fastq" #> [3] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA12_ITS_R1.fastq" #> [4] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA1_ITS_R1.fastq" #> [5] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA2_ITS_R1.fastq" #> [6] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA3_ITS_R1.fastq" #> [7] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA4_ITS_R1.fastq" #> [8] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA5_ITS_R1.fastq" #> [9] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA6_ITS_R1.fastq" #> [10] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA7_ITS_R1.fastq" #> [11] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellA8_ITS_R1.fastq" #> [12] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB11_ITS_R1.fastq" #> [13] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB12_ITS_R1.fastq" #> [14] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB1_ITS_R1.fastq" #> [15] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB2_ITS_R1.fastq" #> [16] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB3_ITS_R1.fastq" #> [17] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB4_ITS_R1.fastq" #> [18] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB5_ITS_R1.fastq" #> [19] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB6_ITS_R1.fastq" #> [20] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB7_ITS_R1.fastq" #> [21] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB8_ITS_R1.fastq" #> [22] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellB9_ITS_R1.fastq" #> [23] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC10_ITS_R1.fastq" #> [24] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC11_ITS_R1.fastq" #> [25] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC12_ITS_R1.fastq" #> [26] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC1_ITS_R1.fastq" #> [27] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC2_ITS_R1.fastq" #> [28] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC3_ITS_R1.fastq" #> [29] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC4_ITS_R1.fastq" #> [30] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC5_ITS_R1.fastq" #> [31] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC6_ITS_R1.fastq" #> [32] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC7_ITS_R1.fastq" #> [33] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellC9_ITS_R1.fastq" #> [34] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD10_ITS_R1.fastq" #> [35] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD11_ITS_R1.fastq" #> [36] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD12_ITS_R1.fastq" #> [37] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD1_ITS_R1.fastq" #> [38] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD3_ITS_R1.fastq" #> [39] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD4_ITS_R1.fastq" #> [40] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD5_ITS_R1.fastq" #> [41] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD6_ITS_R1.fastq" #> [42] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD7_ITS_R1.fastq" #> [43] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD8_ITS_R1.fastq" #> [44] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellD9_ITS_R1.fastq" #> [45] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE10_ITS_R1.fastq" #> [46] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE11_ITS_R1.fastq" #> [47] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE12_ITS_R1.fastq" #> [48] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE1_ITS_R1.fastq" #> [49] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE2_ITS_R1.fastq" #> [50] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE4_ITS_R1.fastq" #> [51] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE5_ITS_R1.fastq" #> [52] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE6_ITS_R1.fastq" #> [53] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE7_ITS_R1.fastq" #> [54] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE8_ITS_R1.fastq" #> [55] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellE9_ITS_R1.fastq" #> [56] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF10_ITS_R1.fastq" #> [57] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF11_ITS_R1.fastq" #> [58] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF12_ITS_R1.fastq" #> [59] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF1_ITS_R1.fastq" #> [60] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF2_ITS_R1.fastq" #> [61] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF3_ITS_R1.fastq" #> [62] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF4_ITS_R1.fastq" #> [63] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF5_ITS_R1.fastq" #> [64] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF7_ITS_R1.fastq" #> [65] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF8_ITS_R1.fastq" #> [66] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellF9_ITS_R1.fastq" #> [67] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG10_ITS_R1.fastq" #> [68] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG11_ITS_R1.fastq" #> [69] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG12_ITS_R1.fastq" #> [70] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG1_ITS_R1.fastq" #> [71] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG2_ITS_R1.fastq" #> [72] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG3_ITS_R1.fastq" #> [73] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG4_ITS_R1.fastq" #> [74] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG5_ITS_R1.fastq" #> [75] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG6_ITS_R1.fastq" #> [76] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG7_ITS_R1.fastq" #> [77] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG8_ITS_R1.fastq" #> [78] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellG9_ITS_R1.fastq" #> [79] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH10_ITS_R1.fastq" #> [80] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH1_ITS_R1.fastq" #> [81] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH3_ITS_R1.fastq" #> [82] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH4_ITS_R1.fastq" #> [83] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH5_ITS_R1.fastq" #> [84] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH6_ITS_R1.fastq" #> [85] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH7_ITS_R1.fastq" #> [86] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH8_ITS_R1.fastq" #> [87] "hpc/home/minardsmitha/NEON/16S_ITS_Aug-Sept_2017/Sept_5_Run_B69RN/RAW_FASTQ/ITS/RAW_Upload_to_BOX/BMI_Plate1WellH9_ITS_R1.fastq"
{ "pile_set_name": "StackExchange" }
Q: Git tag for a subfolder of a repository I use Git to import a SVN repository. Then I created my own project as a subfolder in the repository. I use the SVN repository with Git-SVN. My working procedure is: git commit -am "message" git svn rebase git svn dcommit. Now I want to tag my project with git tag -a RC1 -m 'Release Candidate 1', but I only want that my project gets the tag. How can I do that? A: TL;DR version It's possible to tag specific directories (aka trees) if you know the tree's SHA-1, but it's not often done & not easy to do useful things with that tag. Long answer Every object in Git has a unique SHA-1. Most commonly, SHA-1s refer to commits, but they can also refer to blobs (file contents) and trees (directory structures & filenames/file-permission mappings). You can read about it in the Git Objects documentation. For example, suppose I'm in a particular directory in my repository. I can run git ls-tree HEAD to get the list of files/directories in my path, along with their SHA-1s: $git ls-tree HEAD 100644 blob ed76d466f5025ce88575770b07a65c49b281ca59 app.css 100644 blob ed58ee4a9be6f5b58e25e5b025b25e6d04549767 app.js 100644 blob e2bed82bd9554fdd89d982b37a8e0659fe82390a controllers.js 040000 tree f888c44e16f7811ba69a245adf35c4303cb0d4e7 data 100644 blob d68aa862e4746fc9abd0132cc576a4df266b0a9d directives.js 100644 blob df0ae0e7288617552b373d21f7796adb8fb0d1b6 index.html 040000 tree fa9c05b1bb45fb85821c7b1c27925b2618d646ac partials 100644 blob 28e9eb6fe697cb5039d1cb093742e90b739ad6af services.js I can then tag one of these trees (let's say the data directory above): $git tag data-1.0 f888c44e16f7811ba69a245adf35c4303cb0d4e7 The tag is now an alias for that SHA-1 and I can use it wherever a SHA-1 for a tree is accepted: $git ls-tree -rt data-1.0 100644 blob 6ab0a52a17d14cbc8e30c4bf8d060c4ff58ff971 file1.json 100644 blob e097e393fa72007b0c328d67b70ba1c571854db0 file2.json 040000 tree 39573c56941fdd2fc88747a96bf871550f4affb2 subfolder1 ... ... ... ... To get back the original SHA-1: $git rev-parse data-1.0 f888c44e16f7811ba69a245adf35c4303cb0d4e7 What good will all this do you? Not much as-is. However, if you're willing to write your own scripts to reconstruct the contents of a tree, or to find the commits containing a tree, then it might be useful to you. (e.g. this SO answer could be adapted for such a purpose). But like others have said, you'll probably have an easier time using a versioning/tagging model that's works better with Git, rather than trying to adapt your existing model. As already mentioned by shikjohari & others, if you want projects-within-a-project, which have their own versions, consider Git Submodules instead. A: You cannot. In Git, a tag by design always applies to the repository as a whole (just like commits and branches). This is unlike in Subversion, where a tag (being just a copy) can be applied to a subtree. BTW: Tagging a subtree is usually discouraged even in Subversion, because it can quickly become confusing just which part of the tree was tagged. Most sources I know (for example Version Control with Subversion recommend to always tag by copying trunk. About your problem: Usually, separate projects should get separate Git repositories. "Seperate" in this context usually means that you might want to branch / tag separately. If you do not / cannot do that, the best option is probably to use some tag prefix, and call all tags myproj-1.0, myproj-1.1 etc. A: This isn't possible with Git. A Git tag is a pointer to a specific commit, whereas a Subversion tag is a copy of any folder in the Subversion repository. The concept of tagging a single folder in Subversion doesn't carry over very well into Git. The problem is that your initial setup doesn't match Git's branching model. The way to do this in a Git-friendly manner would be to have a branch set up for your project, and then to tag commits on that branch. You've a couple of options: Tag the entire repository at a given point using git svn tag. Run git help svn for instructions on using this command. Tag the directory using regular Subversion commands. This doesn't need to involve downloading a Subversion working copy, since you can just run svn copy {URL to your project on the repository} {URL to your tag directory}, but you will need to install Subversion. Start a new Git clone of your Subversion repository in a whole new directory. Specify your project folder as the trunk URL, rather than the actual trunk. Git-svn will then treat that directory as your main branch and allow you to tag and copy it through Subversion.
{ "pile_set_name": "StackExchange" }
Q: apache rewrite rules, non-www, https I have two applications on the same server and use apache rewrite rules to redirect: www requests to non www http reuests to https Everything works ok, except one case: request www.test2.test.eu is redirect to https://www.test1.com content How can I konfigure it properly? Rewrites in domain test1.com config file: ServerName test1.com RewriteCond %{HTTP_HOST} ^www.test1.com$ [NC] RewriteRule ^(.*)$ https://www.test1.com/$1 [R=301] RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https:// %{SERVER_NAME}%{REQUEST_URI} Rewrites in domain test2.test.eu config file: ServerName test2.test.eu RewriteCond %{HTTP_HOST} ^www.test2.test.eu$ [NC] RewriteRule ^(.*)$ https://www.test2.test.eu/$1 [R=301] RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https:// %{SERVER_NAME}%{REQUEST_URI} Any suggestions very appreciated. Kind regards. A: i think your first vritualhost config is acting as the default for any request on hosts not matching 'test1.com' and 'test2.test.eu'. Try adding this ServerAlias line to see if it gets the request going to the proper config file. Rewrites in domain test2.test.eu config file: ServerName test2.test.eu ServerAlias www.test2.test.eu *.test2.test.eu RewriteCond %{HTTP_HOST} ^www.test2.test.eu$ [NC] RewriteRule ^(.*)$ https://www.test2.test.eu/$1 [R=301] RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https:// %{SERVER_NAME}%{REQUEST_URI} This explicitly tells apache that requests to 'www.test2.test.eu' should be handled by this configuration. The second entry on the ServerAlias with asterisk provides a wildcard so that even if the request comes for 'wwww.test2.test.eu' or 'xxx.test2.test.eu', the proper apache config will handle it. With using the wildcard, you could actually leave off the first entry, like this: ServerName test2.test.eu ServerAlias *.test2.test.eu RewriteCond %{HTTP_HOST} ^www.test2.test.eu$ [NC] RewriteRule ^(.*)$ https://www.test2.test.eu/$1 [R=301] RewriteCond %{SERVER_PORT} !^443$ RewriteRule ^.*$ https:// %{SERVER_NAME}%{REQUEST_URI} and it should work the same, although your first rewrite won't catch non-'www' hostnames either way.
{ "pile_set_name": "StackExchange" }
Q: How do I eliminate the "'str' object is not callable"? I get the following error on the code below, and have no idea what is going on. I'm very much a beginner and need some help. I am trying to make a very basic game of tic-tac-toe in the console, and am having trouble. Traceback (most recent call last): File "D:/Eric/Projects/Tic Tac Toe/Tic Tac Toe.py", line 68, in <module> printboard() File "D:/Eric/Projects/Tic Tac Toe/Tic Tac Toe.py", line 15, in printboard print("",c[0],"|",c[1],"|",c[2],"\n-----------\n",c[3],"|",c[4],"|",c[5],"\n-----------\n",c[6],"|",c[7],"|",c[8]) TypeError: 'str' object is not callable Code: import random, time #Variables c = [str(i) for i in range(1,10)] #Cells cpuletter = "string input" coinoptions = ["heads", "tails"] coinflip = random.choice(coinoptions) play = "" playercell = 0 #Functions def printboard(): #Prints the gameboard with the cell variables in the spaces print("",c[0],"|",c[1],"|",c[2],"\n-----------\n",c[3],"|",c[4],"|",c[5],"\n-----------\n",c[6],"|",c[7],"|",c[8]) return #Introduction print("Welcome to Tic Tac Toe. Below is the playing table.") #Welcome + Explanation printboard() print("The playing spaces are numbered 1 through 9.\nYou will use these numbers to refer to the places you would like to play your piece.\n") #X or O? playerletter = input("Would you like to be X's or O's?\n") playerletter = playerletter.capitalize() playerletter = playerletter[0] while playerletter not in ["X", "O"]: #Confirm choice == "X" or "O." If not, ask again. playerletter = input("""Sorry, that's not a valid option. Please choose "X" or "O."\n""") playerletter = playerletter.capitalize() playerletter = playerletter[0] if playerletter == "X": cpuletter = "O" elif playerletter == "O": cpuletter = "X" #Who goes first? playercoin = input("Randomizing who goes first:\nDo you choose heads or tails?\n") #Asking for "heads" or "tails" playercoin = playercoin.lower() while playercoin not in ["heads", "tails"]: #Confirm choice == "Heads" or "Tails." If not, ask again. playercoin = input("""Sorry, that's not a valid option. Please choose "heads" or "tails."\n""") playercoin = playercoin.lower() print("...") time.sleep(1) #Waits 1 seconds if coinflip != playercoin: #Tells player who goes first print("It landed " + coinflip + "! I will go first.") play = 0 elif coinflip == playercoin: print("It landed " + coinflip + "! You will go first.") play = 1 #Game input("""Ready to play? Press "Enter" to begin!\n""") if play == 0: random_index = random.randrange(9) #Randomly selects a cell to change to cpuletter c[random_index] = cpuletter print = ("Here is my move.") printboard() elif play == 1: #Allows player to choose cell to change to playerletter printboard() playercell = int(input("It's your turn. Type a cell number to choose where you play.\n")) playercell = playercell - 1 c[playercell] = playerletter printboard() Edit: Forgot to say that this only happens when the computer goes first, and not the player. I fixed the print = ("Here is my move.") but am still having problems. A: print = "Here is my move." That line reassigns the builtin print function to a string. Don't do that.
{ "pile_set_name": "StackExchange" }
Q: CSS selector for reCaptcha checkbok using Selenium and vba excel In the website I am trying to fill some fields, there is a checkbok that I need to click to add the check mark in it <div class="rc-anchor-content"><div class="rc-inline-block"><div class="rc-anchor-center-container"><div class="rc-anchor-center-item rc-anchor-checkbox-holder"><span class="recaptcha-checkbox goog-inline-block recaptcha-checkbox-unchecked rc-anchor-checkbox recaptcha-checkbox-expired" role="checkbox" aria-checked="false" id="recaptcha-anchor" dir="ltr" aria-labelledby="recaptcha-anchor-label" aria-disabled="false" tabindex="0"><div class="recaptcha-checkbox-border" role="presentation" style=""></div><div class="recaptcha-checkbox-borderAnimation" role="presentation" style=""></div><div class="recaptcha-checkbox-spinner" role="presentation" style="transform: rotate(180deg);"></div><div class="recaptcha-checkbox-spinnerAnimation" role="presentation" style=""></div><div class="recaptcha-checkbox-checkmark" role="presentation"></div></span></div></div></div><div class="rc-inline-block"><div class="rc-anchor-center-container"><label class="rc-anchor-center-item rc-anchor-checkbox-label" aria-hidden="true" role="presentation" id="recaptcha-anchor-label"><span aria-live="polite" aria-labelledby="recaptcha-accessible-status"></span>I'm not a robot</label></div></div></div> Using selenium in VBA I tried the following .FindElementByCss("div.recaptcha-checkbox-border").Click and also I tried .FindElementByCss("span.recaptcha-checkbox").Click But I got an error at this line Here's the link of the website to see the whole HTML https://www.moj.gov.kw/AR/E-Gov/Pages/eServices01.aspx A: To click() on the element, as the desired element is within an <iframe> so you have to: Induce a waiter and switch to the desired frame. Induce a waiter for the desired element to be clickable. You can use the following solution: .SwitchToFrame.FindElementByXPath("//iframe[contains(@src, 'recaptcha') and not(@title='recaptcha challenge')]", timeout:=10000) .FindElementByCss("div.recaptcha-checkbox-checkmark").Click You can find similar discussions in: How to click on the reCaptcha using Selenium and Java Find the reCAPTCHA element and click on it — Python + Selenium Here you can find a relevant discussion on Ways to deal with #document under iframe
{ "pile_set_name": "StackExchange" }
Q: Woocommerce Order API Line Item ID changes on update I’m retrieving Woocommerce orders via the "order updated" webhook and storing specific data in a separate database. We are also using a personalisations plugin which allows customers to add custom messages to products. This creates 2 separate line items, which would otherwise be the same product variation in the backend. On my separate database, when creating or updating a row, I need to use order_id, variation_id as well as the id entry (from line_items => id) to check whether a record must be created or updated. This ensure that 2 identical product variations with separate custom messages aren't overwritten by each other. On order create the following JSON response is sent. {"id":10656,"parent_id":0,"number":"10656","order_key":"wc_order_5a9815fa1add6","created_via":"checkout","version":"3.1.2","status":"pending","currency":"ZAR","date_created":"2018-03-01T17:02:18","date_created_gmt":"2018-03-01T15:02:18","date_modified":"2018-03-01T17:02:18","date_modified_gmt":"2018-03-01T15:02:18","discount_total":"0.00","discount_tax":"0.00","shipping_total":"0.00","shipping_tax":"0.00","cart_tax":"60.79","total":"495.00","total_tax":"60.79","prices_include_tax":true,"customer_id":5148,"customer_ip_address":"197.89.123.74","customer_user_agent":"mozilla\/5.0 (linux; android 6.0.1; samsung sm-g900h build\/mmb29k) applewebkit\/537.36 (khtml, like gecko) samsungbrowser\/6.4 chrome\/56.0.2924.87 mobile safari\/537.36","customer_note":"","billing":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA","email":"modackt@webmail.co.za","phone":"0828736647"},"shipping":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA"},"payment_method":"payfast","payment_method_title":"Pay With Your Card or Instant EFT.","transaction_id":"","date_paid":null,"date_paid_gmt":null,"date_completed":null,"date_completed_gmt":null,"cart_hash":"666062e6d9100aa43860fb71caef1466","meta_data":[{"id":506232,"key":"_store_location","value":"loop-street-cbd"},{"id":506233,"key":"_collection_date","value":"3 March, 2018"},{"id":506234,"key":"_collection_time","value":"10:00 AM"},{"id":506235,"key":"mailchimp_woocommerce_is_subscribed","value":"1"},{"id":506259,"key":"_billing_vat_number","value":""}],"line_items":[{"id":28607,"name":"Rainbow - Yes (add R50.00)","product_id":415,"variation_id":2590,"quantity":1,"tax_class":"","subtotal":"434.21","subtotal_tax":"60.79","total":"434.21","total_tax":"60.79","taxes":[{"id":1,"total":"60.79","subtotal":"60.79"}],"meta_data":[{"id":194971,"key":"transform-into-a-pinata","value":"Yes (add R50.00)"}],"sku":"N005-P","price":434.21,"_product_group":"rainbow-cakes"}],"tax_lines":[{"id":28609,"rate_code":"ZA-VAT-1","rate_id":1,"label":"VAT","compound":false,"tax_total":"60.79","shipping_tax_total":"0.00","meta_data":[]}],"shipping_lines":[{"id":28608,"method_title":"Local pickup","method_id":"local_pickup:10","total":"0.00","total_tax":"0.00","taxes":[],"meta_data":[{"id":194976,"key":"Items","value":"Rainbow - Yes (add R50.00) × 1"}]}],"fee_lines":[],"coupon_lines":[],"refunds":[]} The line_item => id, when the order is created is 28607 On order update the following JSON response is sent. {"id":10656,"parent_id":0,"number":"10656","order_key":"wc_order_5a9815fa1add6","created_via":"checkout","version":"3.1.2","status":"pending","currency":"ZAR","date_created":"2018-03-01T17:02:18","date_created_gmt":"2018-03-01T15:02:18","date_modified":"2018-03-01T17:02:18","date_modified_gmt":"2018-03-01T15:02:18","discount_total":"0.00","discount_tax":"0.00","shipping_total":"0.00","shipping_tax":"0.00","cart_tax":"60.79","total":"495.00","total_tax":"60.79","prices_include_tax":true,"customer_id":5148,"customer_ip_address":"197.89.123.74","customer_user_agent":"mozilla\/5.0 (linux; android 6.0.1; samsung sm-g900h build\/mmb29k) applewebkit\/537.36 (khtml, like gecko) samsungbrowser\/6.4 chrome\/56.0.2924.87 mobile safari\/537.36","customer_note":"","billing":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA","email":"modackt@webmail.co.za","phone":"0828736647"},"shipping":{"first_name":"Tasneem","last_name":"Modack","company":"","address_1":"","address_2":"","city":"","state":"","postcode":"","country":"ZA"},"payment_method":"payfast","payment_method_title":"Pay With Your Card or Instant EFT.","transaction_id":"","date_paid":null,"date_paid_gmt":null,"date_completed":null,"date_completed_gmt":null,"cart_hash":"666062e6d9100aa43860fb71caef1466","meta_data":[{"id":506232,"key":"_store_location","value":"loop-street-cbd"},{"id":506233,"key":"_collection_date","value":"3 March, 2018"},{"id":506234,"key":"_collection_time","value":"1:00 PM"},{"id":506235,"key":"mailchimp_woocommerce_is_subscribed","value":"1"},{"id":506256,"key":"_billing_vat_number","value":""}],"line_items":[{"id":28604,"name":"Rainbow - Yes (add R50.00)","product_id":415,"variation_id":2590,"quantity":1,"tax_class":"","subtotal":"434.21","subtotal_tax":"60.79","total":"434.21","total_tax":"60.79","taxes":[{"id":1,"total":"60.79","subtotal":"60.79"}],"meta_data":[{"id":194951,"key":"transform-into-a-pinata","value":"Yes (add R50.00)"}],"sku":"N005-P","price":434.21,"_product_group":"rainbow-cakes"}],"tax_lines":[{"id":28606,"rate_code":"ZA-VAT-1","rate_id":1,"label":"VAT","compound":false,"tax_total":"60.79","shipping_tax_total":"0.00","meta_data":[]}],"shipping_lines":[{"id":28605,"method_title":"Local pickup","method_id":"local_pickup:10","total":"0.00","total_tax":"0.00","taxes":[],"meta_data":[{"id":194956,"key":"Items","value":"Rainbow - Yes (add R50.00) × 1"}]}],"fee_lines":[],"coupon_lines":[],"refunds":[]} The line_item => id, when the order is updated is 28604 This will create an additional line item in the order on my system when in fact it is the same line item. Is there a reason why this happens, and is there a possible workaround? NOTE Dropping the rows and re-adding is not an options as the database on my system contains separate columns that are not related to Woocommerce. UPDATE According to the JSON response, specifically the "date_created", it appears that the "order created" webhook fires twice but on "order updated" it only fires once. A: This is definitely an issue with the personalization plugins you mentioned, because woocommerce on its own does not create a new line item on update as evident from the code below https://github.com/woocommerce/woocommerce/blob/master/includes/api/legacy/v2/class-wc-api-orders.php#L867 protected function set_line_item( $order, $item, $action ) { $creating = ( 'create' === $action ); // if ( $creating ) { $line_item = new WC_Order_Item_Product(); } else { $line_item = new WC_Order_Item_Product( $item['id'] ); } I would strongly recommend you to disable the customisation plugin and try.
{ "pile_set_name": "StackExchange" }
Q: How to find out the probability to enter a house? Let's assume there is $50\%$ of chances to someone's house entry door to be locked. A locksmith has $10$ keys, of which only 2 open the door. What is the probability of someone to enter the house through this door if he (or she) can choose by chance only one key among the ten? The question also asks to provide the sample space related to this random experiment. MY ATTEMPT I have obtained the following sample space \begin{align*} \Omega := & \{(K_{1},L^{c}),(K_{2},L^{c}),(K_{3},L^{c}),(K_{4},L^{c}),(K_{5},L^{c}),(K_{6},L^{c}),(K_{7},L^{c}),(K_{8},L^{c}),\\ & (K_{9},L^{c}),(K_{10},L^{c}),(K_{1},L),(K_{2},L),(K_{3},L),(K_{4},L),(K_{5},L),(K_{6},L),(K_{7},L),\\ &(K_{8},L),(K_{9},L),(K_{10},L)\} \end{align*} Where $K_{i}$ indicates the "choice of the $i$-th key" (for $1\leq i \leq 10$), $L^{c}$ indicates the door is open and $L$ indicates the door is locked. Since there are two keys which open the door, there are twelve cases in which the person can enter the house. Due to the fact that the outcomes have the same weight, the sought probability is given by \begin{align*} \mathbb{P}(E) = \frac{12}{20} = 0.6 \end{align*} Where $E$ indicates the event "the person has entered the house". Here I have used the fact that the events $K_{i}$ and $L$ are independent. Hence I'd like to ask: am I on the right track? Is there another way to obtain the right result? Could someone justify/rectify my argument? Any help is appreciated. Thanks in advance. A: The answer is correct although there is a more systematical approach to the problem in hand. Someone entering the house means that either the house is unlocked or the house is locked and the person chooses the right key. In terms of probability this means $$\begin{array}{crl}P(E) &=& P(house\ is\ unlocked) + P(house\ is\ locked)\cdot P(right\ key\ is\ chosen)\\ &=& \dfrac{1}{2}+\dfrac{1}{2}\cdot \dfrac{2}{10}\\&=& \dfrac{6}{10}\end{array}$$
{ "pile_set_name": "StackExchange" }
Q: How to interpret a t-sql deadlock trace I'm trying to sort out a deadlock by looking at the t-sql trace but I'm struggling to understand the information. I have a summary of the info here and then the full deadlock trace at the end of the post: The first lock is on a table called dbo.RetailVoucher The second lock is on a table called ooc.PlannedUniversalVoucher The 1st stored procedure reads the following tables: dbo.RetailVoucher, ooc.PlannedOrderItem and ooc.PlannedOrder. The 2nd stored procedure reads the following tables: ooc.PlannedBatch & ooc.PlannedUniversalVoucher Now, for the procedures to be waiting for each other, I thought they would both have to be reading the same table at some point. I obviously don't understand how to interpret the trace. Do I need to hunt down the source of the locks on dbo.RetailerVoucher and ooc.PlannedUniversalVoucher in other procedures? Thanks. Here's the full trace: <deadlock-list> <deadlock victim="process894748"> <process-list> <process id="process894748" taskpriority="0" logused="3064" waitresource="KEY: 8:72057594084655104 (845afc30a382)" waittime="944" ownerId="12987790066" transactionname="user_transaction" lasttranstarted="2014-04-10T19:07:02.250" XDES="0x803d53c0" lockMode="S" schedulerid="3" kpid="14356" status="suspended" spid="67" sbid="0" ecid="0" priority="0" trancount="3" lastbatchstarted="2014-04-10T19:07:02.287" lastbatchcompleted="2014-04-10T19:07:02.287" clientapp=".Net SqlClient Data Provider" hostname="ID13115" hostpid="4872" loginname="UVUser" isolationlevel="read committed (2)" xactid="12987790066" currentdb="8" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056"> <executionStack> <frame procname="UVSystem.ooc.PlannedPacketPreserveEVouchers" line="144" stmtstart="12286" stmtend="13618" sqlhandle="0x0300080039a18c7fa2ed9800dda200000100000000000000"> update dbo.RetailVoucher set QuantityInStock -= rvsum.QuantitySum from dbo.RetailVoucher urv join ( select oib.id, SUM(oib.Quantity) as QuantitySum from ( select coalesce(rv.RelatedVoucherId, rv.Id) id, oi.Quantity from ooc.PlannedOrderItem oi join ooc.PlannedOrder po on oi.PlannedOrderId = po.Id join RetailVoucher rv on oi.RetailVoucherId = rv.Id where po.PlannedPacketId = @PlannedPacketId and oi.PartnerId is null and oi.OnDmenadServiceId is null and rv.VoucherTypeId = 1 ) oib group by oib.Id ) rvsum on urv.Id = rvsum.id; </frame> </executionStack> <inputbuf> Proc [Database Id = 8 Object Id = 2139922745] </inputbuf> </process> <process id="processd0db8088" taskpriority="0" logused="10716" waitresource="PAGE: 8:1:778990" waittime="1078" ownerId="12987783115" transactionname="user_transaction" lasttranstarted="2014-04-10T19:07:01.473" XDES="0x144975950" lockMode="S" schedulerid="7" kpid="11172" status="suspended" spid="61" sbid="0" ecid="0" priority="0" trancount="2" lastbatchstarted="2014-04-10T19:07:01.473" lastbatchcompleted="2014-04-10T19:07:01.473" clientapp=".Net SqlClient Data Provider" hostname="ID13115" hostpid="12168" loginname="UVUser" isolationlevel="read committed (2)" xactid="12987783115" currentdb="8" lockTimeout="4294967295" clientoption1="673185824" clientoption2="128056"> <executionStack> <frame procname="UVSystem.ooc.OfflineOrdersImportPacket" line="294" stmtstart="23548" stmtend="24026" sqlhandle="0x030008006d6796551b829700dda200000100000000000000"> update ooc.PlannedBatch set IsCompleted = @True from ooc.PlannedBatch pb join ooc.PlannedUniversalVoucher puv on puv.PlannedBatchId = pb.Id left outer join @DuplicatedVouchers dv on dv.Id = puv.Id where dv.Id is null; </frame> </executionStack> <inputbuf> Proc [Database Id = 8 Object Id = 1435920237] </inputbuf> </process> </process-list> <resource-list> <keylock hobtid="72057594084655104" dbid="8" objectname="UVSystem.dbo.RetailVoucher" indexname="PK_RetailVoucher" id="lock10ccbd180" mode="X" associatedObjectId="72057594084655104"> <owner-list> <owner id="processd0db8088" mode="X"/> </owner-list> <waiter-list> <waiter id="process894748" mode="S" requestType="wait"/> </waiter-list> </keylock> <pagelock fileid="1" pageid="778990" dbid="8" objectname="UVSystem.ooc.PlannedUniversalVoucher" id="lock15ba81480" mode="IX" associatedObjectId="72057594113425408"> <owner-list> <owner id="process894748" mode="IX"/> </owner-list> <waiter-list> <waiter id="processd0db8088" mode="S" requestType="wait"/> </waiter-list> </pagelock> </resource-list> </deadlock> </deadlock-list> A: Let me try. You have tho processes, processd0db8088 and process894748. From the execution stack you can see that the process894748 was executing PlannedPacketPreserveEVouchers, and processd0db8088 is executing OfflineOrdersImportPacket. You can see the queries in question for both processes there as well. From resource list you can find out the resorces on which these two processes were deadlocked. First one is a particular index row in PK_RetailVoucher index on RetailVoucher table: processd0db8088 locked it exclusively and the process process894748 is waiting to gain shared lock on it. The other resource is a data page 778990 which belongs to PlannedUniversalVoucher table, held by process process894748 while processd0db8088 is waiting to gain read access to it. The locks could have been taken anywhere from start of transaction. The queries shown here in the execution stack are the queries that were waiting on the resources, not the ones that taken the locks. Inspect the whole execution trace to find out where the locks were actually taken. The standard advices apply: shorten transactions, access the tables in order, index appropriatelly.
{ "pile_set_name": "StackExchange" }
Q: Is the word typeable with keys adjacent to each other? Before reading this I suggest reading this little puzzle: https://puzzling.stackexchange.com/questions/11408/longest-word-with-adjacent-letters-on-a-keyboard I want you to make a program that takes one argument, a word (only lowercase letters), and outputs "Yes" if the word can be typed with adjacent keys on the keyboard (see the article) and "No" if the word can't be typed with adjacent letters. Here's the keyboard layout used in this challenge: ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ | Q | W | E | R | T | Y | U | I | O | P | └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┘ | A | S | D | F | G | H | J | K | L | └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┘ | Z | X | C | V | B | N | M | └───┴───┴───┴───┴───┴───┴───┘ Remember: this is codegolf so the the shortest answer wins! A: Pyth, 66 ?"Yes".Am>2sm^-.uk2Cm.Dx"qwertyuiopasdfghjkl*zxcvbnm"b9.5dC,ztz"No Try it here. I was surprised to learn Pyth doesn't have a hypotenuse function, so this will likely be beat by a different language. I'll propose a hypotenuse function to Pyth, so this atrocity won't happen in the future. Explanation I transform the keyboard into this: ┌───┬───┬───┬───┬───┬───┬───┬───┬───┬───┐ | Q | W | E | R | T | Y | U | I | O | P | └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┐ | A | S | D | F | G | H | J | K | L | * | └─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴─┬─┴───┴───┘ | Z | X | C | V | B | N | M | └───┴───┴───┴───┴───┴───┴───┘ Which I then encode as "qwertyuiopasdfghjkl*zxcvbnm". Then I used divmod with modulo 9.5 to figure out the 2D coordinates of every key. Then I compute distances between consecutive keys, and check if the squared distance < 2. A: CJam, 83 75 74 bytes l_1>]z["qwertyuiop asdfghjkl zxcvbnm "[__B>]z+s_W%+_]zsf{\#)}:*"Yes""No"? Try it online. Explanation The general approach is to produce a big adjacency string containing every pair of adjacent keyboard characters and then check that every pair of adjacent input characters is contained in that string. I'm quite happy with how I managed to build the adjacency string, which uses very simple and compact logic. l_1>]z "Read a line of input and create a list of every pair of adjacent input characters. There will be a trailing element of just the final character, but that's okay since any single lowercase letter can be found in the adjacency string."; ["qwertyuiop asdfghjkl zxcvbnm " "^ Create the in-row forward adjacency string."; [__B>]z "Create the alternating-row forward adjacency string by interleaving the in-row string with a substring of itself starting with the middle row letters: 'q w e r t y u i o p a s d f g h j k l zxcvbnm ' + ' a s d f g h j k l z x c v b n m '[no interleave here] ----------------------------------------------------- 'qawsedrftgyhujikolp azsxdcfvgbhnjmk l zxcvbnm '"; +s "Append the alternating-row forward adjacency string to the in-row forward adjacency string."; _W%+ "Append the reverse of the forward adjacency string (the backward adjacency string) to the forward adjacency string."; _]zs "Double every character in the adjacency string so every character is adjacent to itself."; f{\#)} "Map each pair of input characters to its 1-indexed location in the adjacency string (0 if not found)."; :* "Calculate the product of each pair's location in the adjacency string. This will be nonzero if and only if every pair of input characters are in fact adjacent."; "Yes""No"? "If the product is nonzero, produce 'Yes'; otherwise, produce 'No'."; "Implicitly print the result.";
{ "pile_set_name": "StackExchange" }
Q: What usage does 有 have in ~的有 (e.g. 偏向于data reseacher的有) In the following sentence over 知乎: 从我的观察来看,不同企业对于data scientist这个title的定义其实是有分歧的,偏向于data reseacher的有,多见于大型IT企业,百度大脑的data scientist们多属于这一类型,他们搞的是比较前沿的深度学习,平常会读大量paper可能自己也会发;偏向于data creative的有,各种企业都会储备,会ETL,懂模型、懂行业,会展示沟通,比较能够创造直接的价值。偏向于data developer的也有但是很少,他们不懂模型,只要给他们算法公式,他们就能用编程语言帮你实现,实现算法是重要的技能,但是这种不懂模型不懂行业的,现在大多企业都不太会给这样的人data scientist的title了。 The grammar book does not seem to have this usage of 有. I feel that the meaning is similar to 关于 or 至于 (at least in this context), so the relevant sentence above can be rewritten as follows: 关于偏向于data researcher (or suffix "的话" here?), 关于data developer,虽然他们比减少, However, grammatically how does 有 work here? I just check out the Chinese grammar wiki but didn't find any relevant pages. A: I am a native speaker and consider myself a "data" person. From my perspective, he didn't end the sentence properly and his array of sentences could be changed a bit like below so it's easier to understand. 从我的观察来看,不同企业对于data scientist这个title的定义其实是有分歧的。 有偏向于data reseacher的,多见于大型IT企业。百度大脑的data scientist们多属于这一类型,他们搞的是比较前沿的深度学习,平常会读大量paper可能自己也会发文章。 The purpose of 有...的 is to illustrate his/her point using example(s).
{ "pile_set_name": "StackExchange" }
Q: How to extract a link from the embedded link with python? I have a string like this: <iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2FDoctorTaniya%2Fposts%2F1906676949620646&width=500" width="500" height="482" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe> I want to extract link: www.facebook.com/DoctorTaniya/posts/1906676949620646 How to write a python script to do this? A: I think it would be better to use beautiful soup instead. The text to parse is an iframe tag with the src. You are trying the retrieve the url after href= and before &width in the src attribute. After that, you would need to decode the url back to text. First, you throw it into beautiful soup and get the attribute out of it: text = '<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2FDoctorTaniya%2Fposts%2F1906676949620646&width=500" width="500" height="482" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>' soup = BeautifulSoup(text) src_attribute = soup.find("iframe")["src"] And then there you could use regex here or use .split() (quite hacky): # Regex link = re.search('.*?href=(.*)?&', src_attribute).group(1) # .split() link = src_attribute.split("href=")[1].split("&")[0] Lastly, you would need to decode the url using urllib2: link = urllib2.unquote(link) and you are done! So the resulting code would be: from bs4 import BeautifulSoup import urllib2 import re text = '<iframe src="https://www.facebook.com/plugins/post.php?href=https%3A%2F%2Fwww.facebook.com%2FDoctorTaniya%2Fposts%2F1906676949620646&width=500" width="500" height="482" style="border:none;overflow:hidden" scrolling="no" frameborder="0" allowTransparency="true"></iframe>' soup = BeautifulSoup(text) src_attribute = soup.find("iframe")["src"] # Regex link = re.findall('.*?href=(.*)?&', src_attribute)[0] # .split() link = src_attribute.split("href=")[1].split("&")[0] link = urllib2.unquote(link)
{ "pile_set_name": "StackExchange" }
Q: Bitminter - no rewards when more work was done? Very new to this concept, why would something like this occur on Bitminter's pool? Completed Duration Difficulty Pay/Hour at 1 TH/s Total Thps Your Ghps Your work 2014-10-25 15:02 1h 46m 35,985,640,265 being paid now 2,436.1 10.7 15,856 2014-10-25 13:15 2h 15m 35,985,640,265 being paid now 1,896.0 10.9 20,718 2014-10-25 10:59 2h 13m 35,985,640,265 being paid now 1,935.6 10.4 19,340 2014-10-25 08:45 2h 26m 35,985,640,265 being paid now 1,767.4 10.2 20,756 2014-10-25 06:18 2h 30m 35,985,640,265 being paid now 1,721.0 10.3 21,688 2014-10-25 03:48 2h 11m 35,985,640,265 being paid now 1,951.9 10.2 18,872 2014-10-25 01:36 2h 36m 35,985,640,265 being paid now 1,646.6 10.4 22,722 2014-10-24 22:59 2h 35m 35,985,640,265 being paid now 1,653.5 10.2 22,314 2014-10-24 20:23 2h 37m 35,985,640,265 being paid now 1,641.0 10.9 24,036 2014-10-24 17:46 2h 36m 35,985,640,265 being paid now 1,649.8 10.8 23,620 2014-10-24 15:09 2h 35m 35,985,640,265 ? 1,664.1 10.6 22,992 2014-10-24 12:34 2h 37m 35,985,640,265 0.00000000 1,642.0 10.0 21,882 2014-10-24 09:56 2h 36m 35,985,640,265 0.00000000 1,650.2 10.3 22,502 2014-10-24 07:20 2h 29m 35,985,640,265 0.00000000 1,724.3 10.4 21,844 2014-10-24 04:50 2h 09m 35,985,640,265 0.00000000 1,996.7 8.5 15,322 2014-10-24 02:40 2h 34m 35,985,640,265 0.00057673 1,673.0 0.2 432 2014-10-24 00:06 2h 26m 35,985,640,265 0.00057673 1,756.1 0.2 354 2014-10-23 21:38 1h 41m 35,985,640,265 0.00057673 2,544.7 0.2 222 2014-10-23 19:57 1h 34m 35,985,640,265 0.00057673 2,736.5 0.2 212 2014-10-23 18:22 2h 00m 35,985,640,265 0.00057673 2,135.9 0.2 284 In some cases, next to no work was done - and small reward was found. In others, far more was contributed, but the pay is zero. I ask on the heels of switching from cgminer to bfgminer; could this be the cause? Is the timing otherwise purely circumstantial? Thanks! A: When a block is found the 10 latest shifts get paid. Finding blocks is a random event. Sometimes we find the next block quickly, other times it takes longer. Sometimes it happens that it takes a lot of work before the next block is found by the pool. With PPLNS what then happens is that some of the work is not paid at all. The opposite happens when many blocks are found in quick succession. The same work gets paid many times and the pay is extremely good. Over time this evens out. This is the nature of mining. If you were mining solo instead of in a pool the variance would be much greater. You could find a block and get 25 bitcoins after a few seconds. Or it could take you several years.
{ "pile_set_name": "StackExchange" }
Q: iterate over a Json file and insert into db in Python {"groupId":"org.springframework","artifactId":"spring-jcl","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.1.2.RELEASE/f0d7165b6cfb90356da4f25b14a6437fdef1ec8a/spring-jcl-5.1.2.RELEASE.jar","dependencies":[]}]}]}, {"groupId":"org.springframework","artifactId":"spring-beans","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.1.2.RELEASE/5d513701a79c92f0549574f5170a05c4af7c893d/spring-beans-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-core","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.1.2.RELEASE/b9b00d4075c92761cfd4e527e0bdce1931b4f3dc/spring-core-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-jcl","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.1.2.RELEASE/f0d7165b6cfb90356da4f25b14a6437fdef1ec8a/spring-jcl-5.1.2.RELEASE.jar","dependencies":[]}]}]}, {"groupId":"org.springframework","artifactId":"spring-expression","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-expression/5.1.2.RELEASE/3c16b062785e4c101db6b754fcb34a77c1e912c/spring-expression-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-core","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.1.2.RELEASE/b9b00d4075c92761cfd4e527e0bdce1931b4f3dc/spring-core-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-jcl","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.1.2.RELEASE/f0d7165b6cfb90356da4f25b14a6437fdef1ec8a/spring-jcl-5.1.2.RELEASE.jar","dependencies":[]}]}]}, {"groupId":"org.springframework","artifactId":"spring-core","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.1.2.RELEASE/b9b00d4075c92761cfd4e527e0bdce1931b4f3dc/spring-core-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-jcl","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.1.2.RELEASE/f0d7165b6cfb90356da4f25b14a6437fdef1ec8a/spring-jcl-5.1.2.RELEASE.jar","dependencies":[]}]}]}, {"groupId":"org.springframework","artifactId":"spring-web","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-web/5.1.2.RELEASE/3ff2a93b072da42c3930225e3dceeabb0678eb0b/spring-web-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-beans","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-beans/5.1.2.RELEASE/5d513701a79c92f0549574f5170a05c4af7c893d/spring-beans-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-core","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.1.2.RELEASE/b9b00d4075c92761cfd4e527e0bdce1931b4f3dc/spring-core-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-jcl","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.1.2.RELEASE/f0d7165b6cfb90356da4f25b14a6437fdef1ec8a/spring-jcl-5.1.2.RELEASE.jar","dependencies":[]}]}]}, {"groupId":"org.springframework","artifactId":"spring-core","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-core/5.1.2.RELEASE/b9b00d4075c92761cfd4e527e0bdce1931b4f3dc/spring-core-5.1.2.RELEASE.jar","dependencies":[ {"groupId":"org.springframework","artifactId":"spring-jcl","version":"5.1.2.RELEASE","file":"/home/howie/.gradle/caches/modules-2/files-2.1/org.springframework/spring-jcl/5.1.2.RELEASE/f0d7165b6cfb90356da4f25b14a6437fdef1ec8a/spring-jcl-5.1.2.RELEASE.jar","dependencies":[]}]}]}]}] output, error = process.communicate() data = json.loads(output.decode('UTF-8')) page = open("JSON/Java.json", "r") parsed = json.loads(page.read()) for v in parsed['groupId'].values(): if isinstance(v, dict): db_entry = {} db_entry['artifactId'] = v['artifactId'] db_entry['version'] = v['version'] db_entry['repo_id'] = repo_id dep_coll.insert_one(db_entry) else: raise ValueError("object is not dictionary") hi i am trying to import a json file on iterate over it so that certain values are inserted into a db. In this case i need artifactid, version insertred. The json file has a list so i would have multiple inserts. I think i am on the right track , any help would be greatly appreciated. At the moment this is the error i am getting for v in parsed['groupId'].values(): TypeError: list indices must be integers or slices, not str A: 'parsed' is a list and not a dict. It contains dicts. Each dict contains a field named 'groupId'. So your code should look like. Upload "JSON/Java.json" to a public location if the code below does not work for you. for entry in parsed: # entry is a dict - do something with it
{ "pile_set_name": "StackExchange" }
Q: Why does a select query require an IX lock? While inspecting the deadlock graph below, I found that a SELECT query (only query inside the SP being executed by the first process process569f048) and an UPDATE query forming a deadlock; and the SELECT query is requiring an IX lock. In what situation such locks are necessary for a SELECT? What can I do to avoid the deadlock? Here is the SELECT query: SELECT TOP (@p_takeCount) t.Id ,s.Column2 ,t.STATUS ,t.Column3 ,t.Column4 FROM Table2 t WITH (INDEX (IX_Table2)) INNER JOIN Table1 s ON s.Id = t.ParentId WHERE t.STATUS != 0 AND t.Column5 IS NULL AND s.SomeId = @p_someId AND s.Category = 2 ORDER BY t.id Here is the plan: Here is the UPDATE query: update Table2 set [Status] = @0, Column5 = null, Column6 = @1 where ([Id] = @2) Here is the plan: Here is the deadlock graph: <deadlock> <victim-list> <victimProcess id="process569f048" /> </victim-list> <process-list> <process id="process569f048" taskpriority="0" logused="0" waitresource="PAGE: 5:1:3017144" waittime="2867" ownerId="964271246" transactionname="SELECT" lasttranstarted="2017-01-29T10:10:49.643" XDES="0x800f9d20" lockMode="S" schedulerid="10" kpid="10108" status="suspended" spid="70" sbid="2" ecid="2" priority="0" trancount="0" lastbatchstarted="2017-01-29T10:10:49.643" lastbatchcompleted="2017-01-29T10:10:49.643" clientapp="EntityFramework" hostname="LOCALHOST" hostpid="4936" isolationlevel="read committed (2)" xactid="964271246" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056"> <executionStack> <frame procname="" line="17" stmtstart="1298" stmtend="1954" sqlhandle="0x03000500d21f5e3dd6d19700cca400000100000000000000" /> </executionStack> <inputbuf /> </process> <process id="process8ee3dc8" taskpriority="0" logused="17956" waitresource="PAGE: 5:1:3017343" waittime="2864" ownerId="964271345" transactionname="user_transaction" lasttranstarted="2017-01-29T10:10:49.667" XDES="0xafdbb03b0" lockMode="IX" schedulerid="17" kpid="9468" status="suspended" spid="61" sbid="2" ecid="0" priority="0" trancount="2" lastbatchstarted="2017-01-29T10:10:49.703" lastbatchcompleted="2017-01-29T10:10:49.703" clientapp="EntityFramework" hostname="LOCALHOST" hostpid="20696" loginname="dbuser_d" isolationlevel="read committed (2)" xactid="964271345" currentdb="5" lockTimeout="4294967295" clientoption1="671088672" clientoption2="128056"> <executionStack> <frame procname="" line="1" stmtstart="74" sqlhandle="0x02000000403aaa03bd8879de1c73d49641f1f81b6ca095af" /> <frame procname="" line="1" sqlhandle="0x000000000000000000000000000000000000000000000000" /> </executionStack> <inputbuf> (@0 tinyint,@1 varchar(64),@2 bigint)update [dbo].[Table2] set [Status] = @0, [Column5] = null, [Column6] = @1 where ([Id] = @2) </inputbuf> </process> </process-list> <resource-list> <pagelock fileid="1" pageid="3017144" dbid="5" objectname="" id="lockc296c6380" mode="IX" associatedObjectId="72057594073317376"> <owner-list> <owner id="process8ee3dc8" mode="IX" /> </owner-list> <waiter-list> <waiter id="process569f048" mode="S" requestType="wait" /> </waiter-list> </pagelock> <pagelock fileid="1" pageid="3017343" dbid="5" objectname="" id="lockd33965a80" mode="S" associatedObjectId="72057594073317376"> <owner-list> <owner id="process569f048" mode="S" /> </owner-list> <waiter-list> <waiter id="process8ee3dc8" mode="IX" requestType="wait" /> </waiter-list> </pagelock> </resource-list> </deadlock> Index details: [PK_Table2] PRIMARY KEY CLUSTERED ([Id] ASC); [IX_Table2]([Column5] ASC, [Status] ASC) INCLUDE ( [Id],[ParentId],[Column3],[Column4]) WHERE ([Column5] IS NULL); Object with id 72057594073317376 (associatedObjectId) is: [IX_Table2] A: Locks are always necessary for selects, as long as you're not using dirty reads. The update query changes the index. Would you really want the select query not to even notice the index changed? You'd just get random nonsense from your queries once in a while (in fact, exactly in the scenario you have here - instead of a deadlock, you'd get malformed data). Of course, a select doesn't usually take an exclusive lock - and even in this case, you can see that the lock is shared, not exclusive. But that still means that anyone who wants to write to that data, can't. And the update statement needs to do exactly that - while at the same time holding an exclusive lock on the index, which the select needs to complete. Deadlocks cannot be avoided in general. They're an expected behaviour you should be prepared for - the typical response in your application should be to repeat the transaction when you get the 1205 error. This is a compromise between performance and convenience, without jeopardising correctness. The process that gets the error is chosen at random, so you need this on both the reads and writes. In your case, it's obvious that you're changing the clustered index - that's usually a bad idea, and leads to plenty of deadlock opportunities (after all, you're rebuilding the table, at least partially). Consider changing your indices to be more in line with what reads and write your application is actually doing. If it happens often, it will also likely be bad for performance. EDIT: Actually, it seems that the locks are on two pages of IX_Table2 - the one where the key used to be, and the one where it needs to be after the change. The two locks are taken in a sequence, and in a different order from the select. Given the layout of the index, this is going to happen relatively often - since both statements deal with Column5 that is null. I don't think it's really avoidable in this case - maybe you could tweak the index layout a bit, but that really only makes sense if the deadlocks pose actual problems - if you only lose a few seconds every day or less, it's likely wasted effort and with likely negative side-effects. For more information about analysing and solving deadlocks on MS SQL, try How to resolve a deadlock. If you need more info to solve your problem, consult with your DBA, and consider posting a question on DBA Stack Exchange - make sure to include all the necessary information, including at least the DDL for the table involved, including the indices. Use sp_help to translate the object ids in the deadlock report to the actual names in your DDL.
{ "pile_set_name": "StackExchange" }
Q: Derive a 2D recurrence from a set of linear recurrences Given a set of high-order linear recurrences: $A(1, n): 0, 1, 0, 1, 0, ...$ $A(2, n): a_{n} = 2a_{n-2} - a_{n-4}$ $A(3, n): b_{n} = 3b_{n-2} - 3b_{n-4} + b_{n-6}$ $A(4, n): c_{n} = 4c_{n-2} - 6c_{n-4} + 4c_{a-6} - c_{n-8}$ ans so on. I want to derive 2D recurrence for $A(m, n)$. Obviously, each of linear recurrences has a characteristic polynomial $(x^2 - 1)^m$ (due to coefficients representing terms of row $m$ of Pascal's triangle). Moreover, each of that recurrences has more or less "nice" explicit formula. So: Is it possible to derive 2D recurrence? If not, is it possible to derive general explicit formula for that recurrences? EDIT: Initial values (offset starts from $1$) are: $A(2, n): 0,3,0,7$ $A(3, n): 0,6,3,31,10,76$ $A(4, n): 0,10,21,117,122,448,367,1131$ $A(5, n): 0,16,89,439,906,2630,3907,9037,11380,23196$ The main problem is that I don't know which initial values would be for $A(m, n)$. So I need a way to generalize it. A: The ordinary generating function (OGF for short) of $A(m,n)$, for fixed $m$, is $$F_m(x):=\frac{P_m(x)}{(x^2-1)^m},$$ where $P_m(x)$ is a polynomial of degree $\leq m$. Since you are interested in $2D$ recursion of $A(m, n)$, we also want to consider the OGF of $A(m+1, n)$, that is $$F_{m+1}(x) := \frac{P_{m+1}(x)}{(x^2-1)^{m+1}}.$$ We obtain $$F_{m+1}(x) = \frac{P_{m+1}(x)F_m(x)}{P_m(x)(x^2-1)}.$$ Suppose $Q(x) = \frac{P_{m+1}(x)}{P_m(x)(x^2-1)} = q_0 + q_1x + q_2x^2 + \dots$. Then $$A(m+1, n) = [x^n]F_{m+1}(x) = [x^n]Q(x)F_m(x) = q_0A(m,n)+q_1A(m,n-1) + \dots + q_nA(m,0).$$ Example: The OGF of $A(1,n): 0, 1, \dots$ is $\frac{x}{1-x^2}$ and the OGF of $A(2,n): 0,3,0,7,\dots$ is $\frac{3x+x^3}{(1-x^2)^2}$. Then $Q(x)=\frac{3+x^2}{1-x^2}=3+4x^2+4x^4+4x^6+\dots$ and so $$A(2,n) = 3A(1,n) + 4A(1,n-2) + 4A(1,n-4) + 4A(1,n-6) + \dots,$$ and so $A(2,6)=3A(1,6)+4A(1,4)+4A(1,2)+4A(1,0) = 0$ as $A(1,0)=A(1,2)=A(1,4)=A(1,6)=0$.
{ "pile_set_name": "StackExchange" }
End of preview. Expand in Data Studio
README.md exists but content is empty.
Downloads last month
5