How to enable source highlighting when doing `less mycodefile.ext`

How to enable source highlighting when doing less mycodefile.ext Install source-highlight sudo apt install source-highlight Configure it on your .bash_profile lessWithSourceHighlightSetup() { # location of the script may vary src_hilite_pipe_script=`dpkg -L libsource-highlight-common | grep lesspipe` export LESSOPEN=”| ${src_hilite_pipe_script} %s” export LESS=’ -R ‘ } lessWithSourceHighlightSetup Use it on any code file less -N /path/to/mycode.ext view […]

Pascal Triangle Generator in Python, and then in Haskell – The Gubatron Method

Here’s in python, imperatively, and then in functional style without the need for loops. This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters Show hidden characters def pascal(n): […]

Python in Functional Style: How to add 2 lists of integers without using loops

Usually you’d add a list of integers this way: [pastacode lang=”python” manual=”a%20%3D%20%5B2%2C%202%2C%202%2C%202%5D%0Ab%20%3D%20%5B2%2C%202%2C%202%2C%202%5D%0Ac%20%3D%20%5B%5D%0Afor%20i%20in%20range(len(a))%3A%0A%20c.append(a%5Bi%5D%20%2B%20b%5Bi%5D)” message=”” highlight=”” provider=”manual”/] You can do it functionally without any loops in different ways: Using map and a lambda that adds them up [pastacode lang=”python” manual=”c%20%3D%20list(map(lambda%20x%2Cy%3A%20x%2By%2C%20a%2C%20b))” message=”” highlight=”” provider=”manual”/] or you can import the add operator as a named function [pastacode lang=”python” manual=”from%20operator%20import%20add%0Ac%20%3D%20list(map(add%2C%20a%2C%20b))” […]