Python Replace Texts For Each File

A useful function to replace certain texts for each files in a given folder:


Python Replace texts in all Files From a Folder and re-write

import os
# Getting the current work directory (cwd)
thisdir = os.getcwd()

folder = thisdir + '\\path_to_your_folder'

# r=root, d=directories, f = files
for r, d, f in os.walk(folder):
for file in f:
fPath = os.path.join(r, file)

read_lines = []
with open(fPath, 'r') as fp:
read_lines = fp.readlines()
read_lines = [line.rstrip('\n') for line in read_lines]

with open(fPath, 'w') as fw:
for line in read_lines:
newText = line.replace("your text 1 to replace", "replace with").replace('your text 2 to replace', 'repalce with').replace('you got the idea', 'your text to replace with').strip()
if(newText.endswith(')')):
newText = newText + ";"
# do something like append/prepend

if not newText.startswith('--'):
#skip certain lines if you want before writing
fw.write(newText + "\n")

How To Handle Right Click Action On Any Element On The Browser

Bind an event handler to the “contextmenu” Javascript event using jQuery.

This captures any Right Click event happening through out the web page.

Now if you want to handle Right Click on a particular element, you can do so by doing something like this:

 

Update On My Writing Career

Folks at w3Stuffs, which is a web/tech related online content magazine, have asked me to join their team of Authors and create content for them. So, I have been busy authoring articles (tutorials mainly) at w3Stuffs lately.

While I have not been able to write anything in my own personal blog here ):, as of now I have already written 17 different posts for w3Stuffs under my name!

I have also authored for Envato Tuts+ in the past where I have three articles.

I also have couple of articles at CodeMentor as well.

Furthermore, I have quite a few articles in my own Gigyasa as well where I try to write just one article every week.

Besides getting the perks of writing, I am also happy that I am getting opportunities to learn about SEO techniques as well from writing around the web.

New Project: Gigyasa

Hello,

This post is about introducing my new writing project “Gigyasa“. It is an online Blog Magazine where I will be writing and sharing some wisdom about Life on general that I have collected over the years.

I had been writing much notes here and there previously on my notebooks much of which were just sporadic writings. However,I would say the theme mainly revolved around around:

  • mindful living,
  • self transformation habits,
  • timeless principles,
  • contemplative thoughts
  • and similar matters of spirituality.

As I flipped through my notebooks last week, I realized that I had some quite good notes (at least in my opinion (: ). I thought it would be a pity to see them just rot down in my basement.

So, I decided upon starting this blog magazine to make use of my existing writings and also to keep it as a platform to write and talk about similar topics for the future.

This is just my initial thoughts and plans about Gigyasa, let’s see where it goes from there later.

Please feel free to review Gigyasa and give your constructive feedback to me.

Thanks!

How To Create A WordPress Blog From R Markdown?

Creating a WordPress blog directly from R Studio

The library packages that you would need for this purpose are:

  • RWordPress
  • knitr

library(RWordPress)
library(knitr)

You can download RWordPress  package from Git hub.

After you have the libraries loaded, you need to set up access to your wordpress site. For that, you will need:

  1. XML-RPC of your WordPress Blog
  2. Valid User Credentials
  3. Rmarkdown file to post

options(WordPressLogin = c(your_username = 'your_password'),
WordpressURL = 'www.sovitpoudel.com.np/xmlrpc.php')

filePath <- "D:\\R\\projects\\exploringClashRoyaleCards.Rmd"

knit2wp(filePath, title = 'Blogging directly from R using RWordPress', publish = FALSE)

The “knit2wp” function reads your markdown file and posts directly to your Blog a new blog post. You can configure whether you would like to publish the blog directly or not and also pass other parameters related to the post like keywords with this function.

You can upload texts, code blocks and outputs including the graphs with the help of this function setup.

Adding Colors and Syntax Highlights

By default, when we post WordPress Blog post directly from R Studio, the syntax highlights, and coloring are not compatible with WordPress Blog themes. We will need to manually provide reference to CSS and Javascript libraries for syntax highlighting codes.

We can achieve this by adding the following function in our functions.php file.


/* Add highlight.js support */
function highlight_load() {
wp_enqueue_style( 'highlight',
'//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/styles/default.min.css');
print "
<script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/highlight.min.js'>
</script>
<script src='//cdnjs.cloudflare.com/ajax/libs/highlight.js/8.4/languages/r.min.js'>
</script>
<script>hljs.initHighlightingOnLoad();</script>";}
add_action('wp_footer','highlight_load');

References:

Divergent Color

Color Usage In Data Analysis

Data Visualization is an integral part of Data Science and Data Analysis. It is a way of beautifully presenting information rather than using traditional spreadsheets and reports.

Humans, by nature, can more easily process information when provided with beautiful visualization as our brains are designed this way. By the use of right visualization, we can group chunks of data into categories, highlight areas that need our attention, or show the progressive growth/decay of our products.

More importantly, as David McCandless describes in his famous Ted Talk “The Beauty Of Data Visualization”, you start to see patterns and connections between numbers which would otherwise be scattered across multiple reports with the help of data visualization.

Now, the most important aspect of Data Visualization is of course the use of colors. Most importantly, good colors that fit the context of your analysis. Without the right choice of colors, your visualization could turn into nasty looking color eruptions.

In this post I will talk about choosing the right kind of colors for data visualization purpose and I will do so by taking help from a Color Brewer package used in R for data analysis.

R Color Brewer

All color choices from Color Brewer

Typically, color usage can be categorized into three different types based on our data analysis needs.

1) Sequential: When you want to show growth or increase in something, you should pick sequential color scheme. Basically, this relates to sequentially ordered numbers and so it can be used to show progression from very small to the very big. In the picture above, the first section of colors relate to Sequential usage. You see they just get darker and darker starting with lighter values.

Sequential Color Usage

Sequential Color Usage

2) Qualitative: When you want to show the different variety of something without giving any emphasize to the numbers behind them, you should pick qualitative color scheme. These are essentially used to show different categories. So, if you have a bunch of different political parties, you might just show each one of them with different colors. Or if you want to show a different countries in a map or different species of animals, you would use different colors. The colors here are usually of the same light/dark values.

Qualitative Color

3) Divergent: Finally, when you want to show two extreme values in your data, you should pick divergent color scheme. This scheme has very light shade in the middle, and then they get darker and darker to different colors going out each side. That’s a way of showing high and low values on something. The highs and the lows and the neutrals are easily visualized here.

Divergent Color

That’s the basics of picking the right colors for data visualization as per the context of data analysis. I hope it helps you to create beautiful visualizations in your reports!

 

Visual Studio: Converting a Class Library to Portable Class Library

Before you even start asking GOOGLE about how to convert a Class Library Project to Portable Class Library (PCL) in Visual Studio, why don’t you try to do it by yourself?

In fact that is the best approach for this scenario because if you try to google for the solution, you will realize that none of the suggested answers actually agree.

@ StackOverflow:

@GeeksWithBlogs

The main reason the solutions provided do not work is that because of the difference in Visual Studio versions. The solutions vary by Visual Studio version: 2012, 2013, 2015 and now 2017.

Solution

As I said before, this will require some manual work from your side.

You will have to manually compare the differences between regular Class Library project and a Portable Class Library project.

To do this comparison, first create a new PCL project (no you do not have to move all of your class libraries to PCL project).

Once we have  a sample PCL project, we can compare the .csproj file of this project with the class library project’s .csproj file.

So, basically just add/remove the lines that are not available in you class library project from your portable class library project.

Once you have made necessary adjustments, Visual Studio will recognize the Class Library project as a Portable Class Library.

With this approach, you can also convert a Portable Class Library project back to Class Library project as well.

Good luck!

 

Becoming An Indie Game Developer From A Programmer Background

As Wikipedia defines it,

Independent video game development is the video game development process of creating indie games; these are video games, commonly created by individual or small teams of video game developers and usually without significant financial support of a video game publisher or other outside source.”

While both game development and regular software development share a few things in common, the differences weigh a lot more.

Unlike a software, a game is a mix of many other components besides regular programming logic. Graphics, sound and animation play vital roles in any game and these are not the objects of regular interactions for a software programmer. It takes years and years to become masters of these arts in themselves. Plus a game requires advanced knowledge of Math and Newtonian Physics!

So it’s not an easy switch from software development to game development.

Here’s a very good read on Quora on this topic:

https://www.quora.com/Can-one-developer-make-a-successful-indie-game

As you can read from the answers on Quora, there are some people who have “moderately” successfully managed to jump into indie game development coming from programming background.

While revenue wise, the first few years do not look as good as the regular full-time software development jobs, if someone keeps at it for a long time, there could be a brighter future.

If all goes well, as Joe Cassavaugh dreams,  maybe someday indie game developers could stop being a one-man-shop and turn their games into a game like Clash Royale that generate daily revenues of $1,992,870.

Freelance Developers Now Earn Through Writing

Since popular freelancing sites are overrated, today I would like to share with you guys one another way to generate extra income.

Freelance Writing!

Get paid to write articles and tutorials.

There are tons of sites on the internet that are craving for excellent content to be published on their sites.

Writers In Charge lists 110 such sites for freelancer writers. These sites pay anywhere between 50 to 300 Dollars per article which I believe  is way way better than many of the freelancing jobs where developers have to battle among one another to get paid in nuts like 5 and 10 dollars.

Here I would like to list some sites which are excellent platforms specifically for Developers/Designers to write and get published.


CodeTuts+

You can submit articles and tutorials about any programming language. I have seen people write about Javascript frameworks, .NET, SQL, WordPress and Game Development and many other topics.

Even I have written few articles for them!

You’ll be paid $100 for a quick tip tutorial and $250 for a regular tutorial; if you are a high profile author/educator, you could earn more.


Smashing Magazine

Based in Freiburg, Germany, Smashing Magazine works with writers from all over the world.They accept articles about web development and web design, and they would prefer a rough draft of your article if you have it already.

Again developers from many different backgrounds can write and publish their articles here. Smashing Magazine even publishes e-book where your article could get published!


Sitepoint

SitePoint pays $150 for articles and $200 for tutorials and are even willing to pay more quality posts. They focus articles mainly on HTML, CSS and Javascript technologies. But they seem to have posts on mobile development and even Entrepreneurship topics so I guess they take any good topic as their content to publish.


Developer Tutorials

You can submit articles about anything related to design, programming, marketing, management and business tips. They have a preference for list articles and prefer tutorials to be at least 1,000 words.


CodingSight

Codingsight is a community platform created and maintained by Devart.They accept articles on SQL Server, Azure, MySql and .NET topics from writers. Besides getting payments, writers also get benefit of up to 3 licenses for any Devart product: one license for a published article


So, this is just a small list of platforms where programmers, developers and designers from any background can write and get paid for their content. I am pretty sure there are many more than listed here available on the web.

Please feel free to add any other platforms that you guys know on the comments below.