Skip to main content

Posts

Use NVM to handle Angular-Node.js incompatibility (e.g., Uncaught SyntaxError: Unexpected token 'export')

Overview If you are a fullstack developer, the chances are that you will be creating multiple frontend or Node.js projects along the way. When you are creating new projects using the newest version of the cli (command-line interface) of a particular framework, you might be asked to install the most updated version of Node.js in order to utilize the newest feature. This might involve upgrading your Node.js version, which might not be compatible with other existing projects (e.g., using Angular) you have created before. A potential solution is to use nvm (Node Version Manager) to install multiple versions of Node.js and use a particular version of the Node.js to install the proper version of the cli (e.g., Angular-CLI) that can be used to manage a particular project. Here I will use a problem I run into to explain how to solve it. Problem There is a compatibility issue between Node.js and angular.js. For instance, I run into an error when I was using an incompatible version of Node.js ...

ngrok, a service to help you get a public URL for your local webserver

If you are looking for options to test your web app hosted on your own machine (e.g., laptop) remotely with someone, I recommend using a service called ngrok. https://ngrok.com/ It has many usages, but in the context of testing an app hosted on your own machine, the most important part is giving you a public URL that will redirect all the requests to your local webserver (e.g., Apache, Nginx, or whatever server you are running). You can give this URL to a testing participant without the need to host the app on a remote server. For instance, if you are testing your app using a sever on your machine, typically you can access your app in a URL like:  http://localhost:3000/?study=11 Using ngrok, you will have a dynamically generated URL like the following: https://3ebe3c019867.ngrok.io/ The service will redirect requests to https://3ebe3c019867.ngrok.io to http://localhost:3000 You can then share the following link with your testing participant for the participant to use your app. http...

Brackets: a free editor/environment for web development

 There are a lot of options, and VS Code is one of the top contenders. I am a VS Code fan, but if you are looking for an alternative, Brackets is another option that I find appealing. It was built for web development, using HTML/CSS/Javascript. I think it is especially helpful for people who just start learning HTML/CSS (and maybe Javascript). http://brackets.io/ Brackets has some built-in features that are pretty convenient. 1. auto-complete for CSS property and value. 2. Live preview the webpage to reflect the changes being made. You can make changes in code and see the result instantly. 3. In-place editing of CSS rules (you can select an element/class name in HTML and press the short keys to edit the corresponding CSS rules directly). 4. Code to browser mapping: you can select/edit an element in HTML or a rule in CSS, and the corresponding user interface elements or those that will be affected by the CSS rule will be highlighted in the browser. See this video for an overview. Th...

Prevent Endless Reboot after Updating your Apple Laptop's macOS, especially the macOS High Sierra 10.13 Supplemental Update

If you have a MacBook pro and you want to do the latest update (the small one after high sierra, or "macOS High Sierra 10.13 Supplemental Update"), you should probably 1. backup (e.g., time machine), 2. (important!) connect your laptop with ethernet, and 3. connect to a power source. My MacBook pro time-jumped to some time in 2016 after the update and it forced itself into a power-cord only endless reboot mode. No kidding! Endless reboot,  like you never hear the reboot sound effect so many times. After the update, it wouldn't start unless it was connected to a power source, but it would reboot a few seconds after that Apple loading progress bar reached around 60% or 90%. My current working hypothesis is that it has to be connected to the internet before it reaches that point. Otherwise, it restarts again before you could quickly choose a WiFi access point and enter the password. After a few hours trying all the special hotkey combinations suggested on the inter...

Basic tmux commands

Here are several basic commands for tmux , a terminal multiplexer. tmux list -> list all the session tmux attach -> attach the last session In session (or any window): Ctrl + b, c -> create window Ctrl + b, n -> next window Ctrl + b, p -> previous window Ctrl + b, l -> last window Ctrl + b, d -> detach session Ctrl + b, :rename-window New_Name_FOR_WINDOW -> rename current window In a window exit -> exist a window Reference Cheatsheet

Using Pandoc for Doing Citation and Bibliography in Markdown

Markdown is a simple formatting syntax that allows you to do common formatting with ease. Pandoc is a feature rich interpreter that helps you convert documents from one format to anther. If you are writing homework, research papers, or anything that needs citation and a bibliography, you can totally use Markdown and Pandoc to achieve that. Below is a set of instructions that you can follow to generate a document with in-text citation and bibliography. First, install Pandoc and the extension for creating citation ( pandoc-citeproc ).  There are several ways to install Pandoc, you can choose one of them recommended on the official website . On Mac, one way is to install Homebrew , a package manager, and then use Homebrew to install Pandoc and the extension. For Windows users, please refer the official website on how to install Pandooc and extension. Here I will show how to install Pandoc and the extension for citation through Homebrew. After installing homebrew, you can ...

How to update multiple fields in an SQL update statement

Syntax: /* the correct way of putting multiple fields together, using comma */ UPDATE `stories` SET `content`='Once upon a time ...', `update_time`=now() WHERE id=1; Note: there is no 'and' between the fields you are trying to update. You should use comma between each pair of the fields you are trying to update. Otherwise, you will likely get an '0' as the result value in the 'content' field without getting any error message. If you do the following, you will likely get an '0' in the 'content' field, without any error message /* the wrong way of putting multiple fields together, using 'and' */ UPDATE `stories` SET `content`='My Story' and `update_time`=now() WHERE id=1; See also:  http://stackoverflow.com/a/7375371

getFragmentManager = null when using 'fragment' tag in Android layout file

I was using 'fragment' tag in the layout file for the Android app I was developing, as shown in the first code block. The id of the layout file for the CalendarFragment (.java) is R.id.calendar. I want to get the CalendarFragment instance in my code at runtime using getFragmentMeneger.findFragmentById(R.id.calendar) but kept getting null result. I ended up using getFragmentMeneger.findFragmentById(R.id.left1), the id for the 'fragment' tag in the main layout file to get the CalendarFragment at run time and it works. 'fragment' tag in the layout file for MainActivity.java: Actual layout file for the CalendarFragment.java: Actual java code in MainActivity.java to access the fragment:

Install Maynard Desktop Shell on Raspberry Pi

There is a light-weight desktop environment, Maynard, for Raspberry Pi. Here are the steps to install and start using it. wget http://raspberrypi.collabora.co.uk/setup-maynard.sh chmod 755 setup-maynard.sh ./setup-maynard.sh // reboot // login maynard // enjoy Reference: http://raspberrypi.collabora.co.uk/maynard.html

Tutorial: Look for strings that start with a specific sub-string using regular expression in Python

In this example, we used regular expression to implement the strings.startswith() function. The program will ask for users' input on a sub-string to find at the beginning of each string. The program will then open a file and print out the lines that start with the sub-string being specified. #Implementing Python's string.startswith() using regular expression # import the regular expression module import re # allow users to specify what string to look for as the start of a string start_str = raw_input("Enter the string that starts a line: ") # specify the name of the file to search within file_name = 'my_file.txt' # open the file for reading file_h = open(file_name, 'r') # define the pattern # ^ : start of the string # {} : place holder for start_str # ^{} -> ^start_str # -> pattern: a string that starts with the content stored in start_str # if You want to specify a word, followed by a space, that starts a string # leave a space after ...

A way to sort a Python dictionary by value, instead of key

Here I used the code on page 122 ~ 123 of the book ' Python for Informatics ’ by Charles Severance (Dr. Chuck) as an example to explain how to sort the key value pairs in a Python dictionary by value. # open the file named remeo.txt fhand = open('romeo.txt') # create a dictionary counts = dict() # read the file line by line for line in fhand: # split the line by whitespace characters (space, tab, newline, return, formfeed) words = line.split() # read the individual word for word in words: # increase the word count by 1 for that specific 'word' counts[word] = counts.get(word, 0 ) + 1 # create our list lst = list() # iterate over each tuple (key value pair) in the list generated by counts.items() for key, val in counts.items(): # create a new tuple (value, key) and append to our list, so that sort() will sort the list by the first element, value. # if we want to sort the list (or you can say dictionary) by key, we ...

Tutorial: Using String.find() and String slicing with [n:m] notation to extract data in Python

When you need to extract data from a string in Python, you can use the built-in String.find() method in Python and the String[n:m] notation to extract the sub-string. string.find(str) will return the starting position of the first instance of str in string. For example. 'abcdecd'.find('cd') will return 2, because the first 'cd' instance starts at position 2 (not 3, since position starts with 0). If no str can be found in the string, the method will return -1. str[n:m] notation will extract the sub-string starting at position n and ending at position m-1, not including the m-th character. For example, if the content of my_str is 'I don't know', my_str[2:] will return 'don't know'. By using string.find() and [n:m] notation, we can write a script to automatically extract the data we need from a string. For example, we have a file test_score.txt that records the scores of all the students enrolled in a class. We know that each line re...

How to install PyQT , QT and SIP on Mac

Step 1: Install QT Download and install from here:  http://qt-project.org/downloads   (Locate where the "qmake" is. For example, "/Applications/Qt5.1.1/5.1.1/clang_64/bin/qmake" when I choose to install qt at "/Applicaitons/Qt5.1.1") Step 2: Install SIP Download the package from here:  http://www.riverbankcomputing.co.uk/software/pyqt/ Unzip it and "cd" into the resulted folder. python configure.py make sudo make install (Review the output messages and locate where sip is installed. For example, "/System/Library/Frameworks/Python.framework/Versions/2.7/bin/sip".) Step 3: Install PyQT Download the package from here:   http://www.riverbankcomputing.co.uk/software/pyqt/ Unzip it and "cd" into the resulted folder. python configure.py --qmake where_qmake_is --sip where_sip_is (ex. python  configure.py  --qmake /Applications/Qt5.1.1/5.1.1/clang_64/bin/qmake --sip /System/Library/Frameworks/Python.fra...

Setting MySQL to Use UTF-8 on MAMP (MySQL 5.5.9, or 5+)

I wanted to setup MySQL to use utf-8 on the MAMP installation on my Mac. I tried the instructions from this article: http://cameronyule.com/2008/07/configuring-mysql-to-use-utf-8/ However, I kept getting error messages that are similar to this one [ERROR] /Applications/MAMP/Library/bin/mysqld: unknown variable 'default-collation=utf8_general_ci' I did some search and realized that several variables are deprecated. Reference: http://dev.mysql.com/doc/refman/5.1/en/server-options.html Therefore, I added the following lines into /Applications/MAMP/conf/my.cnf [mysql] character-set-server=utf8 [client] character-set-server=utf8 [mysqld] character-set-server=utf8 collation-server=utf8_general_ci init-connect='SET NAMES utf8' I restarted the server and mysql run successfully with relevant variables being set correctly. In the "Variables" tab under phpMyAdmin interface (ex. http://localhost:8888/MAMP/?language=English) character set c...

Programmers of All Levels Needed for Research Study! ($20)

Do you regularly code and seek information on the Internet? If so, I would like to invite you to participate in a study of programmers’ online information seeking. Pei-Yao (Perry) Hung, a graduate student from the School of Information at the University of Michigan, is conducting a study to understand how programmers with various levels of expertise seek information online regarding their programming tasks. All the details (e.g., qualifications) of the study are included here: http://bit.ly/146na6b The study will span 2 weeks and take less than 30 minutes each week for you, with the option to extend it to 4 weeks if interested. If you successfully complete the study, you will receive gift cards ($20 for a pre-study interview and the first two weeks, with an additional $20 for the optional two weeks and a follow-up interview) for your effort. Please consider participating in this study and help share this information to people who might be interested. Contact Perry through pe...

Resolve "Box Sync" (online storage) recent issue of crashing (halting) and not syncing on Mac/macbook

My Box (https://www.box.com/) online storage client software stop working on your Mac recently. I found one possible workaround, and I will describe it here. Open "Activity Monitor". Search among "All Processes" for "Box". You will see two process: "Box Sync Engine and "Box Sync".  Stop those two processes by first selecting process and then pressing "Quit Process". Download the latest version of "Box Sync" from Box's web site. (I didn't check whether it is a newer version then what I have on my computer.) Install the latest version of "Box Sync". Provide account information to login and start syncing. Your Box should work correctly after executing the above procedure. I didn't investigate the issue, but I got my Box working by following this procedure. Hope this help!

Install couchdb for lisp on Debian

// every time you meet PGP signature, skip the checking // other wise, try to accept the condition, treat it like it is successfully installed (for the example*.lisp, which sounds reasonable to skip) // I install the package in the system-wide directory // install debian package: couchdb, lisp package: clouchdb, cl-couchdb sudo apt-get install cl-asdf sudo apt-get install couchdb sudo apt-get install erlang (not sure if it is needed) sudo sbcl (require ‘asdf) (require ‘asdf-install) (asdf-install:install ‘cl-couchdb) error: cl-couchdb-test component missing sudo apt-get install cl-cclan (not sure if it is needed) (asdf-install:install ‘cl-couchdb) (asdf-install:install ‘clouchdb) debugger invoked on a SB-INT:STREAM-DECODING-ERROR in thread #<THREAD “initial thread” RUNNING {1002CA6DD1}>: decoding error on stream #<SB-SYS:FD-STREAM for “file /usr/lib/sbcl/site/clouchdb_0.0.11/examples.lisp” {1005FE5DB1}> (:EXTERNAL-FORMAT :ASCII): the octet sequence (195) canno...