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

bash: warning: setlocale: LC_ALL: cannot change locale

Seeing the error “-bash: warning: setlocale: LC_ALL: cannot change locale” when you log in to a remote server over SSH? You run into it because when SSH connects to a remote host, it automatically sends a copy of your local LC_* variables (the locale) to the remote host. If the server doesn’t support the locale you specified, you’ll get the error “-bash: warning: setlocale: LC_ALL: cannot change locale”! ...

SRE
#Linux #SSH
February 22, 2017 · 1 min

Python 3 CP950 Error When Printing to the Windows Command Prompt

Today, while teaching some juniors how to program, I tried to print a line of Chinese text to the Command Prompt with Python, but I got the error “UnicodeEncodeError: ‘cp950’ codec can’t encode character”. I tried all kinds of methods without success, and in the end I found the answer by searching online. When experienced developers see this error, their first instinct is to assume the string contains a special character, so they immediately add the ignore parameter, but that does not help. When I checked, the character that caused the problem was a Japanese character. As everyone knows, Python 3 uses Unicode strings by default, so it should not have trouble printing anything. It’s not like we’re dealing with the notorious Big5 again… ...

Programming
#Python #Windows
February 21, 2017 · 2 min

Fixing HTML Anchor Content Hidden Behind a Menu

HTML anchors are very handy. When a page is long, an anchor lets visitors jump quickly to a specific section. This technique shows up in many technical documents and blogs. If you’ve seen a URL like https://coder.tw/?p=123#section1, that’s the HTML anchor feature at work. Although it’s convenient, it brings some problems. The most common one: there is a floating menu at the top of the page. When a visitor clicks an anchor link, the browser does scroll to the section, but part of the text ends up hidden behind the menu. I had always been annoyed by this, and today, while reading Facebook’s technical documentation, I found their solution, which is pretty good. ...

Programming
#HTML #CSS
February 20, 2017 · 2 min

Google Analytics Exception Tracking

Google Analytics has a hidden feature called exception tracking. It collects error messages from a website’s front end or back end (or from an app) so you can analyze them. Here’s an example from my recent project. When a user fills out a form and submits it, I validate the information they entered. If they forgot to fill in a field, the error message is sent to GA. Afterward, I check how many times that error message appeared in GA. To some extent, this can suggest whether the interface design is poor and causing users to skip that field. ...

Blog
#Google Analytics
February 19, 2017 · 2 min

Shared Links Not Showing Up as Expected on Facebook? Here's How to Optimize Your Site for Facebook!

For every webmaster, Facebook has become just as important a traffic source as Google. In the past, we did a lot of SEO work for search engines, but did you know that Facebook has also published a document, “Best Practices for Sharing Websites and Mobile Apps,” that explains how to adjust your web pages so they are displayed in the best way when users share them on Facebook? In this article, I’ll share what I tried on my personal blog. ...

Blog
#Facebook #SEO
February 18, 2017 · 5 min

How to Prevent the Input onFocus Event From Firing After Page onFocus

Recently I was working on adding Google Analytics user event tracking code to a website. I attached the code to inputs using HTML event handlers, so that whenever a user clicks a specific field or button, a record is sent to Google Analytics. This works fine, but I noticed a problem. If a user clicks into an input field, switches to another page (another Chrome tab), and then switches back to my page (Page onFocus), the input’s onFocus event fires automatically! ...

Programming
#JavaScript #HTML
February 16, 2017 · 2 min

Visual Studio Code: Auto-Indenting Pasted Code

Developers who switched from Sublime Text to Visual Studio Code (hereafter VS Code) surely miss the “Paste and Indent” feature! When coding, copying and pasting code is unavoidable, and the indentation often gets messed up afterward, so you have to fix it by hand. Sublime Text provides a so-called Paste and Indent feature that automatically matches pasted code to the indentation of the current file. VS Code has a similar feature, but it works differently and must be enabled in the settings file. ...

Programming
#Visual Studio Code
February 15, 2017 · 2 min

JavaScript: How to Check Whether a Variable Is NaN

JavaScript has so many strange quirks! Today, while using parseFloat to convert a string into a number, I learned that if the input can’t be converted to a number, it returns NaN (Not a Number). So I wrote the following code to check for it: var score = parseFloat(prompt("Score:")); if(score === NaN) { console.log("Not a Number"); } else { console.log(score); } At first glance, this code seems perfectly reasonable, just like comparing undefined or null directly with equality. Who knew it would completely fail? ...

Programming
#JavaScript
February 14, 2017 · 2 min

Worried About Visitors Copying Your Articles? Use JS to Automatically Append a Reminder or Disable Copying!

Many content sites have a mechanism that automatically appends the original article URL when text is copied, such as Mojing Lyrics and Zhihu. Some sites even ban users from copying text altogether. Achieving these features isn’t difficult; it only takes a few lines of simple JavaScript. But first you should think about whether your site really needs such a feature. When a regular visitor copies text and pastes it into Facebook, does that really harm your site? And if you truly want to stop visitors from copying text, these tricks only keep out the honest, not the determined. Are you really protecting your interests, or just making your site harder to use? ...

Blog
#JavaScript #SEO
February 12, 2017 · 4 min

Detention Chapter 4: How to Get Through the Broken Classroom

In the first stage of the final chapter of Detention, you can swap identities after talking with the soul fragment, and then you need to cross the broken classroom to reach the door on the other side. This stage is really hard, no question about it. If you got stuck like me, let’s work out how to clear it together! ...

Games
#Detention #Walkthrough
February 11, 2017 · 3 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