Member

[email protected]

Total likes received: 98 | Pubby Cash: 932


My Articles: 44

Hard-to-find Tiny Bugs in Code

Categories: Tech | Pubby Cash Received:  0

Based on my limited coding experience, I've summarized my top three tiny bugs that have wasted many of my valuable hours. I would like to share with you all so that you can avoid them by all means. No. 1. Punctuation and Spelling. A mistake of missing a comma would either cause an immediate trackback or temporarily got accepted but blow off your code in future. I had a field in a database table storing a list that is dynamically being appended, say [1,2,3,4,5,] and has been converted to string. Note that the list is ended with a comma in the square brackets. That comma costs me hours to make things at other places work as planned. Spelling is another thing that can be easily overlooked. When I was coding to communicate with a database via SQLAlchemy, I typed db.session.commmit(). That triple m drove me crazy when I found out with my old eyes. No. 2. Indentation. Tabs and white spaces are treated differently in Python. This is especially true when you are trying to copy a code snippet from elsewhere and paste it into your program. You thought they are identical and should work flawlessly. However, the cruel reality might be that you just cannot make it work. Tabs and white spaces cannot be distinguished by naked eyes. It takes me hours to find out that the Sublime Text editor has a function of converting all tabs to spaces, and that solves my problem. No. 3. Data Types. Operations with values of different data types will throw out an error. Although it is not difficult to realize that datetime and timedelta are incomparable, and strings are incomparable with other data types, the problem is: sometimes, it is visually impossible to tell the difference between a string and another datatype! Let's say x = 2. Now x is an integer. Then let's say y = str(2), and now y =2, too. But this "2" is different from the previous "2", because this "2" is a string. If you run x + y, it will throw off an error! The recommendation is: always check the data types to make sure you are well informed. If you are trapped in debugging processes, you could try to target on the above-mentioned three hard-to-find bugs. Hope this will help you out!...  Read more

Be a Trader in Real Stock Market with Your Pubby Cash

Categories: Tech | Pubby Cash Received:  0

Stock trading is about economics. This is also a skill that one definitely needs to master in the modern world. I'm glad to find that the GoPubby stock trading market is online. You have a selection of trading over 20 stocks with your Pubby Cash. The stocks on the market right now are choices of brand company names covering a variety of sections including technology, consumer goods, health, finance, energy, transportation, utilities, and so on. The reason I say this is real stock market is because you will be trading at real-time stock prices. For example, one share of Facebook stock costs 240 right now, you will be able to buy it at 240, and of course, the currency is not in US Dollars, but in Pubby Cash. After refreshing the page, if the stock price changed, your net worth will increase or decrease. You will gain or lose Pubby Cash only at the moment the stocks are sold. The recommendation is if you see the price of the stock you are holding decreases at a moment, keep holding it, unless you urgently need Pubby Cash at that moment. Be confident in the US economy! The overall trend of investment should make you gain money in the long run. A side note: Without Pubby Cash at a whole number multiple of one share price will not forbid you from buying that stock. Feel free to use a fractional number, no matter how small it is. You also don't need to invest all your Pubby Cash into the same company. You can split your Pubby Cash into multiple investments, which simulates S&P500 and can greatly lowers your investment risks. Have fun in the GoPubby Stock Market! ...  Read more

Write and Read a Dictionary into TXT file in Python

Categories: Tech | Pubby Cash Received:  0

I've been exploring an elegant way of exporting/importing a dictionary into/from an external TXT file for recording purposes. Say I have a dictionary with stocks codes and prices, and the dictionary's name is called stocks, and this dictionary is stored in a py file called rank.py. The txt file I've like to export to is 'stocks.txt'. The relative path from the operating py file to the txt file is 'static/stocks.txt'. To export the dictionary from the py file into the txt file, this code will be neat: from rank import stocks with open('static/stocks.txt', 'w') as f: print(stocks, file=f) To read the dictionary from the txt file, use this code: with open('static/stocks.txt', 'r') as f: content = f.read() stocks = eval(content) When it comes to the operation in flask route functions, I found it worked totally different with regard to the file path of the txt file. An error of "no file/file directory" keeps blowing off the code. Eventually I figured out that the file path should be written in a different way with the following code: import os from flask import current_app f_path = os.path.join(current_app.root_path, 'static/stocks.txt') with open(f_path, 'r') as f: content = f.read() stocks = eval(content) What a tricky debugging issue! ...  Read more

The Raffle Game

Categories: Tech | Pubby Cash Received:  10

It would be fun to find ways for pubbies to spend and earn Pubby Cash. Purchasing a raffle ticket is one of the ways the admin team has developed. Let me explain how this is realized. 1. Create a table in the database with sufficient columns to record all relevant raffle related information. The columns are: raffle id, date raffle opened, date raffle closed, current raffle pool, max raffle pool, transaction activities (a list with player id), winner id, and raffle status. The table should be declared as a model and linked to the code. 2. When a player trying to buy a raffle ticket, the database will be queried for the most recent game. If the most recent game is closed, a new game will be created. When the max raffle pool has reached (100 Pubby Cash) in this case, the status of the game will be changed to a closed state. Random number will be generated to determine who is the winner. 3. Update the database with relevant info. The tables that will be affected are the cash table, message table, user table, and of course the raffle game table. For the cash table, record the purchase transaction details. If a player wins, insert an additional transaction on the amount that he/she won. For the message table, update the table with a new message sent to the winner. For the user table, all players' Pubby Cash balance should be updated. For the raffle game table, the game record should be updated. 4. Generate a plot visualizing the dynamic purchasing activities of pubbies involved in the raffle game. This would require a data visualization module "matplotlib", which will generate a bar chart plotting the number of tickets each pubby purchased on the x axis, and the name of each pubby who purchased ticket(s). Then, a raffle game is all set to go! ...  Read more

Sublime Text vs. Pycharm, Which One is Better?

Categories: Tech | Pubby Cash Received:  20

Text editor is essential for python programming. Specifically, the default notepad that comes with the computer should be avoided, as it does not provide the debugging ability. The text editors programmers use have a fancy name: IDE, which is the abbreviation of Integrated Development Environment. IDE provides features like autocomplete, libraries, compiling, debugging, executing, etc., in one place to make tasks simpler. So far I've used PyCharm for several months and just switched to Sublime Text. Here is a review of what I feel about the two IDEs. 1. Both Pycharm and Sublime Text have the free version and the paid version. The paid version of PyCharm costs $199 per user per year, while the paid version of Sublime Text cost $80 per user. As for the free version, PyCharm is more clean, while Sublime Text prompt you to purchase from time to time when you are trying to save a file, which can be annoying. 2. PyCharm creates a virtual environment, which makes the launching process long. If you have an old computer like I do, it takes over 1 minute to launch the program. Sublime Text is more clean and opens in the blink of an eye, and thus is better in this aspect. 3. PyCharm is more GUI based, as you can click a button to run a py file after you add it to the configurations. Sublime Text is more terminal based. You must run command lines in terminal windows to test your file. But it does not slow you down at all as long as you are experienced in doing this. 4. Sublime Text has some cool features such as generating dummy text by typing "lorem" in an HTML file, populating a schema of an HTML file by typing "html", freely enlarging and reducing font sizes on screen by pressing Ctrl + or Ctrl -, auto wrapping codes, freely changing indentation styles, displaying codes full screen, etc, that PyCharm does not have. My preference goes towards Sublime Text at this time, as it speeds up my old computer. There are some other well-known python IDEs, such as Spyder, Pydev, Idle, Atom, Jupyter Notebook, etc. I could try them all one day. ...  Read more

1 ... 5 6 7 ... 9

Daily Deals


MECHANICSBURG WEATHER