Erroneous text by pandas while using to_csv function Posted: 04 May 2021 08:35 AM PDT I have a CSV file which has a list of stock symbols for different companies. I need to add token to each symbol and export the dataframe to a csv using to_csv function. I know how do it and have been doing it for long. But a weird bug is bugging the program. Input csv file has a stock symbol SMRUTHIORG which is the correct symbol. But my python script somehow reads it as SMRUTHIORGÂ with an extra weird A in the end and thus it fails to map to a stock code. I have no idea where this weird A comes from. I guess it is have a problem in decoding. Here is my code: import pandas as pd df = pd.read_csv('../list_of_script.csv') df1 = df[['trendlyne_symbols','nse_instrument_token']] df1 = df1.assign(token = '') df1 = df1.drop(['nse_instrument_token'], axis=1) df1 = df1.dropna() print(df1) for index, row in df1.iterrows(): print(f'working on row number {index} of df1') for index2, row2 in df.iterrows(): if row['trendlyne_symbols'] == row2['nse_tradingsymbol']: row['token'] = row2['nse_instrument_token'] print('match found...') break elif row['trendlyne_symbols'] == row2['bse_tradingsymbol']: row['token'] = row2['bse_instrument_token'] print('match found') break df1.to_csv('output_tokens.csv', index=False) print(df1.tail()) Any help is appreciated. Thanks in advance. |
Google Drive File download through Oauth2 Posted: 04 May 2021 08:35 AM PDT |
Add text box at specific location in report base on value Posted: 04 May 2021 08:35 AM PDT I'm working on a cut list generator but I'm having difficulty on the final report. I'd like to display a rectangle that represents the factory length piece with lines indicating cut points. In each segment I'd like to have the length of the piece shown. Using Report.line I've created the rectangles needed but I'm not sure how to get text in each box. Here is a sample output so far Sample Output. As an example I want the three rectangles for Piece #1 to have 48" in them, probably all the way to the left. Any suggestions? I thought createReportControl might work but I'm not sure that is the correct approach. I'm also thinking about one text box with a monospace font so I can scale the input across the entire width. Any suggestions are appreciated. Thanks, Dave |
Why are the files duplicated? Help me with GitHub Actions Posted: 04 May 2021 08:35 AM PDT I want to have a folder for the windows build and another for the mac build but I always get two files and both have the windows and the mac build , I tried multiple approaches but I failed , any help is appreciated. The artifacts I get are MacBuiltProject and WinBuiltProject and in both of them theres these files: StandaloneOSX with the mac build StandaloneWindows64 with the windows build What I want to accomplish is to have inly the mac build in MacBuiltProject and only the windows build in WinBuiltProject Here's the YAML File : name: Actions on: pull_request: {} push: { branches: [master] } env: UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }} jobs: BuildWindows: name: Build the Project for Windows runs-on: ubuntu-latest steps: # Checkout - name: Checkout repository uses: actions/checkout@v2 with: lfs: true # Cache - uses: actions/cache@v1.1.0 with: path: Library key: Library # Test - name: Run tests uses: webbertakken/unity-test-runner@v1.3 with: unityVersion: 2019.3.9f1 # Build for win - name: Build project for windows uses: webbertakken/unity-builder@v0.10 with: buildName: InteractiveWriting-Windows unityVersion: 2019.3.9f1 targetPlatform : StandaloneWindows64 # Output for win - uses: actions/upload-artifact@v1 with: name: WinBuiltProject path: build BuildMacOS: name: Build the Project for MacOS runs-on: ubuntu-latest steps: # Checkout - name: Checkout repository uses: actions/checkout@v2 with: lfs: true # Cache - uses: actions/cache@v1.1.0 with: path: Library key: Library # Test - name: Run tests uses: webbertakken/unity-test-runner@v1.3 with: unityVersion: 2019.3.9f1 # Build for Mac - name: Build project for MacOS uses: webbertakken/unity-builder@v0.10 with: buildName: InteractiveWriting-Mac unityVersion: 2019.3.9f1 targetPlatform : StandaloneOSX # Output for Mac - uses: actions/upload-artifact@v1 with: name: MacBuiltProject path: build Release : name: Release the project runs-on : ubuntu-latest needs : - BuildWindows - BuildMacOS steps: - name: Win Download files uses: actions/download-artifact@v2 with: name: WinBuiltProject path: build - name: Mac Download files uses: actions/download-artifact@v2 with: name: MacBuiltProject path: build - name: WinCompressTheFinalResult uses: thedoctor0/zip-release@master with: filename: WinBuiltProject.zip path: build - name: MacCompressTheFinalResult uses: thedoctor0/zip-release@master with: filename: MacBuiltProject.zip path: build - name: Create Github Release id: create-new-release uses: actions/create-release@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: tag_name: v${{ github.run_number }} release_name: Release v${{ github.run_number }} - name: WinUpload to GitHub Release uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create-new-release.outputs.upload_url }} asset_path: ./WinBuiltProject.zip asset_name: WinBuiltProject-v${{ github.run_number }}.zip asset_content_type: application/zip - name: MacUpload to GitHub Release uses: actions/upload-release-asset@v1 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} with: upload_url: ${{ steps.create-new-release.outputs.upload_url }} asset_path: ./MacBuiltProject.zip asset_name: MacBuiltProject-v${{ github.run_number }}.zip asset_content_type: application/zip |
Finally i created a full functinality Search_bar, but it only searches when i press the Enter Button, after i type on the search bar, Posted: 04 May 2021 08:35 AM PDT Finally I created a full functionality Search bar, but it only searches when I press the Enter Button, after I type on the search bar, I Want the search bar fetches data immediately while I type without I press Enter button,, if you want I add my full code. |
How to do image similarity search with an image? Posted: 04 May 2021 08:35 AM PDT If the title isn't clear here's an example of what I am talking about Let's say I have an image like this, and I want to find a list of images that contains a star that most resembles this one: In that case this image would be result since there is a star that is very similar to the one above. Also would it be possible to make it rotation invariant? Any recommendations or approaches? I've read up about opencv's template matching: https://docs.opencv.org/master/d4/dc6/tutorial_py_template_matching.html Those examples seem to be for EXACT matches where as I am looking for similarities. Also maybe some kind of unsupervised ml? (Idk if ml is actually useful or just a buzzword at this point, but I am open to anything). |
FireBase not running most of the javascript Posted: 04 May 2021 08:35 AM PDT So I finally hosted my webpage but there is a few lines of javascript code not running the Document.write("Good Day!") other js functions work totally fine but this one doesn't seem to work on most of the Webhosting services out there |
position: absolute only working on the first item Posted: 04 May 2021 08:35 AM PDT I'm creating a user card where there's a menu button on the top of the card when clicked, it should show a menu. Whenever I click on the menu of the first item in the loop, then it shows fine. However, there are many user cards and when I click on the menu button of the other cards, the menu still shows on the first card and not on the card that I click. What am I doing wrong here? <template> <div class="custom-users" v-if="users && users.length > 0"> <user-card v-for="user in users" :key="user.userId" @open-menu="openMenu" > </user-card> <div class="menu" v-if="showMenu"> <p>Delete</p> </div> </div> </template> <script> data() { return { showMenu: false, }; }, methods: { openMenu(){ this.showMenu = !this.showMenu; }, } </script> <style scoped> .custom-users{ position: relative; } .menu{ position: absolute; height: 100px; width: 100px; top: 60px; right: 25px; z-index: 9999; } </style> |
Alternative R package to Treetag for POS and lemmatization Posted: 04 May 2021 08:35 AM PDT I am just wondering whether there is an alternative package to Treetag in R to conduct both Part of speech tagging and lemmatization on strings? Reason is I am having extreme difficulties in installing the Treetag (driving me insane). Thank you. |
fatal error: unexpectedly found nil while implicitly unwrapping an optional value in NSimageView Posted: 04 May 2021 08:34 AM PDT I'm trying to load an image (NSImageView). I'm doing this with the following function: func loadImage(path: String) { print("Path: \(path)") imageElement.image = NSImage(byReferencingFile: path) } Whenever i do this in the file this function is, it loads fine, but when i got to another file, otherFile.swift, i get above error. Even though the path still does print properly (not nil or anything) What am i doing wrong here? (using swift4) |
What is the easiest way to create an Enumeration<T> object containing a single T value in java? Posted: 04 May 2021 08:35 AM PDT Generally, I want to know what is the most convenient and readable approach to generate an Enumeration<T> object from a given single T object in java. In my case I have a String object which I need to wrap into an Enumeration<T> . This is what I am doing: public Enumeration<String> getEnumeration(String value) { Vector<String> result = new Vector<>(); result.add(value); return result.elements(); } Is there any other approach which is more succinct? Thanks |
Why MutationObserver does not work for title change in FullCalendar? Posted: 04 May 2021 08:35 AM PDT I need to know the current title of a FullCalendar. The title could be changed after clicking the navigation buttons. I did not find any FullCalendar native way how to get the title so I was looking for other ways to find out. I thought that MutationObserver would work.. But it does not work when changing the text through the buttons. If the change is done via JavaScript setInterval(function(){ // target.innerText = ('hello world ' + Math.random() + '!!!'); },1000); then the MutationObserver works. Any idea how to fix that? Working jsFiddle |
Remove unnecessary square brackets from output Posted: 04 May 2021 08:35 AM PDT The code below returns: [[('direction', 'north')], [('direction', 'east')], [('direction', 'south')]] There is a set of [ ] around each value that I'm wondering how to get rid of. The ideal output is: [('direction', 'north'), ('direction', 'east'), ('direction', 'south')] Here is the function: def scan(input): words = input.split() dictionary = [('direction', 'north'),('direction', 'south'),('direction', 'east')] output = [] for word in words: output.append(list(filter(lambda x:word in x, dictionary))) return output print(scan('north east south')) Does anyone know why the square brackets show up in the output and how I can get rid of them? Any assistance is much appreciated. |
Error catching in JavaScript does not catch error properly Posted: 04 May 2021 08:35 AM PDT I am working on a game in javascript which utilizes the p5.js library. I am trying to load my own font, in which I am using a .ttf file, but sometimes, p5.js doesn't properly load the font. in cases like this, I am trying to use the try and catch method to check if this happens, and if it does, to switch my font to a default built-in font that always works (not a .ttf, just built-in). Here is my code pertaining to the issue: function preload() { try { font = loadFont("assets/BebasNeue-Regular.ttf"); // Font from Google Fonts - https://fonts.google.com/specimen/Bebas+Neue#standard-styles } catch (error) { console.error("ERROR: " + error) console.log("Font was unable to load, using default font."); font = "Helvetica"; } console.log("Assets preloaded..."); } However, whenever I try to run my code, not only does my canvas not load anything, but the error still appears in the console. My console.log statement, however, is not there. Here is what it says: Not allowed to load local resource: blob:null/a07d873c-2d5e-4653-92f4-02fd085cc6e4 p5.js:48337 🌸 p5.js says: It looks like there was a problem loading your font. Try checking if the file path (assets/BebasNeue-Regular.ttf) is correct, hosting the file online, or running a local server. (More info at https://github.com/processing/p5.js/wiki/Local-server) p5.js:80410 Font could not be loaded assets/BebasNeue-Regular.ttf (anonymous) @ p5.js:80410 assets/BebasNeue-Regular.ttf:1 Failed to load resource: net::ERR_FAILED Even though my asset is in my folder, when I try to run the program, it does not work. Does anyone know how to fix/change my error-catching statement? EDIT: I tried a different way of error catching, which is provided by p5 in the loadFont() procedure. Here is what my new code is: function preload() { font = loadFont("assets/BebasNeue-Regular.ttf", setup, fontError); // Font from Google Fonts - https://fonts.google.com/specimen/Bebas+Neue#standard-styles console.log("Assets preloaded..."); } function fontError() { console.log("Font was unable to load, using default font."); font = "Helvetica"; } function setup() { // Sets up the game, irrelevant to error. } Here is a link to my code download is it helps: https://www.mediafire.com/file/k4nm445dkxhv0i8/game.zip/file |
Enums VS Objects Posted: 04 May 2021 08:35 AM PDT I am creating a "mock-dictionary" using a HashMap with the keys being the word the user wants to search, such as "dog" or "bike". And the second value, in simple terms, is the definition. The definition will also be further broken down into different definitions for each applicable part of speech (i.e, verb/noun/adj). However, I am wondering what the performance differences are between doing something like HashMap<ENUM_Name, Enum_GetterMethod> vs HashMap<Object.getName, Object.getDefinitionMethod>. Basically, I am confused about why we need ENUMS when we have objects, and when it is better to use an ENUM over an object and vise versa. I have read other forums about how Enums are cleaner and are great for readability, but I don't see anything as to when to create an Enum class vs just use objects? code is just as an example: class Dictionary{ public enum Words{ Dog("noun definition"), Bike("noun definition", "verb definiton"); //constructors & private variables & getter methods } private static void Main() { //use a for() loop to add in all the keys/values to map HashMap<ENUM_Name, Enum_GetterMethod> } } VS class DictionaryWords{ //private variables for defintions //constructors for objects //getter methods for private variables public static void main(){ Dictionary Dog = new Dictionary("noun definition"); Dictionary Bike = new Dictionary("noun definition", "verb definiton"); //use a for() loop to add in all the keys/values to map HashMap<Object_Name, Object_GetterMethod> } |
500 Errors When Trying to Install Symfony Based Application Eventic Posted: 04 May 2021 08:35 AM PDT Hoping someone with experience might be able to help. We've been attempting to install Eventic on our GoDaddy server (enhanced business hosting with security management). We have updated the file permissions of a few folders and one file to 775 via the cPanel file manager as noted in the documentation. Otherwise, all directories are 755 and all files are 644. We then visited the https://events.ourdomain.com/ and the documentation indicates we should be redirected, but that doesn't happen. So we go to https://events.ourdomain.com/public/ and we see the setup wizard - but it's an un-styled, non-functioning page. The console indicates 500 errors. When we tried the same in a WAMP environment, we encounter the same issues, but the errors are 404. The thought here is using WAMP should have resolved any permission errors, so that's not the root issue, correct? If that's the case, and it's confirmed the php requirements are met and, in the case of the production environment, the folder permissions were updated, what is the issue? Where do we start? So far, the only errors we can find are the following... In a local error log file in the /public folder: - [04-May-2021 01:02:49 America/New_York] PHP Deprecated: Non-static method App\Form\Extension\CryptedGatewayConfigTypeExtension::getExtendedTypes() should not be called statically in /home/etkt/public_html/events.ourdomain.com/vendor/symfony/form/DependencyInjection/FormPass.php on line 109
- [04-May-2021 01:02:49 America/New_York] PHP Deprecated: Non-static method App\Form\Extension\CryptedGatewayConfigTypeExtension::getExtendedTypes() should not be called statically in /home/etkt/public_html/events.ourdomain.com/vendor/symfony/form/DependencyInjection/FormPass.php on line 109
There are no errors in the cPanel Errors module, and no other local error logs. |
What is (&array)[1] exactly? Posted: 04 May 2021 08:35 AM PDT This Q in C, how come the address of array, &array, &array[0] are the same? made me investigate on pointers and arrays: I confirm they are very similar but not identical. &a[0] is the verbose form for a or &a . But what about the precedence of & vs [] ? When I put parens the wrong way like (&a)[1] this changed the value, but not (&a)[0] . #include <stdio.h> int main(){ int a[3] = {10,20,30}; int *b; b = a; printf("%p a\n", a); printf("%p a+1\n", a+1); printf("%p a+2\n\n", a+2); printf("%p (&a)[0]\n", (&a)[0]); printf("%p (&a)[1]\n", (&a)[1]); printf("%p (&b)[0]\n", (&b)[0]); printf("%p (&b)[1]\n\n",(&b)[1]); printf("%p cast\n\n", (void **)((&a) + 1) ); int *c = a; printf("%p\n", c); printf("%p\n", &c); return 0; } output: 0x7ffe18053c9c a 0x7ffe18053ca0 a+1 0x7ffe18053ca4 a+2 0x7ffe18053c9c (&a)[0] 0x7ffe18053ca8 (&a)[1] 0x7ffe18053c9c (&b)[0] (nil) (&b)[1] 0x7ffe18053ca8 cast 0x7ffe18053c9c c (int *c = a) 0x7ffe18053c90 &c I found (void **)((&a) + 1) to get the same result. Can't leave out a piece it seems. Suddenly &a does create a pointer, anonymously. With index zero you get the base address (...c9c) both with a and its pointer b . But with index 1 strange things happen, and differently for b . Is there a rule for this? I don't even know if I want to hear it! Is that what &a does besides being between a and &a[0] ? good A here by chux. His cast is simpler, but does it do the same? difference between &array and &array[0] in C From mentioned link I not only simplified my cast but now I think I know what it does and why the index or offset of 0 is special. (void *)(&a + 0) is the cast. But why even cast? &a + 0 prints the base address. With offset + 1 the address advances a whole array size (not a pointer as I tried) - "one past the end". A second dimension. The base remains, but the offset changes. For assignment: int *c = a; int (*d)[3] = &a; // with some help from the left... int *e = (int *)&a; // ... or on the right side... int *f = &a; // or with a warning, but working So (&a) generates a new type, but not a pointer? New reference to the same spot. Address of = pointer to = array of. |
Delphi: TIdTCPClient disconnect don't close the connection Posted: 04 May 2021 08:35 AM PDT I'm investigation on a growing of active TCP connection. Seems TIdTCPClient.Disconnect don't close connection. This is a sample project program Project2; {$APPTYPE CONSOLE} {$R *.res} uses System.SysUtils, IdTCPClient; var FClient: TIdTCPClient; begin try FClient := TIdTCPClient.Create(); FClient.Connect('LOCALHOST', 6379); FClient.Disconnect; FClient.Free; except on E: Exception do Writeln(E.ClassName, ': ', E.Message); end; end. Opening this console application multiple times cause a growing of the connection netstat -na | find "6379" Side note: I'm on Berlin 10, Windows 7 (but is the same on Windows 10) |
How to convert xml data into a csv file? Posted: 04 May 2021 08:35 AM PDT I have the following data in xml format. Now, I need to extract data from the headers 'Expression Field 1', 'X Gender', 'Entrant Age', etc. into a csv file. I have written the following code but it doesn't work. Please help. When I try the following code, I get the error ''NoneType' object has no attribute 'tag'' import xml.etree.ElementTree as Xet import pandas as pd cols = ["EXPRESSION_FIELD_1", "XGENDER", "ENTRANT-AGE", "CATEGORY2-NUM__SNZ", "XCATEGORY1", "RESULT-TIME-MILLISECONDS","FINA-POINTS__SNZ"] rows = [] # Parsing the XML file xmlparse = Xet.parse('sample.xml') root = xmlparse.getroot() for i in root: name = i.find("EXPRESSION_FIELD_1").tag gender = i.find("XGENDER").tag age = i.find("ENTRANT-AGE").tag category = i.find("CATEGORY2-NUM__SNZ").tag result = i.find("XCATEGORY1").tag rows.append({"name": name, "gender": gender, "age": age, "category": category, "result": result}) df = pd.DataFrame(rows, columns=cols) # Writing dataframe to csv df.to_csv('output.csv') <?xml version="1.0" encoding="UTF-8" standalone="no"?> <TableData> <Fields> <Field align="" field="FRAGMENT_DISPLAY.SPLITS" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Expander" name="FRAGMENT_DISPLAY-SPLITS" showInExpander="true" sortable="true" source="tableColumn" type="string" width=""/> <Field align="" field="EXPRESSION_FIELD_1" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Name " name="EXPRESSION_FIELD_1" showInExpander="false" sortable="false" source="tableColumn" type="string" width="130"/> <Field align="" field="XGENDER" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Gender" name="XGENDER" showInExpander="false" sortable="true" source="tableColumn" type="string" width="50"/> <Field align="" field="ENTRANT.AGE" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Age" name="ENTRANT-AGE" showInExpander="false" sortable="true" source="tableColumn" type="int" width="35"/> <Field align="" field="CATEGORY2.NUM$$SNZ" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Distance" name="CATEGORY2-NUM__SNZ" showInExpander="false" sortable="true" source="tableColumn" type="int" width="70"/> <Field align="" field="XCATEGORY1" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Stroke" name="XCATEGORY1" showInExpander="false" sortable="true" source="tableColumn" type="string" width="70"/> <Field align="right" field="RESULT.TIME.MILLISECONDS" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Time " name="RESULT-TIME-MILLISECONDS" showInExpander="false" sortable="true" source="tableColumn" type="int" width="70"/> <Field align="right" field="FINA.POINTS$$SNZ" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="FINA Points" name="FINA-POINTS__SNZ" showInExpander="false" sortable="true" source="tableColumn" type="string" width="85"/> <Field align="right" field="FINA.YEAR$$SNZ" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Points Year" name="FINA-YEAR__SNZ" showInExpander="false" sortable="true" source="tableColumn" type="string" width="80"/> <Field align="right" field="$DATE$COMP.DATE" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Date" name="_DATE_COMP-DATE" showInExpander="false" sortable="true" source="tableColumn" type="string" width="70"/> <Field align="" field="XEVENT.CODE" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Meet" name="XEVENT-CODE" showInExpander="false" sortable="true" source="tableColumn" type="string" width="190"/> <Field align="" field="PARAMETER1" hasEmailLink="false" hasHyperlink="false" hidden="false" id="" label="Course" name="PARAMETER1" showInExpander="false" sortable="true" source="tableColumn" type="string" width="50"/> <Field field="MEMBER.FORE1" name="MEMBER-FORE1" type="string"/> <Field field="MEMBER.SURNAME" name="MEMBER-SURNAME" type="string"/> <Field field="XCATEGORY2" name="XCATEGORY2" type="string"/> <Field field="TIME$$SNZ" name="TIME__SNZ" type="string"/> </Fields> <TotalRows>77910</TotalRows> <StartRowIndex>21</StartRowIndex> <EndRowIndex>41</EndRowIndex> <RowCount>20</RowCount> <Rows> <Row> <MEMBER-FORE1>Ieuan</MEMBER-FORE1> <MEMBER-SURNAME>Edwards</MEMBER-SURNAME> <XCATEGORY2>100 metre</XCATEGORY2> <TIME__SNZ>1:30.23</TIME__SNZ> <FRAGMENT_DISPLAY-SPLITS type="string"><!-- Start Fragment DISPLAY.SPLITS--><!-- Time Taken 16 Milliseconds--><apt_fragment_ms.comp.results_display.splits><div class="test-message" style="display:none">Public</div><!-- Start Display Process B:MS.CMS.BUILD.COMP.RESULTS.SPLITS,PUBLISHED,6--><!-- Time Taken 0 Milliseconds--><table border="1" ><tr><td>Split Distance</td><td style="width:50px" align="right">50</td><td style="width:50px" align="right">100</td></tr><tr><td>Cumulative</td><td align="right">42.53</td><td align="right">1:30.23</td></tr><tr><td>Individual</td><td align="right">42.53</td><td align="right">47.70</td></tr></table><br/><!-- End Display Process B:MS.CMS.BUILD.COMP.RESULTS.SPLITS,PUBLISHED,6--><div class="test-message" style="display:none"><div class="apt-form-item"><label>Staff Site</label><span class="output"></span></div><div class="apt-form-item"><label>Key</label><span class="output">004837*I*1319</span></div><div class="apt-form-item"><label>Stage</label><span class="output">P</span></div><div class="apt-form-item"><label>Heat</label><span class="output">1</span></div></div><style> /*<![CDATA[*/.fields table {border:0 none;}.splits td {background-color:pink;}/*]]>*/ </style></apt_fragment_ms.comp.results_display.splits><!-- End Fragment DISPLAY.SPLITS--></FRAGMENT_DISPLAY-SPLITS> <EXPRESSION_FIELD_1>Ieuan Edwards</EXPRESSION_FIELD_1> <XGENDER type="string">Male</XGENDER> <ENTRANT-AGE type="int">18</ENTRANT-AGE> <CATEGORY2-NUM__SNZ type="int">100 metre</CATEGORY2-NUM__SNZ> <XCATEGORY1 type="string">Breaststroke</XCATEGORY1> <RESULT-TIME-MILLISECONDS type="int">1:30.23</RESULT-TIME-MILLISECONDS> <FINA-POINTS__SNZ type="string">250</FINA-POINTS__SNZ> <FINA-YEAR__SNZ type="string">2021</FINA-YEAR__SNZ> <_DATE_COMP-DATE type="string">10/04/2021</_DATE_COMP-DATE> <XEVENT-CODE type="string">2021 Aon New Zealand Swimming Championships</XEVENT-CODE> <PARAMETER1 type="string">L</PARAMETER1> </Row> <Row> <MEMBER-FORE1>Sophie</MEMBER-FORE1> <MEMBER-SURNAME>Irving</MEMBER-SURNAME> <XCATEGORY2>50 metre</XCATEGORY2> <TIME__SNZ>29.73</TIME__SNZ> <FRAGMENT_DISPLAY-SPLITS type="string"><!-- Start Fragment DISPLAY.SPLITS--><!-- Time Taken 16 Milliseconds--><apt_fragment_ms.comp.results_display.splits><div class="test-message" style="display:none">Public</div><!-- Start Display Process B:MS.CMS.BUILD.COMP.RESULTS.SPLITS,PUBLISHED,6--><!-- Time Taken 0 Milliseconds--><table border="1" ><tr><td>Split Distance</td><td style="width:50px" align="right">50</td></tr><tr><td>Cumulative</td><td align="right">29.73</td></tr><tr><td>Individual</td><td align="right">29.73</td></tr></table><br/><!-- End Display Process B:MS.CMS.BUILD.COMP.RESULTS.SPLITS,PUBLISHED,6--><div class="test-message" style="display:none"><div class="apt-form-item"><label>Staff Site</label><span class="output"></span></div><div class="apt-form-item"><label>Key</label><span class="output">004837*I*131</span></div><div class="apt-form-item"><label>Stage</label><span class="output">P</span></div><div class="apt-form-item"><label>Heat</label><span class="output">2</span></div></div><style> /*<![CDATA[*/.fields table {border:0 none;}.splits td {background-color:pink;}/*]]>*/ </style></apt_fragment_ms.comp.results_display.splits><!-- End Fragment DISPLAY.SPLITS--></FRAGMENT_DISPLAY-SPLITS> <EXPRESSION_FIELD_1>Sophie Irving</EXPRESSION_FIELD_1> <XGENDER type="string">Female</XGENDER> <ENTRANT-AGE type="int">18</ENTRANT-AGE> <CATEGORY2-NUM__SNZ type="int">50 metre</CATEGORY2-NUM__SNZ> <XCATEGORY1 type="string">Butterfly</XCATEGORY1> <RESULT-TIME-MILLISECONDS type="int">29.73</RESULT-TIME-MILLISECONDS> <FINA-POINTS__SNZ type="string">554</FINA-POINTS__SNZ> <FINA-YEAR__SNZ type="string">2021</FINA-YEAR__SNZ> <_DATE_COMP-DATE type="string">10/04/2021</_DATE_COMP-DATE> <XEVENT-CODE type="string">2021 Aon New Zealand Swimming Championships</XEVENT-CODE> <PARAMETER1 type="string">L</PARAMETER1> </Row> |
Nginx with multiple docker-compose error 111 Posted: 04 May 2021 08:35 AM PDT I 'm trying to deploy a service with multiple docker-compose files using Nginx as reverse-proxy. My folder structure is: and my files are: Apple docker-compose.yaml: version: "3.5" services: apples: build: context: ./ dockerfile: Dockerfile networks: reverseproxy_santo-dio: aliases: # ApplesApp hostname on "fruit-network" - apples_net networks: reverseproxy_santo-dio: external: true Apple docker: FROM httpd:2.4 RUN echo "<html><body><h1>A</h1>App A works!</body></html>" > /usr/local/apache2/htdocs/index.html Orange docker-compose: version: "3.5" services: orange: build: context: ./ dockerfile: Dockerfile networks: reverseproxy_santo-dio: aliases: - orange_net networks: reverseproxy_santo-dio: external: true Orange docker: FROM httpd:2.4 RUN echo "<html><body><h1>B</h1>App B works!</body></html>" > /usr/local/apache2/htdocs/index.html My reverse-proxy is: version: '3.5' services: nginx: image: nginx:latest container_name: reverse-proxy volumes: - ./nginx.conf:/etc/nginx/conf.d/default.conf - ./log/:/var/log/nginx ports: - 80:80 - 443:443 networks: - santo-dio restart: always networks: santo-dio: where the nginx.conf: server { # Redirect http:// to https:// listen 80; # default_server; listen [::]:80; error_log /var/log/nginx/mylog.error_log debug; #frontend location / { proxy_pass http://apples_net; } #backend location /api/ { proxy_pass http://orange_net:8080/api; } } To deploy the service I lauch: - reverse proxy
- apple
- orange
When I go in my browser apple (localhost) works but orange (localhost/api) answers me with 502 Bad Gateway. In my logfile: 2021/05/04 11:07:23 [error] 32#32: *4 connect() failed (111: Connection refused) while connecting to upstream, client: xxx.xxx.xx.x, server: , request: "GET /api/ HTTP/1.1", upstream: "http://xxx.xxx.xxx.x:8080/api", host: "localhost" Where is my error? I started from this project: multiple-docker-compose-same-ports Thank |
why does subprocess fails during the given task? Posted: 04 May 2021 08:35 AM PDT I am using subprocess instead of os.system to execute a shell command to convert a document to pdf asynchronously. When being called repeatedly, it fails for approx 50% of files. It doesn't convert the doc file to pdf. How can I fix it. conversion_process = await asyncio.create_subprocess_shell( 'soffice -env:UserInstallation=file:///tmp/LibreOffice_Conversion_' + author + ' --headless --convert-to pdf --outdir ' + folder + ' ' + input_file, stdout=subprocess.PIPE, stderr=subprocess.PIPE) stdout, stderr = await conversion_process.communicate() if stderr: app.logger.error(f"stderr: {stderr}") error message: stderr: b'javaldx: Could not find a Java Runtime Environment! Please ensure that a JVM and the package libreoffice-java-common is installed. If it is already installed then try removing ~/.config/libreoffice/4/user/config/javasettings_Linux_*.xml Warning: failed to read path from javaldx |
Java stream's iterator forces flatmap to traverse substream before getting the first item Posted: 04 May 2021 08:35 AM PDT I have the need to create an iterator out of a stream of streams. Both the parent and the child streams are composed by non-interfering stateless operations and the obvious strategy is to use flatMap. Turns out that iterator, at the first "hasNext" invocation, traverse the entire first substream and I don't understand why. Despite iterator() is a terminal operation is clearly stated that it shouldn't consume the stream. I need that the objects generated from the substream are generated one by one. To replicate the behaviour I've mocked my real code with a sample which shows the same: import java.util.Iterator; import java.util.Objects; import java.util.concurrent.atomic.AtomicInteger; import java.util.stream.Stream; public class FreeRunner { public static void main(String[] args) { AtomicInteger x = new AtomicInteger(); Iterator<C> iterator = Stream.generate(() -> null) .takeWhile(y -> x.incrementAndGet() < 5) .filter(y -> x.get() % 2 == 0) .map(n -> new A("A" + x.get())) .flatMap(A::getBStream) .filter(Objects::nonNull) .map(B::toC) .iterator(); while(iterator.hasNext()) { System.out.println("after hasNext()"); C next = iterator.next(); System.out.println(next); } } private static class A { private final String name; public A(String name) { this.name = name; System.out.println(" > created " + name); } public Stream<B> getBStream() { AtomicInteger c = new AtomicInteger(); return Stream.generate(() -> null) .takeWhile(x -> c.incrementAndGet() < 5) .map(n -> c.get() % 2 == 0 ? null : new B(this.name + "->B" + c.get())); } public String toString() { return name; } } private static class B { private final String name; public B(String name) { this.name = name; System.out.println(" >> created " + name); } public String toString() { return name; } public C toC() { return new C(this.name + "+C"); } } private static class C { private final String name; public C(String name) { this.name = name; System.out.println(" >>> created " + name); } public String toString() { return name; } } } When it is executed it shows: > created A2 >> created A2->B1 >>> created A2->B1+C >> created A2->B3 >>> created A2->B3+C after hasNext() A2->B1+C after hasNext() A2->B3+C > created A4 >> created A4->B1 >>> created A4->B1+C >> created A4->B3 >>> created A4->B3+C after hasNext() A4->B1+C after hasNext() A4->B3+C Process finished with exit code 0 In debug it's clear that iterator.hasNext() triggers the generation of objects B and C. The desired behaviour, instead, is: > created A2 >> created A2->B1 >>> created A2->B1+C after hasNext() A2->B1+C >> created A2->B3 >>> created A2->B3+C after hasNext() A2->B3+C > created A4 >> created A4->B1 >>> created A4->B1+C after hasNext() A4->B1+C >> created A4->B3 >>> created A4->B3+C after hasNext() A4->B3+C What am I missing here? |
Avoid SQL Injection: Raw SQL in scope Posted: 04 May 2021 08:35 AM PDT I have the following scope in my model: scope :with_total_status, -> (date = Date.today) do select("agreements.*, ( SELECT json_agg(statuses) FROM ( SELECT ? AS calculated_status, SUM(?) AS total FROM agreement_installments WHERE agreement_installments.agreement_id = agreements.id GROUP BY calculated_status ) AS statuses ) agreement_status", "#{ AgreementInstallment.calculated_status_sql(date) }", "#{ AgreementInstallment.calculated_amount_remaining_or_paid(date) }") end To avoid SQL injection, I have used ? in two places as necessary. It doesn't work and give me any output. However, the following works correctly: scope :with_total_status, -> (date = Date.today) do select("agreements.*, ( SELECT json_agg(statuses) FROM ( SELECT #{AgreementInstallment.calculated_status_sql(date)} AS calculated_status, SUM(#{AgreementInstallment.calculated_amount_remaining_or_paid(date)}) AS total FROM agreement_installments WHERE agreement_installments.agreement_id = agreements.id GROUP BY calculated_status ) AS statuses ) agreement_status") end I am not really sure what is going wrong. Can you please give me the right direction for avoiding SQL injection and getting the correct output? |
Create Condition to Insert Array in MySql Posted: 04 May 2021 08:35 AM PDT Actually I am using this code to Insert my array into MySql Table, it's working fine, but I need to create a way to prevent duplicated rows foreach($resultado["$objeto"] as $key => $item) { $location = explode('/', $item['location']); $stmt = $conn->prepare('INSERT INTO eventos (objeto, data, hora, localizacao, estado, acao, mensagem, alteracao_dias, posicao) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)'); $stmt->bind_param('sssssssii', $objeto, // objeto $item['date'], // data $item['hour'], // hora trim($location[0]), // localizacao trim($location[1]), // estado $item['action'], // acao $item['message'], // mensagem filter_var($item['change'], FILTER_SANITIZE_NUMBER_INT), // alteracao_dias $key // posicao ); $stmt->execute() or die("erro ao tentar cadastrar evento"); } This is my array: Array ( [OD583091439BR] => Array ( [0] => Array ( [date] => 25/11/2020 [hour] => 13:38 [location] => FLORIANOPOLIS/SC [action] => Objeto entregue ao destinatário [message] => Objeto entregue ao destinatário [change] => há 152 dias ) [1] => Array ( [date] => 25/11/2020 [hour] => 11:48 [location] => FLORIANOPOLIS/SC [action] => Objeto saiu para entrega ao destinatário [message] => Objeto saiu para entrega ao destinatário [change] => há 152 dias ) [2] => Array ( [date] => 24/11/2020 [hour] => 07:34 [location] => SAO JOSE / SC [action] => Objeto em trânsito - por favor aguarde [message] => Objeto em trânsito - por favor aguarde de Unidade de Tratamento em SAO JOSE / SC para Unidade de Distribuição em FLORIANOPOLIS / SC [change] => há 153 dias ) [3] => Array ( [date] => 23/11/2020 [hour] => 21:14 [location] => PORTO ALEGRE / RS [action] => Objeto em trânsito - por favor aguarde [message] => Objeto em trânsito - por favor aguarde de Unidade de Tratamento em PORTO ALEGRE / RS para Unidade de Tratamento em SAO JOSE / SC [change] => há 154 dias ) [4] => Array ( [date] => 23/11/2020 [hour] => 16:36 [location] => NOVO HAMBURGO / RS [action] => Objeto em trânsito - por favor aguarde [message] => Objeto em trânsito - por favor aguarde de Agência dos Correios em NOVO HAMBURGO / RS para Unidade de Tratamento em PORTO ALEGRE / RS [change] => há 154 dias ) [5] => Array ( [date] => 23/11/2020 [hour] => 09:35 [location] => NOVO HAMBURGO/RS [action] => Objeto postado [message] => Objeto postado [change] => há 154 dias ) ) ) I created a column in mysql called "posicao" this column refers to each $key, How can I Verify if the column "posicao" already created for the specific "$objeto" before Insert in MySql Table ? Below is possible to see the duplicates rows in MySql for the same "posicao" and "objeto", I Need to prevent this, and allow only one register for each combination of "posicao" and "objeto". INSERT INTO `eventos` (`id`, `objeto`, `data`, `hora`, `localizacao`, `estado`, `acao`, `mensagem`, `alteracao_dias`, `posicao`) VALUES (1, 'OD583091439BR', '25/11/2020', '13:38', 'FLORIANOPOLIS', 'SC', 'Objeto entregue ao destinatário', 'Objeto entregue ao destinatário ', 159, 0), (2, 'OD583091439BR', '25/11/2020', '11:48', 'FLORIANOPOLIS', 'SC', 'Objeto saiu para entrega ao destinatário', 'Objeto saiu para entrega ao destinatário ', 159, 1), (3, 'OD583091439BR', '24/11/2020', '07:34', 'SAO JOSE', 'SC', 'Objeto em trânsito - por favor aguarde', 'Objeto em trânsito - por favor aguarde de Unidade de Tratamento em SAO JOSE / SC para Unidade de Distribuição em FLORIANOPOLIS / SC', 160, 2), (4, 'OD583091439BR', '23/11/2020', '21:14', 'PORTO ALEGRE', 'RS', 'Objeto em trânsito - por favor aguarde', 'Objeto em trânsito - por favor aguarde de Unidade de Tratamento em PORTO ALEGRE / RS para Unidade de Tratamento em SAO JOSE / SC', 161, 3), (5, 'OD583091439BR', '23/11/2020', '16:36', 'NOVO HAMBURGO', 'RS', 'Objeto em trânsito - por favor aguarde', 'Objeto em trânsito - por favor aguarde de Agência dos Correios em NOVO HAMBURGO / RS para Unidade de Tratamento em PORTO ALEGRE / RS', 161, 4), (6, 'OD583091439BR', '23/11/2020', '09:35', 'NOVO HAMBURGO', 'RS', 'Objeto postado', 'Objeto postado ', 161, 5), (7, 'OD583091439BR', '25/11/2020', '13:38', 'FLORIANOPOLIS', 'SC', 'Objeto entregue ao destinatário', 'Objeto entregue ao destinatário ', 159, 0), (8, 'OD583091439BR', '25/11/2020', '11:48', 'FLORIANOPOLIS', 'SC', 'Objeto saiu para entrega ao destinatário', 'Objeto saiu para entrega ao destinatário ', 159, 1), (9, 'OD583091439BR', '24/11/2020', '07:34', 'SAO JOSE', 'SC', 'Objeto em trânsito - por favor aguarde', 'Objeto em trânsito - por favor aguarde de Unidade de Tratamento em SAO JOSE / SC para Unidade de Distribuição em FLORIANOPOLIS / SC', 160, 2), (10, 'OD583091439BR', '23/11/2020', '21:14', 'PORTO ALEGRE', 'RS', 'Objeto em trânsito - por favor aguarde', 'Objeto em trânsito - por favor aguarde de Unidade de Tratamento em PORTO ALEGRE / RS para Unidade de Tratamento em SAO JOSE / SC', 161, 3), (11, 'OD583091439BR', '23/11/2020', '16:36', 'NOVO HAMBURGO', 'RS', 'Objeto em trânsito - por favor aguarde', 'Objeto em trânsito - por favor aguarde de Agência dos Correios em NOVO HAMBURGO / RS para Unidade de Tratamento em PORTO ALEGRE / RS', 161, 4), (12, 'OD583091439BR', '23/11/2020', '09:35', 'NOVO HAMBURGO', 'RS', 'Objeto postado', 'Objeto postado ', 161, 5); Right, I am trying to do with the code informed by you, but I am missing somethings, could you check for me? foreach($resultado["$objeto"] as $key => $item) { $location = explode('/', $item['location']); $stmt = $conn->prepare('INSERT INTO eventos (objeto, data, hora, localizacao, estado, acao, mensagem, alteracao_dias, posicao) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)WHERE NOT EXISTS ( SELECT null FROM eventos WHERE posicao = ? )'); $stmt->bind_param('sssssssii', $objeto, // objeto $item['date'], // data $item['hour'], // hora trim($location[0]), // localizacao trim($location[1]), // estado $item['action'], // acao $item['message'], // mensagem filter_var($item['change'], FILTER_SANITIZE_NUMBER_INT), // alteracao_dias $key, $posicao ); $stmt->execute() or die("erro ao tentar cadastrar evento"); } |
How to correctly order a recursive DB2 query Posted: 04 May 2021 08:35 AM PDT Hello friendly internet wizards. I am attempting to extract a levelled bill of materials (BOM) from a dataset, running in DB2 on an AS400 server. I have constructed most of the query (with a lot of help from online resources), and this is what I have so far; @set item = '10984' WITH BOM (origin, PMPRNO, PMMTNO, BOM_Level, BOM_Path, IsCycle, IsLeaf) AS (SELECT CONNECT_BY_ROOT PMPRNO AS origin, PMPRNO, PMMTNO, LEVEL AS BOM_Level, SYS_CONNECT_BY_PATH(TRIM(PMMTNO), ' : ') BOM_Path, CONNECT_BY_ISCYCLE IsCycle, CONNECT_BY_ISLEAF IsLeaf FROM MPDMAT WHERE PMCONO = 405 AND PMFACI = 'M01' AND PMSTRT = 'STD' START WITH PMPRNO = :item CONNECT BY NOCYCLE PRIOR PMMTNO = PMPRNO) SELECT 0 AS BOM_Level, '' AS BOM_Path, MMITNO AS Part_Number, MMITDS AS Part_Name, IFSUNO AS Supplier_Number, IDSUNM AS Supplier_Name, IFSITE AS Supplier_Part_Number FROM MITMAS LEFT OUTER JOIN MITVEN ON MMCONO = IFCONO AND MMITNO = IFITNO AND IFSUNO <> 'ZGA' LEFT OUTER JOIN CIDMAS ON MMCONO = IDCONO AND IDSUNO = IFSUNO WHERE MMCONO = 405 AND MMITNO = :item UNION ALL SELECT BOM.BOM_Level, BOM_Path, BOM.PMMTNO AS Part_Number, MMITDS AS Part_Name, IFSUNO AS Supplier_Number, IDSUNM AS Supplier_Name, IFSITE AS Supplier_Part_Number FROM BOM LEFT OUTER JOIN MITMAS ON MMCONO = 405 AND MMITNO = BOM.PMMTNO LEFT OUTER JOIN MITVEN ON IFCONO = MMCONO AND IFITNO = MMITNO AND IFSUNO <> 'ZGA' AND MMMABU = '2' LEFT OUTER JOIN CIDMAS ON MMCONO = IDCONO AND IDSUNO = IFSUNO ; This is correctly extracting the components for a given item, as well as the sub-components (etc). Current data looks like this (I have stripped out some columns that aren't relevant to the issue); https://pastebin.com/LUnGKRqH My issue is the order that the data is being presented in. As you can see in the pastebin above, the first column is the 'level' of the component. This starts with the parent item at level 0, and can theoretically go down as far as 99 levels. The path is also show there, so for example the second component 853021 tells us that it's a 2nd level component, the paths up to INST363 (shown later in the list as a 1st level), then up to the parent at level 0. I would like for the output to show in path order (for lack of a better term). Therefore, after level 0, it should be showing the first level 1 component, and then immediately be going into it's level 2 components and so on, until no further level is found. Then at that point, it returns back up the path to the next valid record. I hope I have explained that adequately, but essentially the data should come out as; Level | Path | Item | 0 | | 10984 | 1 | : INST363 | INST363 | 2 | : INST363 : 853021 | 853021 | 1 | : 21907 | 21907 | Any help that can be provided would be very much appreciated! Thanks, |
Can't connect to SQL Server database from UWP Posted: 04 May 2021 08:35 AM PDT I have a UWP C# app and I need to connect to my SQL Server Express database. When I connect to the database from tools option in Visual Studio, I can copy the connection string. Connectivity tests successfully, but when I try to connect with code I always get this error: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 25 - Connection string is not valid) string connectionString = @"Data Source=DESKTOP-IF672GA\SQLEXPRESS;Initial Catalog=TestDatabase;Integrated Security=True"; SqlConnection sc = new SqlConnection(connectionString); sc.Open(); |
How to edit and save TOML content in Python Posted: 04 May 2021 08:35 AM PDT |
Unexpected token # in JSON at position 0 when opening ipynb file in vscode Posted: 04 May 2021 08:35 AM PDT I have a ipynb file (a jupyter notebook) which I am opening in vscode with python extension. I receive the error in the title Unexpected token # in JSON at position 0 which I dont understand at all, since the file is supposed to be interpreted as a python file. I can change the extension to .py and its opened fine by vscode, but I dont have the decorators to run/debug cells like define here (https://code.visualstudio.com/docs/python/jupyter-support-py). I know the file is correct because I have use it in another vscode installation in another computer and works fine. I have no idea what might be misconfigured in my environment... Any tops would be really helpful. Here is the actual python code I have that its producing the mentioned error my actual environment. issue.ipynb # %% import world as w import world_eg as weg import world_case1 as wc1 import simulator_static as simulation import numpy as np from scipy.optimize import minimize import matplotlib.pyplot as plt``` From the error, I understand that is parsing the file as a JSON file and the first line, which contains the #, fails. |
In C++, does the scope of a named parameter include the expression for its default value? Posted: 04 May 2021 08:35 AM PDT Example: Is this legal C++14? #include <iostream> static int d() { return 42; } static int e(int d = d()) { return d; } int main() { std::cout << e() << " " << e(-1) << std::endl; } g++ 5.4 with -std=c++14 likes it, but clang++ 3.8 with -std=c++14 complains: samename.cxx:3:23: error: called object type 'int' is not a function or function pointer static int e(int d = d()) {return d;} ~^ |
Is __init__.py not required for packages in Python 3.3+ Posted: 04 May 2021 08:35 AM PDT I am using Python 3.5.1. I read the document and the package section here: https://docs.python.org/3/tutorial/modules.html#packages Now, I have the following structure: /home/wujek/Playground/a/b/module.py module.py : class Foo: def __init__(self): print('initializing Foo') Now, while in /home/wujek/Playground : ~/Playground $ python3 >>> import a.b.module >>> a.b.module.Foo() initializing Foo <a.b.module.Foo object at 0x100a8f0b8> Similarly, now in home, superfolder of Playground : ~ $ PYTHONPATH=Playground python3 >>> import a.b.module >>> a.b.module.Foo() initializing Foo <a.b.module.Foo object at 0x10a5fee10> Actually, I can do all kinds of stuff: ~ $ PYTHONPATH=Playground python3 >>> import a >>> import a.b >>> import Playground.a.b Why does this work? I though there needed to be __init__.py files (empty ones would work) in both a and b for module.py to be importable when the Python path points to the Playground folder? This seems to have changed from Python 2.7: ~ $ PYTHONPATH=Playground python >>> import a ImportError: No module named a >>> import a.b ImportError: No module named a.b >>> import a.b.module ImportError: No module named a.b.module With __init__.py in both ~/Playground/a and ~/Playground/a/b it works fine. |
No comments:
Post a Comment