[["Q:\n\nInterpolate between observations (piecewise approximation) R\n\nI'm comparing some forecast data against actual values. The forecasts are obtained from three different providers. However, the time stamps for the actual data and the forecast data are not the same. I want to compare the error for each point where are forecast was made. \nIn the below snapshot, I'd like to get the difference of the forecast for each providers forecast from the actual value. The encircled points represent forecasts for which the actual data is not available but we can see there is a distinct trend. I think I would be okay with a piecewise approximation but i'm not sure how to do that. I've seen the answers posted in Need a R package for piecewise linear regression? but it's not very helpful. \n10-day sample:\n\n1-day sample showing the offset b/w forecast instances and actual data:\n\nsample data (for 1 day)\n> dput(dt)\nstructure(list(tme = structure(c(1516221000, 1516224600, 1516228200, \n1516231800, 1516235400, 1516239000, 1516242600, 1516246200, 1516249800, \n1516253400, 1516257000, 1516260600, 1516264200, 1516267800, 1516271400, \n1516275000, 1516278600, 1516282200, 1516285800, 1516289400, 1516293000, \n1516296600, 1516300200, 1516303800, 1516307400, 1516226400, 1516230000, \n1516233600, 1516237200, 1516240800, 1516244400, 1516248000, 1516251600, \n1516255200, 1516258800, 1516262400, 1516266000, 1516269600, 1516273200, \n1516276800, 1516280400, 1516284000, 1516287600, 1516291200, 1516294800, \n1516298400, 1516302000, 1516305600, 1516221000, 1516224600, 1516228200, \n1516231800, 1516235400, 1516239000, 1516242600, 1516246200, 1516249800, \n1516253400, 1516257000, 1516260600, 1516264200, 1516267800, 1516271400, \n1516275000, 1516278600, 1516282200, 1516285800, 1516289400, 1516293000, \n1516296600, 1516300200, 1516303800, 1516307400, 1516233600, 1516244400, \n1516255200, 1516266000, 1516276800, 1516287600, 1516298400), tzone = \"UTC\", class = c(\"POSIXct\", \n\"POSIXt\")), degc = c(2.25, 1.69, 2.22, 2.22, 1.65, 1.12, 2.22, \n1.1, 1.13, 2.82, 5.58, 7.8, 7.85, 8.43, 10.05, 10.06, 10.07, \n10.03, 8.89, 6.17, 5.04, 5.01, 3.92, 2.29, 2.29, -1, -1, -1, \n-1, -1, 0, 1, 2, 4, 6, 7, 8, 8, 9, 9, 9, 7, 6, 4, 3, 2, 2, 1, \n-0.16, -1.13, -2.19, -2.98, -3.48, -3.86, -3.84, -2.96, -1.16, \n0.91, 2.61, 3.92, 4.84, 5.59, 6.68, 7.41, 6.82, 5.08, 3.07, 1.56, \n0.51, -0.36, -1.15, -1.86, -2.53, -0.2, -0.9, 4.1, 6.9, 8.1, \n3.6, 2.6), rh = c(0.55, 0.6, 0.51, 0.51, 0.6, 0.52, 0.55, 0.57, \n0.6, 0.49, 0.44, 0.41, 0.38, 0.36, 0.33, 0.33, 0.31, 0.33, 0.35, \n0.39, 0.4, 0.4, 0.43, 0.49, 0.49, 73, 73, 75, 75, 75, 71, 67, \n59, 52, 47, 42, 39, 37, 35, 34, 37, 43, 48, 51, 54, 58, 61, 62, \n0.61, 0.64, 0.67, 0.7, 0.72, 0.74, 0.74, 0.71, 0.65, 0.58, 0.54, \n0.52, 0.51, 0.5, 0.46, 0.44, 0.45, 0.5, 0.57, 0.61, 0.64, 0.65, \n0.67, 0.69, 0.71, 59.1, 62.6, 43.9, 36.7, 33.2, 46.4, 50.1), \n type = c(\"Actual\", \"Actual\", \"Actual\", \"Actual\", \"Actual\", \n\"Actual\", \"Actual\", \"Actual\", \"Actual\", \"Actual\", \"Actual\", \n\"Actual\", \"Actual\", \"Actual\", \"Actual\", \"Actual\", \"Actual\", \n\"Actual\", \"Actual\", \"Actual\", \"Actual\", \"Actual\", \"Actual\", \n\"Actual\", \"Actual\", \"Provider W\", \"Provider W\", \"Provider W\", \n\"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \n\"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \n\"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \n\"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \"Provider W\", \n\"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \n\"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \n\"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \n\"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \n\"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \"Provider D\", \n\"Provider B\", \"Provider B\", \"Provider B\", \"Provider B\", \"Provider B\", \n\"Provider B\", \"Provider B\")), .Names = c(\"tme\", \"degc\", \"rh\", \n\"type\"), row.names = c(NA, -80L), class = c(\"data.table\", \"data.frame\"\n), .internal.selfref = <pointer: 0x0000000000120788>)\n\nI'm really not sure on how to proceed with this. I need to repeat this exercise for several datasets (a few hundred rows each) with up to 30 variables (sample data only has two). \n\nA:\n\nI think that what you are asking for is this.\nfAct = approxfun(dt$tme[dt$type=='Actual'], dt$degc[dt$type=='Actual'], )\n\nThis gives a piecewise linear approximation to the Actual values. You can then compare this with values from the various providers. For example,\n> dt[35,]\n tme degc rh type\n35 2018-01-18 07:00:00 6 47 Provider W\n> fAct(dt[35,'tme'])\n[1] 6.69\n\nSo Provider W predicts that degc will be 6 at time 2018-01-18 07:00:00. The (approximation to the) Actual value is 6.69 so the error is 0.69.\nEdit\nAs noted by @RalfStubner, you can get a smoother (non-linear) approximation using\nfAct2 = splinefun(dt$tme[dt$type=='Actual'], dt$degc[dt$type=='Actual'])\n\n"],["Q:\n\nHow to jump from one activity to another and set a fragment\n\nWhat i want is when i jump from one activity to another with intent it should also automatically set a fragment inside framelayout but i can't figure out how to do that any help will be appreciated.\n\nA:\n\nIf I got your question correctly, this code should help you:\nIn your first activity put this code:\npublic static final String FRAGMENTA = \"FragmentA\";\npublic static final String FRAGMENTB = \"FragmentB\";\npublic static final String FRAGMENTC = \"FragmentB\";\n\nString fragmentToDisplay = FRAGMENTA;\nIntent intent = new Intent(getApplicationContext(), SecondActivity.class);\nintent.putExtra(\"fragmentToDisplay\", fragmentToDisplay);\nstartActivity(intent);\n\nThen in your second activity in onCreate, receive the intent and set a fragment according to the string intent:\nString fragmentToDisplay = getIntent.getStringExtra(\"fragmentToDisplay\");\nswitch (fragmentToDisplay) {\n case FirstActivity.FRAGMENTA:\n //FragmentTransaction to show Fragment A\n break;\n case FirstActivity.FRAGMENTB:\n //FragmentTransaction to show Fragment B\n break;\n case FirstActivity.FRAGMENTC:\n //FragmentTransaction to show Fragment C\n break;\n}\n\n"],["Q:\n\nDisable CodeRush\n\nI do not want to uninstall code rush. I just want to have the chance to turn it off when I don't want it.\nIs this possible? (express version)... \n\nA:\n\nFirst you should turn on the \"DevExpress\" menu. This is hidden by default in CodeRush Xpress.\nSee this blogpost http://www.coderjournal.com/2009/08/show-coderush-xpress-9-2-menu-in-visual-studio/\nOnce this is done you should be able to use the Unload/Load menu option (Last item on DevExpress menu)\nAdditionally you can set CodeRush Xpress to not load fully by default..\n\nFollow these steps to get to the Startup options page:\n\nFrom the DevExpress menu, select \"Options...\".\nIn the tree view on the left, navigate to this folder:\nCore\nSelect the \"Startup\" options page.\nThis page level is Expert, and will only be visible if the Level combo on the lower-left of the Options dialog is set to Expert.\n\nOnce on this page, you can toggle the \"Load Manually\" setting to dictate how CodeRush starts.\n\nA:\n\nShift Ctrl Alt O brings up CR's options dialog - not sure if there's something useful in the Xpress version though.\n(In the Pro, the DevExpress menu has a \"Unload\" option)\n\nA:\n\nIn VS 2017 goto \n\nTools > Extensions and Updates\n\nThen you can enable, disable, uninstall the CodeRush or any other extension.\n\n\n"],["Q:\n\nIs OAEP reversible?\n\nGiven nothing more than some integer $m =$ OAEP($M$), is it possible to recover the original plaintext $M$? In other words, without being given the hash functions or the random string used for encoding, or even the length of it.\nEDIT: This is being used in tandem with RSA, but I don't know the hash functions that OAEP usually uses with RSA; they might be public, for all I know.\n\nA:\n\nIf you know the hash functions, yes. If the hash functions are secret, no\u2014but how would you come into a situation where OAEP is being used with a secret hash function?\nFor any hash functions $G$ and $H$, OAEP is a fixed permutation involving no secret keys. Specifically, given a message $m$ and randomization $r$, OAEP returns $(a, b)$ where\n\\begin{align}\n a &= m \\oplus G(r), \\\\\n b &= r \\oplus H(a),\n\\end{align}\nwhich can be inverted by\n\\begin{align}\n r &= b \\oplus H(a), \\\\\n m &= a \\oplus G(r).\n\\end{align}\nSo if you have $(a, b)$ and you can compute $G$ and $H$, you can recover $m$ (and $r$). This is exactly what RSAES-OAEP decryption does, after it completes the RSA private key operation.\n\n"],["Q:\n\n403 forbidden on image url on production asp.net\n\nI've referred lots of site and questions, but did not find any solution. It is working on my local site but not on production.\nStructure:\n-Root\n -Files\n -Products\n -Product01.jpg\n -others\n -Product01.jpg\n\nI'm able to access Product01.jpg from others folder, but when I'm trying to access image from Products it gives me an error of 403 forbidden:You have attempted to view a resource that does not have Read access..\nI've Added IUSer, IIS_IUser and NETWORK SERVICES with full access. But getting same error.\nAlso tried with allow anonymous authentication, but no luck!\nSide: All users roles have full permission. \n\nA:\n\nOkay, I got the answer.\nI'm using IBM VPS server, So need configure as below.\nIIS > Folder > Handler mappings > Edit Feature Permissions > check here is enabled or not! and checked Read and Script\n\n"],["Q:\n\nText color in TextViews of ListView setted by selector works only in \"normal\" state\n\nI create ListView and my own ListAdapter. I use simple_list_item_2. I want to change color of text for each state. There is code of dark.xml below:\n<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<selector xmlns:android=\"http://schemas.android.com/apk/res/android\"> \n <item android:state_selected=\"true\" android:color=\"@color/selectedTextListColor\"/>\n <item android:state_focused=\"true\" android:color=\"@color/selectedTextListColor\"/>\n <item android:state_pressed=\"true\" android:color=\"@color/selectedTextListColor\"/>\n <item android:color=\"@color/textListColor\"/>\n</selector>\n\nNext it is part of code when I try to set that functionality. I think there is a problem.\nArrayAdapter<Element> adapter = new ArrayAdapter<Element>(instance, android.R.layout.simple_list_item_2, songsArray){\n\n @Override\n public View getView(int position, View convertView, ViewGroup parent) {\n\n TwoLineListItem row;\n\n if (convertView == null) {\n LayoutInflater inflater = (LayoutInflater)getApplicationContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);\n row = (TwoLineListItem)inflater.inflate(android.R.layout.simple_list_item_2, null);\n\n } else { \n row = (TwoLineListItem)convertView;\n\n }\n\n Element song = songsArray[position];\n String data = song.text();\n\n int dashIndex = data.indexOf(\"-\");\n\n TextView text2 = row.getText2();\n text2.setText(data.substring(0, dashIndex-1).trim());\n text2.setTextSize(12.0f);\n text2.setPadding(10, text2.getPaddingTop(), text2.getPaddingRight(), text2.getPaddingBottom());\n\n TextView text1 = row.getText1();\n text1.setText(data.substring(dashIndex+1).trim()); \n text1.setTextSize(18.0f);\n text1.setPadding(10, text1.getPaddingTop(), text1.getPaddingRight(), text1.getPaddingBottom());\n\n text1.setTextColor(getResources().getColor(R.color.dark)); \n\n return row;\n }\n\n};\n\nIt still works in such a way, that text has color red and it didn't change on press. Could you tell correct way? Pay attention on line \ntext1.setTextColor(getResources().getColor(R.color.dark)); \n\nI think there is my mistake.\n\nA:\n\ntext1.setTextColor(getResources().getColorStateList(R.color.dark));\n\nThat was my problem. Now it works great.\n\n"],["Q:\n\nHow to choose Content-Type in HTTP response\n\nI write small http server. I need to set Content-Type when I send file in response. How it should be done? Should Content-Type field be preset in some map for each file or it might be set basing on file extension? If yes, how about *.ico files that are PNG actually? \nSo what\u2019s the common practice?\n\nA:\n\nSo what\u2019s the common practice?\n\nCommon practice, for static files, is to infer the Content-Type from the file extension.\n\nIf yes, how about *.ico files that are PNG actually?\n\nThen common practice would give the wrong content-type.\nYou could override it on a case-by-case basis from a configuration file.\ne.g. Apache HTTPD would allow:\n<Files \"favicon.ico\">\n ForceType image/png\n</Files>\n\n"],["Q:\n\nWhy does substring expansion [ test=\"-efoo\"; echo ${test:0:2} ] fail?\n\nOn Linux Mint, using bash..\ntest=\"-ffoo\"; echo ${test:0:2}\n\nworks outputting the first two characters\nbut \ntest=\"-efoo\"; echo ${test:0:2}\n\nfails, with apparently null output.\nI'm thinking the form of this is\n${parameter:offset:length}\n\nI know enough that parameter characters cannot be *@#?-$!0_ \nbut $test is the parameter - surely its contents can be anything? I guess -e is triggering something shell-like but why..\n\nA:\n\nWhen you run\ntest=\"-efoo\"; echo ${test:0:2}\n\necho is run with the argument -e, which in some echo implementations including the echo builtin command of most bash deployments, is a valid option and is thus \u201cswallowed\u201d.\nUse printf instead:\ntest=\"-efoo\"; printf %s\\\\n \"${test:0:2}\"\n\n"],["Q:\n\nDifference between a manifold and a sub-manifold of the same dimension?\n\nI appologize in advance in case this is a very trivial issue and for any mistakes due to translating stuff from my German lecture notes to English ...\nA subset $M \\subset \\mathbb{R}^n$ is defined to be a $k$-dim submanifold of $\\mathbb{R}^n$ with $1 \\le k \\le n-1$, if each point $m \\in M$ has the following property:\nThere is an open set $U \\subset \\mathbb{R}^n $ surrounding $m$ and an open subset $V \\subset \\mathbb{R}^n$ related by a diffeomorphism $\\Phi: U \\rightarrow V$ such that \n$$\n\\begin{eqnarray}\n\\nonumber\n\\Phi(U \\cap M) & = & V \\cap(\\mathbb{R}^k \\times \\{ 0 \\}) \\doteqdot W \\\\\n & = & \\{ x =(x_1, ...,x_n) \\in V | x = (x_1, ... ,x_k, 0, ..., 0) \\}\n\\end{eqnarray}\n$$\nThis basically means, that $M\\cap U$ locally corresponds to $\\mathbb{R}^k$.\nA local chart of $M$ at point $m$ is given by the pair $(W,\\phi \\doteqdot \\Phi^{-1})$\nFrom another source, a k-dim manifold is described to be locally $\\mathbb{R}^k$ too and covered by a family of local coordinate systems.\nWhat is the difference between a manifold and a submanifold of the same dimension?\nIs it just that the sumbanifold is \"embeded\" into a higher-dimensional space, whereas the manifold is not?\nTo me it seems both can be covered in a very similar way by local coordinates.\n\nA:\n\nAn abstract manifold of dimension $k$ is defined by a family of charts (local coordinate systems). In particular, such a family of charts exists for every $k$-dimensional submanifold of $\\mathbb{R}^n$. \nOn the other hand, manifolds may be constructed independent of a realization in a Euclidean space, e.g., by surgery. There are 2-dimensional manifolds such as the Klein bottle that cannot be realized (without self-intersection) as 2-dimensional submanifold of $\\mathbb{R}^3$. \nThe Whitney embedding theorem says that a $k$-dimensional manifold can be diffeomorphically embedded into $\\mathbb{R}^{2k}$ iff its topology is Hausdorff and second countable. Thus the concept of an abstract manifold is slightly more general than a submanifold but the collection of nice examples is the same (up to diffeomorphisms). \nNote that there may be multiple differentiable structure on the same manifold considered as a topological space. Examples are exotic spheres. \n\n"],["Q:\n\nScraping through on Wiki using \"tr\" and \"td\" with BeautifulSoup and python\n\nTotal python3 beginner here. I can't seem to get just the name of of the colleges to print out.\nthe class is no where near the college names and i can't seem to narrow the find_all down to what i need. and print to a new csv file. Any ideas?\nimport requests\nfrom bs4 import BeautifulSoup\nimport csv\n\nres= requests.get(\"https://en.wikipedia.org/wiki/Ivy_League\")\nsoup = BeautifulSoup(res.text, \"html.parser\")\ncolleges = soup.find_all(\"table\", class_ = \"wikitable sortable\")\n\nfor college in colleges:\n first_level = college.find_all(\"tr\")\n print(first_level)\n\nA:\n\nYou can use soup.select() to utilize css selectors and be more precise:\nimport requests\nfrom bs4 import BeautifulSoup\n\nres= requests.get(\"https://en.wikipedia.org/wiki/Ivy_League\")\nsoup = BeautifulSoup(res.text, \"html.parser\")\n\nl = soup.select(\".mw-parser-output > table:nth-of-type(2) > tbody > tr > td:nth-of-type(1) a\")\nfor each in l:\n print(each.text)\n\nPrinted result:\nBrown University\nColumbia University\nCornell University\nDartmouth College\nHarvard University\nUniversity of Pennsylvania\nPrinceton University\nYale University\n\nTo put a single column into csv:\nimport pandas as pd\npd.DataFrame([e.text for e in l]).to_csv(\"your_csv.csv\") # This will include index\n\n"]]