How to speak ?

From the past few days I was exploring different resources and How’s to guide to improve my public skills and then stumble upon a great video How To Speak by Patrick Winston. So, here are my notes from that video, enjoy!

How to Start

  • Don’t start with a Joke.
  • Start with the promise by telling them the things they will know at the end of the talk.
  • Build a fence around your idea and be clear what you are going to talk about and should repeat it in the talk.
  • Ask question, this usually helps you to engage people present in the talk, remember that question should not be too easy or too hard.

Time and Space

  • Choose the time of the talk very wisely, so that people joining the talk should be energetic, avoid the time after the lunch as people will be a bit drowsy at that time.
  • Be Always comfortable with the space where you are going to talk, if necessary visit that place beforehand to get familiar with.
  • Space should be well lit.

Tool of the Trade

  • Board
  • Props

Slides

  • Remove unnecessary things from slides, it should have meaningful lines only.
  • Font size should be big enough.
  • Don’t read the slides while giving talk, always give time to the listener to read the slides.

How to Stop

  • Don’t end the slide with, Thank You.
  • End it with the contributions, or a Joke 🙂

~ Always remember that Knowledge and practice is greater than talent.

Cheers!

Understanding Generators in Python.

Generators is a function in which objects are created at once but not all code is executed at once as done in normal function. In normal function execution from top to the return statement. A function that consists of a yield statement is called a generators function. The execution of the generator function happens differently, in which the code execution stops at the yield statement rather than a return statement, to move to the next statement next() method is called which will start the execution of the code from where it is left over. If no yield statement is found a StopIteration exception is raised.

So lets see how to create, execute a Generators in python.

def fib(n):
    a, b = 0, 1
    while a <= n:
        yield a   # yield statement.
        a, b = b, a + b

Now let execute the method fib().

fib_fun = fib(10)
next(fib_fun) # 0
next(fib_fun) # 1
next(fib_fun) # 1
.
.
.
next(fib_fun) # 8
next(fib_fun) # reached the end will raise StopIteration Error.
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
StopIteration
 

# Else you can use for loop which call next() in the background.

for fib_value in fib(10):
    print(fib)

# Output
0
1
1
2
3
5
8

So here we today understand the Generators concept in python. Now you would be thinking where we can use this, let me state some use cases.

  • Can be used for memory management, where we pass the whole list as once, we can use Generator to pass data one by one so that less load comes on memory.
  • Generator can be used to define infinite streams.

If you know any more use case, please do share in the comments and if want to share something else or talk about Generators feel free to ping me on twitter

Till then Cheers 🙂
Happy Digging.

How to merge specific files from another branch/repository

Let says you are working on a project and you have dependencies of code from some another repository, which you need in your project code.

  • One way is to copy the code from another repository manually to yours whenever it gets update not so good way 😦
  • Another way is to use git version control system to do that for you and its super easy to do 🙂

Let me show you how we can do it.

Fetching from Another Repository

git add remote other <repository_link>
git fetch other
git checkout <your_target_branch>
git checkout -p other/target-branch file_path

If you have multiple files you have to just change the last checkout statement to

git checkout other/target-branch file_path1 file_path2

But wait there is one catch here that is the path of the file in your repository should be a mirror image (same as) of the path of the file in another repository you are fetching from.

Fetching from Same Repository

Now If you want to fetch files from another branch of the same repository you have to just do

git checkout other_branch_name file_path1 file_path2

I have to admit that it has been three years now working with git, but it still excites me that there is lot of things that I do not know about git, If you also have some important time-saving git commands which you feel can save someone else time do share in comment because sharing is caring :sunglasses: .

Cheers!

Happy Coding


Photo by Yancy Min on Unsplash

Scrapy The Tool

scrapy logo

As part of my job, I have to scrape some website to help our sales team with data on the market, as of now they were doing it manually which is a bit of tedious job to do and consumes lot of their productive time. So on bit searching and going through different tools and framework came across a framework named Scrapy. So here I am going to share how to set up and use Scrapy.

Scrapy is a free and open source web-crawling framework written in python which is used to extract data from a website without much of hassle. They have a very nice documentation you can check out here.

Steps to Install Scrapy

sudo apt-get install python-dev python-pip libxml2-dev libxslt1-dev zlib1g-dev libffi-dev libssl-dev
pip install Scrapy

Steps to Create New Project

To create a Scrapy project type this command in your terminal.scrapy startproject <project name>. Project structure will look like this

now go ahead and create a python file at path /spiders and paste below code.

#!/usr/bin/env python3
import scrapy

class RedditSpider(scrapy.Spider):
    # name of the scrapper, it should be unique.
    name = "reddit"
    # list of the URL need to be iterated.
    start_urls = ['https://www.reddit.com/']

    # Called to do any operation on the response of the above URL.
    def parse(self, response):
       # css selector of the anchor tag which contains the headers
       top_post = response.css("a.SQnoC3ObvgnGjWt90zD9Z")
       for post in top_post:
           self.log(post.css('::text').extract_first())

To start scrapping, type

scrapy crawl reddit

Here we are scrapping the Reddit website for the latest post and getting the header of all the post. The output of the above code will look like this.

  • Trump Organization ‘Sold Property to Shell Company Linked to Maduro Regime,’ Says Report
  • Blind people of Reddit, what do you find sexually attractive?
  • A “caravan” of Americans is crossing the Canadian border to get affordable medical care
  • A “caravan” of Americans is crossing the Canadian border to get affordable medical care
  • [Post Game Thread] The Houston Rockets defeat the Golden State Warriors, 112-108, behind Harden’s 38 points to level the series 2-2, despite the continued brilliance of Kevin Durant 18, my friend here is failing biology and thinks she’s unroastable. Go for it guys, and go hard If you strike me down, I shall become more powerful than you can possibly imagine. [BOTW]
  • ELI5: Why are all economies expected to “grow”? Why is an equilibrium bad?
    ….

Now the best part of Scrapy is if you want to experiment around any website before creating any project you can easily do that.

scrapy shell 'https://www.reddit.com/'

and then can try different CSS selector on the response . Though there is a lot more you can do with Scrapy like saving the result in JSON, CSV format and even integrate with Django project might show that in next post, till then good bye.

Cheers

Music for productivity

Past few days back I have finished my Learning How to Learn course from Coursera recommended by Jason Braganza.

So here sharing a piece of knowledge from the course, that can really help you to increase productivity. We all love to hear music while working, but did you ever give a thought about which music genre you should here while working? So, here is straight advice from people who have tried this out.

Classical Music : If your work involves numbers or attention to detail

Pop music : If your work involves data entry or working to deadlines

Ambient music : If your work involves solving equations

Dance music : If your work involves proof-reading and problem solving

 


Love to hear from you if you know more music genre, or have playlist of your own productive music. Thanks to  Mark Solarski for the cover image.

ILUG-BOM Meet-Up

This Saturday, I went to ILUG-BOM meet-up which was on Image processing by Raghavendra Kamath.

It was great meet-up where we discuss about image processing using the GIMP tool which is an open source tool.

Learn about Mask, Layer, Color curve using GIMP tool.

After the meet-up floor was open for discussion where the discussion is about how to encourage schools to use open source tool and aware them about its benefits. I really enjoyed being part of the discussion as being my first day with the ILUG -BOM they don’t let me feel that and appreciate my participation in the discussion.Soon i will share image edit with GIMP tool.

Dgplug Summer Training

One day i was just surfing the internet and just came across the dgplug Summer Training and than magic happens  🙂

Training started on 19th June 2016, from that day some meaningful input comes to the code of my life .Training is going under the guidance of Mr Kushal Das, ex poser which we get meeting the smart people around the world in one hood is great and billion dollar is nothing in front of 2 hours+ time spent in training.

Till now I enjoy being the part of the training and learn a lot..

What I added to Main method of my life from this training?

  • Smart Question – In this session taught about the etiquette of irc, mailing list and how to ask smart question?.
  • FHS- The File Hierarchy Standard (FHS) defines the file system of Unix and Unix like system somewhat like drives in window’s, great session  about filesystem and learn a lot from the session about the Linux GNU/Linux.
  • Vim- A beautiful text editor of which i have only heard about but never tries my hand’s on it , but during this session i try and  found it simply awesome!
  • reStructuredText Primer- I don’t attend this session but going through Log i understand that it is Document generator that can ease your lot of work and you can convert the reStructuredText Primer document into any format but till now learning about how to convert into HTML.

For now that’s all, hope you enjoy the blog post and you will take something valuable from the post.Till next post cheers! and HapPppPpPpPy  Bug Free Life  : )