Skip to main content

Posts

Showing posts from 2018

Linux playing with end of line

I was trying to figure out why the checksum of file on the server having different value with the same file that being optimized by pagespeed.   It turns out, that pagespeed has a filter-whitespace-collapse   and the filter is enabled on our server.This filter will remove any unnecessary whitespace. So happen that the original file has one end line added, while the file that being optimized by pagespeed doesnt has that. to quickly validate this. i tried to search easiest way to check a file with end of line cat -E /tmp/script1 document.write("hello Recently, I published an")$ I can see that the script has end of line, "$" is the indicator. then i quickly search again, what is the simplest way to remove end of line in linux. tr -d "\n" < /tmp/script1 > /tmp/script1_removed_el the command actually will delete all newline in the file and output it to /tmp/script1_removed_el. Ok this is working for current scenario where my file is

Python regex finditer

Just a revision for me, sharing with you all! so i have problem to find multiple keywords in a text. i tried using re.search. but that wouldnt work. as re.search only applicable if keyword found first in a group match. so, lets go ahead! i ran using python2.7 Example code for find keywords appearance using python re.finditer (regex) search_keywords = ["smart", "high", "confident", "mature"]  Now we join the keywords with OR operator | , it will looks something like this  smart|high|confident|mature search_patterns = "|".join(search_keywords) Sample input text text = "This is a story about a girl. Living in a secluded area in Wonderland.\n" \        "She is small but very smart and smart, how ever she has verly low confident. Dont judge a book" \        "by its cover.\n The way she thinks shown how mature she is."  Now we update the pattern again with ( ) - > parenthesis  The object