Lin's Blog
|
  • Zh-Tw
  • Ja
  • Posts
  • Categories
  • About

Why Python Prints Nothing When Piped to tee

Recently I wrote a Slack bot in Python. Being lazy, I just print the log messages directly and save them to a file with the tee command. That way I can see the bot’s activity in the console and keep the same information in a file. But when I combined Python’s print() with tee, I found that the log file often had no content, or messages that should have appeared showed up much later. After some research, I learned that Python’s print function checks where its output is going. If the output goes to a shell, it is written immediately. If it doesn’t, the output is stored in a buffer and only written out once the buffer is full. So when you use Python with tee, you run into this buffering problem, and the expected output doesn’t show up on the screen or in the file in time. ...

Programming
#Python #Linux
June 16, 2018 · 2 min

BigQuery SQL String Split

Most programmers are familiar with split. It’s one of the ten most commonly used functions in programming. BigQuery has a split function too, but since it’s SQL, the usage is quite different from general-purpose programming languages. On top of that, BigQuery comes in two versions, Standard SQL and Legacy SQL. Both have split, but they are used in completely different ways. ...

Programming
#BigQuery #SQL
September 17, 2017 · 1 min

Fixing Google Drive on macOS Defaulting to Simplified Chinese

After installing Google Drive on macOS, I suspected it was a bug in the program. Even though my system language is set to Traditional Chinese, Google Drive displayed Simplified Chinese. It looked really unfamiliar, so I researched it and found a fix to share with everyone. Just open Terminal and enter the following command, then restart Google Drive, and it will switch to Traditional Chinese: defaults write com.google.GoogleDrive AppleLanguages '("zh-TW")'

Hardware
#MacOS #Google
September 17, 2017 · 1 min

BigQuery Federated Google Sheets Table Access Denied Error

BigQuery lets you link a table to a Google Sheet stored in Google Drive, so the table updates right away whenever the Google Sheet changes. When you use this kind of federated table, some people run into an Access Denied error. Queries in the WebUI work fine, but when you query the table with the bq command line tool, you get the following error message: Access Denied: BigQuery BigQuery: No OAuth token with Google Drive scope was found...

Programming
#BigQuery #Google
September 14, 2017 · 2 min

How to Quickly Count Items in Different Ranges with Excel

When analyzing data, you often need to split values into different ranges so you can see how they are distributed. For example, you might group students into 80-100 points, 60-80 points, and failing, then count how many students fall into each group for analysis. That’s where the FREQUENCY function in Excel (or Google Sheets) comes in very handy! ...

Software
#Excel
August 3, 2017 · 2 min

Generating a Datetime Series in Python

In Excel, you can generate a series of consecutive dates with a simple drag. In Python, you can do something similar with the datetime and timedelta modules. Whether you want intervals of one hour, one day, or one month, you can do it. ...

Programming
#Python #Pandas
July 30, 2017 · 2 min

BigQuery SQL Get First or Last Day of Month From a Specified Date

In BigQuery, if you want to get the first day from a date (or a timestamp or datetime value), for example turning “2017-05-24” into “2017-05-01”, you can call the UTC_USEC_TO_MONTH function in Legacy SQL, or DATE_TRUNC() in Standard SQL. In fact, BigQuery has a whole series of functions that do these things, getting the first day, hour, week, and so on from a date. ...

Programming
#BigQuery #SQL
July 29, 2017 · 2 min

BigQuery SQL Get Random N Row Sampling

When doing data analysis, randomly picking N rows from a dataset (sampling) is a very common need. You might sample to check whether the data is correct, or sample so a model can be built when there is too much data to process comfortably. Sampling with SQL inside the database is actually very simple. Here I’ll demonstrate with BigQuery Standard SQL, but Legacy SQL works the same way. ...

Programming
#BigQuery #SQL
July 28, 2017 · 1 min

Forcing a Hyperlink to Download a File in HTML

Modern browsers are smart. When a hyperlink points to a plain text file, a PDF, or a CSS file, the browser previews it instead of downloading it. But sometimes we want users to download the file directly instead of viewing it in the browser. For example, when I previously went to the jQuery official site to download jquery.js, it opened as a preview, and I had to right-click and choose “Save As.” But my goal was clear: I wanted to download the file, not view it! ...

Programming
#HTML
April 26, 2017 · 1 min

CSS Inner Border: Drawing a Border Inside the Box

While designing my personal landing page, I wanted to create an inner border effect, and I learned a clever technique for it. When it comes to a CSS inner border, your first instinct is probably to use padding or margin to make the box bigger. But that doesn’t work: when you enlarge the box, the border moves along with it, so you can’t create an inner border style this way. ...

Programming
#CSS
April 26, 2017 · 1 min
« Prev  Next 

Categories

All Programming AI SRE Life Hardware Software Blog Travel Web Apps Games Security
© 2026 Lin's Blog · Powered by Hugo & PaperMod