From 7d800598b65aa603c298df7c09a9df49785588fd Mon Sep 17 00:00:00 2001 From: Gabor Szabo Date: Sat, 9 Nov 2024 09:23:41 +0200 Subject: [PATCH] comments --- .../en/pages/a-polling-station-with-flask.txt | 34 ++++++- sites/en/pages/add-code-snippets-to-atom.txt | 20 +++- sites/en/pages/ajax-request-for-json-data.txt | 26 ++++- ...v-raw-command-line-arguments-in-nodejs.txt | 8 +- .../automatic-counter-using-angularjs.txt | 7 +- .../convert-string-to-number-in-ruby.txt | 17 +++- ...reate-and-download-csv-with-javascript.txt | 97 ++++++++++++++++++- .../pages/creating-an-iterator-in-python.txt | 13 ++- .../dependency-injection-in-angularjs.txt | 6 +- ...thon-flask-using-uwsgi-on-ubuntu-14-04.txt | 8 +- ...notification-from-the-mac-command-line.txt | 71 +++++++++++++- ...enforcing-commit-message-format-in-git.txt | 43 +++++++- .../pages/function-or-callback-in-python.txt | 60 +++++++++++- .../en/pages/git-workflow-for-individuals.txt | 10 +- ...ebars-with-dynamically-loaded-template.txt | 8 +- ...ring-to-uppercase-or-lowercase-in-ruby.txt | 20 +++- sites/en/pages/http-requests-in-python.txt | 47 ++++++++- 17 files changed, 478 insertions(+), 17 deletions(-) diff --git a/sites/en/pages/a-polling-station-with-flask.txt b/sites/en/pages/a-polling-station-with-flask.txt index 731980cd..cd753265 100644 --- a/sites/en/pages/a-polling-station-with-flask.txt +++ b/sites/en/pages/a-polling-station-with-flask.txt @@ -5,7 +5,7 @@ =books flask, python =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -221,4 +221,36 @@ $ git commit -m "show the results" Testing the Flask Poll. +

Comments

+hello in part where we add " + + +@app.route('/poll') +def poll(): +vote = request.args.get('field') +return vote " +the /poll pagedoesn't show me the selection I've made + +The code: +from flask import Flask, render_template +import os +app = Flask(__name__) + +poll_data = { +'question' : 'Which web framework do you use?', +'fields' : ['Flask', 'Django', 'TurboGears', 'web2py', 'pylonsproject'] +} + +@app.route('/') +def root(): +return render_template('poll.html', data=poll_data) +@app.route('/poll') +def poll(): +vote = request.args.get('field') +return vote + +if __name__ == "__main__": +app.run(debug=True) + + diff --git a/sites/en/pages/add-code-snippets-to-atom.txt b/sites/en/pages/add-code-snippets-to-atom.txt index b6046923..47c3db0d 100644 --- a/sites/en/pages/add-code-snippets-to-atom.txt +++ b/sites/en/pages/add-code-snippets-to-atom.txt @@ -5,7 +5,7 @@ =books atom =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -76,3 +76,21 @@ I know this because I opened the Settings (Actually the Atom / Pref and among the Packages looked for the one handling HTML files. This is how it looks like: HTML file type in Atom + + +

Comments

+ +Exactly what I was looking for to bet a long ad code snippet working. Thanks.. + +
+ +How can i stop auto-complete to mess with my snippets? When i tab, it does code completation instead of my snippet! Is it possible to do bind it in another key? + +
+ +Thank you! This was helpful. Do you know of a community site where snippet examples and shared? Maybe a github repo? + +
+ +This was super-helpful! Thank you!! + diff --git a/sites/en/pages/ajax-request-for-json-data.txt b/sites/en/pages/ajax-request-for-json-data.txt index a2628cf2..c2f0d1cf 100644 --- a/sites/en/pages/ajax-request-for-json-data.txt +++ b/sites/en/pages/ajax-request-for-json-data.txt @@ -5,7 +5,7 @@ =books javascript =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -75,3 +75,27 @@ to create and html string from various parts of this data object. This is not re I am going to use this opportunity to show a more convincing reason to use Handlebars that I had in the introduction to Handlebars +

Comments

+ +Awesome + +
+ +how do you fetch and render the entire json file content instead of fetching individual element values? i was thinking about something like below... + +document.getElementById("TEXTAREA_ID").innerHTML = `${data}`; + +but it doesnt work... +
+Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://www.google.fr/. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing). + +
+ +why xmlhttp.readyState == 4, and xmlhttp.status == 200 ? + +--- + +Good Question, see here https://developer.mozilla.org/en-US/docs/Web/API/XMLHttpRequest/readyState + +This should give you an idea why. + diff --git a/sites/en/pages/argv-raw-command-line-arguments-in-nodejs.txt b/sites/en/pages/argv-raw-command-line-arguments-in-nodejs.txt index af1b6570..f42215c6 100644 --- a/sites/en/pages/argv-raw-command-line-arguments-in-nodejs.txt +++ b/sites/en/pages/argv-raw-command-line-arguments-in-nodejs.txt @@ -5,7 +5,7 @@ =books nodejs =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -108,4 +108,10 @@ $ node argv.js hello Param: hello +

Comments

+thanks for awesome and simple entry guide + +
+ +Just used this to troubleshoot a problem in someone else's code. One of the arguments wasn't being passed correctly on the command line. Thanks! diff --git a/sites/en/pages/automatic-counter-using-angularjs.txt b/sites/en/pages/automatic-counter-using-angularjs.txt index fd609625..971530d0 100644 --- a/sites/en/pages/automatic-counter-using-angularjs.txt +++ b/sites/en/pages/automatic-counter-using-angularjs.txt @@ -5,7 +5,7 @@ =books angularjs, javascript =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -104,3 +104,8 @@ and create the new $timeout object only if the timer was null. + +

Comments

+ +Is it possible to add a save button and save the elapsed (time) count in the above script? Maybe make the elapsed time counter value a variable in an ionic application? + diff --git a/sites/en/pages/convert-string-to-number-in-ruby.txt b/sites/en/pages/convert-string-to-number-in-ruby.txt index 8ac5fb89..54919a98 100644 --- a/sites/en/pages/convert-string-to-number-in-ruby.txt +++ b/sites/en/pages/convert-string-to-number-in-ruby.txt @@ -5,7 +5,7 @@ =books ruby =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -131,4 +131,19 @@ puts e.to_c # 23000.0+0i +

Comments

+ +foo.to_i" works for simple cases. One might consider: "Integer(foo)". + +"1.4.5".to_i => 1 +Integer("1.4.5") => invalid value for Integer() + +Latter is better suited as a result. + +
+ +Hi, in this case my string is "12345.678" when use to_f then result is: 12345.67 (only 2 number after dot) +How can i get enough 12345.678 . I mean how can i get more number after dot. +Thanks guys + diff --git a/sites/en/pages/create-and-download-csv-with-javascript.txt b/sites/en/pages/create-and-download-csv-with-javascript.txt index eb48d976..7d61cb50 100644 --- a/sites/en/pages/create-and-download-csv-with-javascript.txt +++ b/sites/en/pages/create-and-download-csv-with-javascript.txt @@ -5,7 +5,7 @@ =books javascript =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -47,3 +47,98 @@ However, what happens if the data can also contain quotes? We will then have to This is not "unsolvable" of course, but it needs some more work and currently I did not have the need for that. +

Comments

+ +In Firefox is not working. I click the button and nothing happens.Thanks + +--- + +Firefox requires the download A-element to be present in the DOM before clicking and not created dynamically. So, just add a hidden or similar and fetch that instead of using createElement and you're set. :) + +(This might not be the official explanation, but it works) + +
+ +hye how can i click the save button and it will automatically save into my server not my laptop ? + +
+Excellent little example - just what I needed. +Thanks very much Gabor. + +
+ +Hi, is there any check to prevent delimiter inside data? What if any data will contain delimiter (",")? rows and columns wont match. Is there workaround for that? + +
+ +thanks, very handy! + +
+ +thank you .....its perfect + +
+ +I'm glad you explain each. line of code. Thanks! + +
+ +Thank you + +
+Chrome has an issue using encodeURI if the filesize is greater than 1mb. This discussion on StackOverflow shows how to use createObjectURL instead. +https://stackoverflow.com/questions/24610694/export-html-table-to-csv-in-google-chrome-browser/24611096#24611096 + +
+ +Hi, It is not working in IE 11. I have added tag in DOM. Whenever call function to download csv, getting alert, "Do you want to open application from this website". After click on Allow csv is not dwonloading. Working fine on chrome. Please help to eun on IE 11. + +
+ +Thank you very much! + +
+ +hello....I need your help...i want to export form data into csv file using plain JS + +
+ +Is there any option to set password for the files. + +
+ +How can we download multiple sheets? + +
+what if my delimiter in the string is ; instead of comma +--- + +Then join with a semi-colon instead; + +csv += row.join(';'); + + +
+ +Thank's for this solution, I'm saved :) + +
+ +i followed the steps hoewever i get my array values written in one row in CSV file, no \n is applied. +my data is an array returned by a function as : +var data = [days]; +return data; +and i call this function from the downloadCSV () + +
+ +Getting the following error: (TypeError: row.join is not a function) Any idea? + +
+ +Hi, How to achieve the same functionality in IE 11 ? + +
+ +Thank you! + diff --git a/sites/en/pages/creating-an-iterator-in-python.txt b/sites/en/pages/creating-an-iterator-in-python.txt index 22501ddb..8952ce74 100644 --- a/sites/en/pages/creating-an-iterator-in-python.txt +++ b/sites/en/pages/creating-an-iterator-in-python.txt @@ -5,7 +5,7 @@ =books python =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -112,3 +112,14 @@ elements), or it can be totally unrelated. (e.g. some user input. Elapsed time. Day of the week. Etc.) + + +

Comments

+ +Very nice. Thank you! + +
+ +%> python3 fibonacci_finate_iterator.py +TypeError: iter() returned non-iterator of type 'Fibonacci' + diff --git a/sites/en/pages/dependency-injection-in-angularjs.txt b/sites/en/pages/dependency-injection-in-angularjs.txt index f1814bf5..af78c396 100644 --- a/sites/en/pages/dependency-injection-in-angularjs.txt +++ b/sites/en/pages/dependency-injection-in-angularjs.txt @@ -5,7 +5,7 @@ =books angularjs =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -109,4 +109,8 @@ the function call. +

Comments

+ +Simple, short, and great explanation. When i saw in tutorials both ways you mention i couldn't understand when to use one or the other, and now i do thanks to you. + diff --git a/sites/en/pages/deploying-python-flask-using-uwsgi-on-ubuntu-14-04.txt b/sites/en/pages/deploying-python-flask-using-uwsgi-on-ubuntu-14-04.txt index 612a826f..0eaa6b09 100644 --- a/sites/en/pages/deploying-python-flask-using-uwsgi-on-ubuntu-14-04.txt +++ b/sites/en/pages/deploying-python-flask-using-uwsgi-on-ubuntu-14-04.txt @@ -4,7 +4,7 @@ =books flask =status show =author szabgab -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -389,4 +389,10 @@ my-uswgi.ini. For other options you might want to check out the
Deploying Flask on uWSGI in the documentation. +

Comments

+ +Got my app up and running, thank you, command "uwsgi --http-socket :9090 --plugin python --wsgi-file app.py --callabe app" worked. But there is still a typo - callale + +--- +fixed. thanks diff --git a/sites/en/pages/display-notification-from-the-mac-command-line.txt b/sites/en/pages/display-notification-from-the-mac-command-line.txt index cae07f34..f151719d 100644 --- a/sites/en/pages/display-notification-from-the-mac-command-line.txt +++ b/sites/en/pages/display-notification-from-the-mac-command-line.txt @@ -4,7 +4,7 @@ =status show =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -191,4 +191,73 @@ and I'll get a pop-up that remains on the screen later. So even if I am out of t I'll see the pop-up when I return to my computer. +

Comments

+ +This is brilliant! Just what I was looking for! :) + +
+ +Is there a way to specify a custom icon in the slide out notification? I know other apps have their own custom icons in the notifications side bar on the right of the screen. +--- + +I don't think it's possible, but please share if you've learned how :) + +
+This is so awesome!! +
+ +Great article. I placed this in an alias to run after long bash processes. + + alias notify='osascript -e "display notification \"done!\""' + +
+ +On Big Sur there is an additional title showing the process that triggered the banner (I guess). For these examples it is always "SCRIPT EDITOR". Any way to remove or customize it? + +
+ +Awesome ! + +
+I know I am a bit late to the party here but I can only use "with title" or "with icon" and nothing else after either of those. If I try +osascript -e 'display dialog "Hello world!" with title "title" subtitle "subtitle"' +I get the error message +syntax error: A identifier can’t go after this “"”. (-2740) +Basically putting anything after the initial with parameter gives an error. "with subtitle" also gives an error. So I am left using just "with title" or I can use "with icon". Anyone have any ideas why this doesn't work? I am on Big Sur. +--- +Instead of using " use ' +I hope it will work ^_^ + +
+ +Perfect. + +
+ +It would be nice to add an example of sending the notification of the result of another shell command. for example +``` +echo "hey"|xargs -I {} osascript -e 'display notification "{}"' +``` + +--- + +THANK YOU! + + +
+ +In my Xcode it shows failed to display notification. + +caused by: script error: osascript: no such component "JavaScript". + +Any solution for this? + +
+ +Nice insights. Just a further question: is it possible to detect a notification window in order to trigger an Automator workflow? +Something like: +if window "Hello World" from application System Events exists +... +end if + diff --git a/sites/en/pages/enforcing-commit-message-format-in-git.txt b/sites/en/pages/enforcing-commit-message-format-in-git.txt index 298366f9..7d2f41c1 100644 --- a/sites/en/pages/enforcing-commit-message-format-in-git.txt +++ b/sites/en/pages/enforcing-commit-message-format-in-git.txt @@ -4,7 +4,7 @@ =status show =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -82,4 +82,45 @@ It checks if the text starts with one of those. Using this will require you to update the .git/hooks/commit-msg file with the current task names, but will enforce the specific names. +

Comments

+ +Thanks for the useful article! I think there is an error in the first two examples, grep with a Regex pattern works only with -P parameter. To make it work, I needed to add it, so for example: + +test "" = "$(grep -P '^#(\d+)\s' "$1")" && { + +
+ +Thanks for this, it really solves my problem. However, is there an easy way to deploy it across my teams when they do their next pull? It looks like the .git folder is excluded from the repo. + +--- + +No AFAIK you cannot automatically distribute this. I would also not put any such enforcement on my team. I'd educate them and let them opt for self-enforcement if they feel the need. + +--- + +Why not? Shouldn't we require traceability be established between commits and the tickets that authorize the work? + +--- + +Since I made that comment I learned about the https://pre-commit.com/ project that would make it easy to distribute pre-commit hooks, but unless the computers of the developers are locked down they can always find a way to avoid the pet-commit hooks. If someone so much distrust their employees then, well, I don't have much to say. + +I sure think it is a good idea to have traceability, but it should not be extreme. If I want to fix a typo in a comment, do I need to open a ticket, get approval from management in order to do that? + +Do I need to get authorization to change a variable name to be more descriptive? + +I think that's not the right way to handle development. + + +
+ +Wouldn't this make Git consider the line to be comment (and to not include in the final commit message), because it starts with '#'? + +--- + +If you supply the comment on the command-line then this works. If you let it open an editor then indeed the solution is problematic. There are was to tell git to not consider # as a comment. A better solution might be not to use # as the leading character in my commit messages. + +--- +Yes, you can change comment character to something else with `core.commentChar`. + + diff --git a/sites/en/pages/function-or-callback-in-python.txt b/sites/en/pages/function-or-callback-in-python.txt index 871e46f9..3c908fb0 100644 --- a/sites/en/pages/function-or-callback-in-python.txt +++ b/sites/en/pages/function-or-callback-in-python.txt @@ -5,7 +5,7 @@ =books python =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -206,3 +206,61 @@ each other or by passing them to other sequence-generating functions. There are two additional solutions to this problem. One is by creating an iterator, and the other one is by creating a generator. + + +

Comments

+ +Good explanation. However, I don't see whether or where the callback function "def cb(values[-1])" is actually declared. I see on line 12 where it is referenced, but where do you actually define it? + +--- + +already read + +---- + +Hey there. +cb is defined on line 16 as we see on line 27 that we are using check_17 as cb. cb is the just name for the paramater used in fibonacci(). + +line 27: +res = fibonacci(check_17) + +so then at line 4 this is what the script will do: +def fibonacci(check_17): + +so line 12 would rea +r = check_17(values[-1]) + +which we then go to line 16 and run through that function just replacing 'v' for 'values[-1]'. + +Then we check the output of that function in the conditional at line 13 + +Lastly we have the conditional on line 28 that just makes sure that there is a value to print before printing. + +I hope that helps it make sense for those that didn't quite get it. + +
+ +nice explanation + +
+ +How is this a "callback function"? By definition, a callback function should be executed after the first one has ended. This looks like one of those high order functions, which are completely legitimate in Python, since functions are "first class citizens" and are treated equally as any other objects. + +
+ +values [-1], isnt it out of index ? or am I too naive here. + +--- + +I don't think that "naive" is the right word here. In Python you can use negative indexes values[-1] is the last element of the values list. + +
+ +Thanks Gabor, +You selected a good example to explain callbacks. + +
+ +Thanks that really helps with understanding callbacks, I can figure out how to implement this in a class , just assuming i need to use self. construct. + + diff --git a/sites/en/pages/git-workflow-for-individuals.txt b/sites/en/pages/git-workflow-for-individuals.txt index 05f2d085..f3e1b374 100644 --- a/sites/en/pages/git-workflow-for-individuals.txt +++ b/sites/en/pages/git-workflow-for-individuals.txt @@ -5,7 +5,7 @@ =books git =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -211,3 +211,11 @@ files or different areas of the same file. + +

Comments

+ +You don't need to rebase (though if you are working alone, you could, and there are advantages to that), but if you want your features nicely separated each on its own feature branch (so that `--first-parent` looks like a string of features), you can enforce merge even in fast-forward situation with `git merge --no-ff` (and I think it is possible to configure Git to have this behavior automatic). + +BTW. I have heard about git-imerge tool that allegedly has advantages of both merge and rebase, but never used it myself. + + diff --git a/sites/en/pages/handlebars-with-dynamically-loaded-template.txt b/sites/en/pages/handlebars-with-dynamically-loaded-template.txt index 07beb7bd..030bcd7c 100644 --- a/sites/en/pages/handlebars-with-dynamically-loaded-template.txt +++ b/sites/en/pages/handlebars-with-dynamically-loaded-template.txt @@ -5,7 +5,7 @@ =books handlebars, jquery =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -106,3 +106,9 @@ the display_template function: In this solution, the code fetching the raw template from the server was moved inside the display_template function. It is called if the template is not in the templates object. + +

Comments

+ +Do you think its beneficial to rend a new file with a 2/3 same partials and the middle partial missing or doing what you do here? + + diff --git a/sites/en/pages/how-to-convert-a-string-to-uppercase-or-lowercase-in-ruby.txt b/sites/en/pages/how-to-convert-a-string-to-uppercase-or-lowercase-in-ruby.txt index 85625561..b8b86da4 100644 --- a/sites/en/pages/how-to-convert-a-string-to-uppercase-or-lowercase-in-ruby.txt +++ b/sites/en/pages/how-to-convert-a-string-to-uppercase-or-lowercase-in-ruby.txt @@ -5,7 +5,7 @@ =books ruby =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -40,3 +40,21 @@ puts name # RUBY +

Comments

+ +Should not the output is based on name = 'Foo'? + +---- + +Yes, it is but I'm sure that wasn't important in this case. + +---- + + For most folk not especially, we get the intent... but imagine just starting to learn programming for the first time... what you see and what you expect are different, and you could get confused. + + +
+ +You did a good job. I think many people will benefit from this post. + + diff --git a/sites/en/pages/http-requests-in-python.txt b/sites/en/pages/http-requests-in-python.txt index 89b6a414..d447eaf0 100644 --- a/sites/en/pages/http-requests-in-python.txt +++ b/sites/en/pages/http-requests-in-python.txt @@ -5,7 +5,7 @@ =books python =author szabgab =archive 1 -=comments_disqus_enable 1 +=comments_disqus_enable 0 =abstract start @@ -137,3 +137,48 @@ If you run this program it will send the request as if it was Internet Explorer and let the system administrator wonder if you are really stuck with such an old browser. +

Comments

+ +If you wanted to send a User-Agent like a name to a particular proxy, etc..... what would be the appropriate way to do that... I think I am sending it but it doesn't seem to be received. It is populated in the "header" and sent - can you suggest a better way? + +--- +have you tried to see what happens when you access http://httpbin.org/user-agent ? That should show you if you managed to set the User-Agent or not. The particular proxy might look for something else though. Check in the docs of that proxy. + + +--- +Can you think of a better way to send an identifying "object" other then trying to use user-agent stuffed in the header? + +--- + +You will need to give a bit more explanation of what do you (or the site you are connecting to) needs. Can you explain a what are you trying accomplish? + +--- + +I am trying to pass an "id" in the header under user-agent so for example the header has an authorization code and then what was supposed to be a User-Agent: "BillyBob" so when it was passed.. the proxy would see the BillyBob and allow it to passthrough (I hope that makes sense to you) + +So headers = {'user-agent': "BillyBob", 'Authorization': 'abcd-eft...'} +than +r. = requests.get("https://name.com", data=json.dumps(hec_data), headers=headers, proxies=proxies, timeout=1) + + +--- + +That does not seem right. The User-Agent is usually the name of your browser not your personal ID or username. In any case you are already talking about a solution here. My question is what server are you trying to access? What does the documentation of it say about authentication? + +--- + +Just trying to push some captured data to Splunk that has to go through our proxy - I will have to do research as I don't have access to the proxy myself. But I agree it doesn't look right, but I am a beginning learner of Python so.... + +--- + +Have you tried using the proxies from https://docs.python-requests.org/en/latest/user/advanced/ ? + +--- + +Yes I have that in there as well… + +
+ +I tried - I think that it sends it - however perhaps User-Agent is not the appropriate way to do this... Being new to Python and etc... I am not really sure what is available and the best way. I will double check with the proxy team. Thank you so much for your reply :) + +