Beautiful Soup Detailed docs: the Beautiful Soup 4 Docs.
Assume t is an object of Tag.
Core concepts (classes) Tag, a Tag object corresponds to an XML or HTML tag. BeautifulSoup, the BeautifulSoup object represents the parsed document as a whole. You can treat it like a special Tag. It needs a parser to parse the document, a built-in parser is "html.parser", e.g. soup = BeautifulSoup("<html>a web page</html>", 'html.parser') NavigableString, a string corresponds to a bit of text (as you see it in the browser) within a tag.
[Read More]
Clojure reduce: one case for text processing
As a practice, I managed to illustrate Clojure files using illustrate.clj, but my original idea was to annotate org-mode files of blogs. It's not uncommon that a blog post has some code snippets.
But it missed the feature until last night, as I wasn't sure how to implement it appropriately before and didn't have enough time.
For example, I may have an org-mode like this:
sum of two numbers: #+begin_src clojure (+ 1 2) #+end_src I want to have a result comment ((;; => 3)) after each top-level form after using illustrate.
[Read More]
illustrate.clj to Illustrate Clojure Snippet
To get my hands dirty with Clojure, I am trying to find or implement Clojure's string functions in the sense of Python. Python has powerful string APIs, and I also want to see how powerful Clojure could be in this field. That would be interesting.
As shown in the cheatsheet, Clojure has implemented most of them, and there are some that I have to implement myself, like title-case.
Along the way, I found it was a little cumbersome to append the evaluation result and the result of calling them, for example,
[Read More]
String Title Case in Clojure
These days I like to write scripts for some tasks in Python instead of shell. One important reason I think that's because Python is powerful at string manipulation.
Recently I'm learning Clojure, and I'm trying to find similar ways in Clojure, one of them is s.title() for getting a title-cased version of a string. For example,
>>> ' Hello world'.title() ' Hello World' How to do that in Clojure? To make the problem simple, let's assume that the input string only has letters and spaces, that is, [a-zA-Z ] in regex pattern.
[Read More]
String Manipulation in Clojure
Python string APIs are powerful and concise, that is an important reason I use it to do a lot of scripting these days, join, split, strip, to name a few.
Since I am learning Clojure recently, I am wondering, how is string manipulation like in Clojure and how to implement equivalent ones?
I think it's an excellent opportunity to get familiar with Clojure. Before diving into the implementation, how to declare a multi-line string?
[Read More]
Send Notifications from Emacs with i3wm and Dunst
I barely use notifications, but recently I think it's a valuable way to remind me things like helping me nurture habits, or to notify me of emergencies like a critically low laptop battery.
So I try to integrate notifications to org-mode and Emacs today.
The org-notify package from org-contrib (install it by (package-install 'org-contrib) ) could do this job easily before, so I first test it in the minibuffer with (org-notify "test").
[Read More]
A Random Password Generator in Babashka
I'm used to learning by practicing, so when I learned Clojure, I always kept an eye on chances to write code in it.
Scripting is an excellent field to practice, but the experience is not so good. On the one hand, it's too hacky to wrap Clojure code in a shell script with the shell bang. On the other hand, the startup time of JVM is too long to hurt the user experience.
[Read More]
An Online Python re.findall Service
As a programmer, I know that grep, sed and awk are powerful for processing text, but they sometimes aren't that straight-forward for specific tasks, as I need to think about how to filter the lines and the columns out.
So I wonder if there is a handy way to do these tasks?
After using it for a while, I think using regex directly can help, so I launched a re.
[Read More]
Generate Call Graphs Using Doxygen in Emacs
Doxygen is a nice tool for generating documentations for well-annotated C/C++ projects, the one feature that I like most is generating call graphs and class diagrams, so that I can learn a project quickly by browsing the diagrams from a higher point of view.
I take the following steps to generate call graphs for a project on terminals on Linux:
cd /path/to/a/project/, and generate a template config file by doxygen -s -g doxygen.
[Read More]
Is It Safe to Use Redis As a Data Store?
Traditionally we are used to storing data in an RDBMS like MySQL, and avoid using in-memory solutions such as Redis, to have a confidence of no data loss. Sometimes I find that we are so stubborn with MySQL that ending up with a complicated design, and I've even seen a solution that stores data in MySQL and then using Redis as a cache for it to improve read performance in the meanwhile.
[Read More]