Writing simple execution Trigger for linux

So there is an app or process based on its behavior you want to initiate some other app ?

Lets do it.

 

I came across this problem when I had to setup Snort for one of my web Application projects, for those who don’t know snort is an Intrusion Detection system. Whenever it finds some bad packet or anything that violates our rules, it will print alter on terminal, so we can hook that and initiate our own process.

For example :

Link to StackOverflow : Here

If you dont understand any part of this, Kindly comment and I will get back to it ASAP

Regards,
Harsh Daftary

Speed up String concatenation in Python

Series Python Performance : Episode 1

Why String concatenation is so expensive in terms of memory ??

In python whenever we assign a variable, actually object is created in memory for that and its variable name points to that address
so when I do

each iteration in loop generates new object in memory with its contents plus contents of previous object, then ‘a’ changes its memory reference point.

Lets say its SLOW in simple words. As well as also eats up huge space in ram.

Now what ?
Speeding Up concatenation :

First attempt :

Using in place string concatenation by ‘+’ is THE WORST method of concatenation in terms of stability and cross implementation as it does not support all values. PEP8 standard discourages this and encourages the use of format(), join() and append() for long term use
Second attempt :

or by

Both of the latter forms avoid multiple-allocation overhead.

This code is actually quadratic in the total size of the mylist strings due to repeated string copies of ever-larger prefix segments.

Final Attempt:

This can be much faster because all the string concatenation in the last line creates exactly one new string object with one C-level copy sequence (and list operations are relatively cheap).

Regards,
Harsh Daftary

Displaying Random Quote each time opening terminal

           After couple of days at my newly joined office where Every PC runs on Linux. Even Marketing and sales department (We love Open Source), One of my co-worker asked me to write him a code such that every time someone opens a terminal, an inspirational message will be displayed.
           I ended up with a small script which displays a randomly selected message from array of Inspirational Quotes. (Of Course with some help from quora)

ScreenShot :

Inspirational Terminal

Inspirational Terminal

Add the following code at the end of your ~/.bashrc file
open terminal > gedit ~/.bashrc > copy paste > save & exit.

Code can be found here
Github

Comments and ratings are appreciated.

When c starts getting funny strlen vs sizeof

Some things are too obvious to notice, so i thought you should not also fall for this.
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 5.00 out of 5)
Loading...Loading...

whereas:

 

I hope you got the point !

Get the source code here.
GitHub