A cow for her milk; a hen for her eggs; and a stock,
John Burr Williams
by heck, for her dividends.
HOWTO : Python string search
Quick self-note 🙂
different ways to search for content in a string in python
- Basic (and quickest)
if 'content' in string:
- String.find (second quickest and doesn’t need additional module)
if string.find('content'):
- re.match (uses regex engine, most powerful)
import reif re.search('content', string)
Good discussion here : https://stackoverflow.com/questions/4901523/whats-a-faster-operation-re-match-search-or-str-find
HOWTO : Replace first space in a line using Notepad++
Search for ^([^\s]*)(\s)
Replace with $1 AND_WHAT_EVER_STRING_YOU_WANT
Here is an example of searching for first space in a line and adding “',” to the string

Overheard : Process
Love this quote about process attributed to Tobi Lutke in multiple interviews. He said it in different ways, but here is the gist
There are three kinds of processes
- Process that makes things that were previously impossible to do, possible. That’s good.
- Process that makes something that was previously possible significantly simpler, which is also good.
- Remaining 99.9% of all process that exists in corporate America is the third category, which is actually just telling people to behave slightly different from what common sense tells them to do.
Source :
HOW TO : Add commas (,) at the end of every line using Notepad++
Thanks for this great nugget from Sumama Waheed
Many a time, you get some data as a CSV file and need to copy some of that data and include it in a SQL statement. For instance one of the rows in the CSV was first name in the format below
employee_id 1234 8765 9808 1235 8734 6723
And you need to put it in a SQL statement as below
SELECT * FROM employee_table WHERE employee_table.employee_id IN (1234, 8765, 9808, 1235, 8734, 6723)
That’s a lot of adding commas (,) at the end of every line. You can do it quickly in Notepad++ (you can do the same in any editor that supports regex) using the regex capability in search and replace using ($) as the search string and $, as the replace string.

Overheard : Revenue, Profit & Cash-Flow
Not sure about the origins of this phrase, but came across in a quarterly newsletter from Greenwood Investors
revenue is vanity, profit is sanity and cash-flow is reality
HOW TO : Configure nginx to use URI for modifying response content
That was a pretty long title for the post :). I love nginx for it’s flexibility and ease of use. It is like a swiss army knife.. can do a lot of things :).
We needed to serve some dynamic content for one of our use cases. If user visits a site using the following URL format http://example.com/23456789/678543 , we want to respond with some html content that is customized using the 23456789 and 678543 strings.
A picture might help here

Here’s how this was achieved
- Define a location section in the nginx config to respond to the URL path specified and direct it to substitute content
location ~ "^/(?<param1>[0-9]{8})/(?<param2>[0-9]{6})" {
root /var/www/html/test/;
index template.html;
sub_filter_once off;
sub_filter '_first_param_' '$param1';
sub_filter '_second_param_' '$param2';
rewrite ^.*$ /template.html break;
}
create a file named template.html with the following content in /var/www/html/test 
Breaking down the config one line at a time
location ~ "^/(?<param1>[0-9]{8})/(?<param2>[0-9]{6})" : The regex is essentially matching for the first set of digits after the / and adding that as the value for variable $param1. The first match is a series of 8 digits with each digit in the range 0-9. The second match is for a series of 6 digits with each digit in the range 0-9 and it will be added as the value for variable $param2
root /var/www/html/test/; : Specifying the root location for the location.
index template.html; : Specifying the home page for the location.
sub_filter_once off; : Specify to the sub_filter module to not stop after the first match for replacing response content. By default it processes the first match and stops.
sub_filter 'first_param' '$param1'; : Direct the sub_filter module to replace any text matching first_param in the response html with value in variable $param1.
sub_filter 'second_param' '$param2'; : Direct the sub_filter module to replace any text matching second_param in the response html with value in variable $param1.
rewrite ^.*$ /template.html break; : Specify nginx to server template.html regardless of the URI specified.
Big thanks to Igor for help with the configs!!
Я вас любил – Pushkin
Loved this English translation of Я вас любил by Alexander Pushkin. One of my most favorite poems in Russian. Thought Robin Kallsen did a great job of translating it into English.
Original – In Russian
Я вас любил: любовь еще, быть может, В душе моей угасла не совсем; Но пусть она вас больше не тревожит; Я не хочу печалить вас ничем. Я вас любил безмолвно, безнадежно, То робостью, то ревностью томим; Я вас любил так искренно, так нежно, Как дай вам бог любимой быть другим.
Translation – In English
I loved you once, and love, perhaps, has not Within my soul yet wholly lost its flame; But please do not be saddened or distraught - To trouble you would drench my heart in shame. I loved you once, though lacking hope completely, By envy and timidity worn thin; I loved you so sincerely and so sweetly - Ah, may God grant you be so loved again!
Overheard : Return on investment from a book
Quote from “The Rebel Allocator” by Jacob L. Taylor on the return on investment from reading a book
For around ten dollars, you get to have an in-depth conversation with an expert who dedicated years to distilling all the information about a topic. For the cost of a mediocre dinner, you get access to years of another human’s effort. I did the math. If it took the author one year of work, you’re paying them about one penny per hour. How much time does this penny-per-hour investment save you in culling through information? We’re talking lifetimes.

