Planet dgplug

June 22, 2017

Saptak Sengupta

Avoid Race Condition in CSV exports





One of the biggest problems that appear while writing any file in the server side is a race condition. A race condition when two or more users make request to write to the same file in the server side and since neither of the operations are completed, so there is a certain problem in the integrity of the data written and may also cause the operation to be completely blocked. So how to stop this and still maintain that a large number of files or memory is not used? Let’s see.


What is a Race Condition?


A race condition is a situation when two or more processes perform a write operation on the same file at the same time. This causes an undesirable situation since the process should be in a sequential manner. So the situation causes something like a ‘race’ between the two server requests to change or modify the same file. So in such a scenario, there is no guarantee that the data written to the file is correct or will be meaningful at the end. Maximum probability is it won’t be.


Avoiding Race Condition


The general way of avoiding a race condition is adding a file lock. We lock a file while it is being written by some user or process and prevent other users from being able to write to the file. They have to wait for the ongoing writing process to complete to start another write process. But making that might increase the wait time quite considerably for users when we are looking to export CSV data about an event.







So to keep the process fast and use the advantage of distributed system, we write the CSV for different request in different files. We create the filenames by appending a random hexadecimal string to the original filename.


Avoid Wastage of Memory


However as we can understand by the proposed method above, there will be a huge wastage of memory since a large amount of files will be created. So to avoid wastage of memory, we run a cron job. The cron job deletes all the csv files after a certain amount of time. For this, we use apscheduler.







Thus, we avoid the race condition while also maintaining that a lot of memory isn’t wasted.

by SaptakS (noreply@blogger.com) at June 22, 2017 09:45 PM

June 21, 2017

Kushal Das

Updates on my Python community work: 16-17

Thank you, everyone, for re-electing me to the Python Software Foundation board 2017. The results of the vote came out on June 12th. This is my third term on the board, 2014, and 2016 were the last two terms. In 2015 I was out as random module decided to choose someone else :)

Things I worked on last year

I was planning to write this in April, but somehow my flow of writing blog posts was broken, and I never managed to do so. But, better late than never

As I had written in wiki page for candidates, one of my major goal last was about building communities out of USA region. I warm welcome I have received in every upstream online community (and also in physical conferences), we should make sure that others should be able to have the same experience.

As part of this work, I worked on three things:

  • Started PyCon Pune, goal of the conference being upstream first
  • Lead the Python track at FOSSASIA in Singapore
  • Helping in the local PyLadies group (they are in the early stage)

You can read about our experience in PyCon Pune here, I think we were successful in spreading the awareness about the bigger community which stands out there on the Internet throughout the world. All of the speakers pointed out how welcoming the community is, and how Python, the programming language binds us all. Let it be scientific computing or small embedded devices. We also managed to have a proper dev sprint for all the attendees, where people did their first ever upstream contribution.

At FOSSASIA, we had many professionals attending the talks, and the kids were having their own workshops. There were various other Python talks in different tracks as well.

Our local PyLadies Pune group still has many beginner Python programmers than working members. Though we have many working on Python on their job, but never worked with the community before. So, my primary work there was not only about providing technical guidance but also try to make sure that the group itself gets better visibility in the local companies. Anwesha writes about the group in much more details than me, so you should go to her blog to know about the group.

I am also the co-chair of the grants working group. As part of this group, we review the grants proposals PSF receives. As the group members are distributed, generally we manage to get good input about these proposals. The number of grant proposals from every region has increased over the years, and I am sure we will see more events happening in the future.

Along with Lorena Mesa, I also helped as the communication officer for the board. She took charge of the board blog posts, and I was working on the emails. I was finding it difficult to calculate the amounts, so wrote a small Python3 script which helps me to get total numbers for every months’ update. This also reminds me that I managed to attend all the board meetings (they are generally between 9:30 PM to 6:30 AM for me in India) expect the last one just a week before PyCon. Even though I was in Portland during that time, I was confused about the actual time of the event, and jet lag did not help either.

I also helped our amazing GSoC org-admin team, Terri is putting countless hours to make sure that the Python community gets a great experience in this program. I am hoping to find good candidates in Outreachy too. Last year, the PSF had funds for the same but did not manage to find a good candidate.

There were other conferences where I participated in different ways. Among them the Science Hack Day India was very special, working with so many kids, learning Python together in the MicroPython environment was a special moment. Watiting for this year’s event eagerly.

I will write about my goals in the 2017-18 term in a future blog post.

by Kushal Das at June 21, 2017 10:56 AM

Saptak Sengupta

Ticket Ordering and Positioning (Front-end)


As discussed in my last blog about ticket ordering and positioning, in this blog we are gonna talk about how we implement the front-end part of re-arranging the tickets. We essentially do it using compute and methods of Vue.js. The functionality that is expected in the front-end is, the event organizer should be able to move the tickets Up or Down the order and save that position so that it gets displayed later in that very particular order.
Like I said above we use two main things of Vue.JS for this purpose - Compute and Methods.

Compute

We use this to get the sorted list of tickets based on the position key of the tickets and use this sorted list to display the tickets in the event editing wizard. Whenever you change the value of the position for a ticket, it automatically updates the list to sorted list again and hence the order of ticket in the front-end also updates. To add a compute function in Vue.JS, inside the new Vue() object creation, we add an attribute computed and inside that we put all the functions that we are gonna use. So in our case the function is sortedTickets . We make use of the sort function of lodash to sort the tickets array based on it's position attribute.

Now while showing or looping over the tickets, we loop over sortedTickets  rather than the original ticket array.

Method

This method is called when the button is clicked to move it up or down. This makes the calculations to determine the values of the position of the two tickets which are being re-ordered in a single click. To add a method, we do it in a similar way like computed but using methods attribute instead. The methods we have written to move tickets up or down is moveTicket.

It has 3 parameters - ticket, index and direction. So when this function call is emitted, depending on the button, the direction is either "up" or "down" while the other two parameters are the ticket properties of the particular ticket. So in this function we check the direction and accordingly update the value of position for the tickets involved in the arranging. As we update the position here, because of the compute, the UI automatically updates to show the tickets in the new order.
Finally after all arrangement is done, the position is always saved in a hidden input field which is then passed as form data and is saved in the database so that the position value can be used in other pages for showing the ticket in order.

Show Ordered Ticket

In other pages, while showing ordered ticket, we already receive the ticket array in sorted format based on the position key. Hence, we don't need to worry about it in the front-end and it automatically is shown in the sorted order.

by SaptakS (noreply@blogger.com) at June 21, 2017 08:22 AM

June 20, 2017

Shakthi Kannan

Rootconf 2017

Introduction

I attended Rootconf 2017 on May 11-12, 2017 at MLR Convention Centre, JP Nagar, Bengaluru.

Sponsors

The event had two parallel tracks, the Rootconf track at the main conference hall, and the DevConf.in track sponsored by Red Hat. A number of infrastructure hosting companies had sponsored the event. The selected talks had good diversity with topics ranging from monitoring, databases, networking, security etc.

Day I

The day’s proceedings began with the talk on the “State of open source monitoring landscape” by Bernd Erk. He gave a good overview of the available monitoring tools. He is involved in the Icinga2 project, which is re-written in C++ for performance. It is an alternative for the Nagios tool.

Aditya Patawari then provided an introduction to Kubernetes with a demo, as Spencer Krum could not make it to his talk on the “Anatomy of an alert”. After a short break, I attended “A little bot for big cause” session by Pooja Shah. The talk basically demonstrated how to create a bot by integrating various APIs.

I attended Manan Bharara’s talk on “Monitoring performance critical applications” where he had explained how they had used Clojure for monitoring at Otto in Germany. The presentation was very good, and the Oscillator Clojure code is available. He had provided good illustrations and code snippets in his presentation.

Manan Bharara' oscillator visualization

A number of stalls were available in the hallway, and I spent considerable time talking with the sponsors. At the Red Hat stall, I learnt some of the features and use cases for the Foreman provisioning tool. I was pictured with the Foreman helmet:

Shakthimaan with Foreman helmet

After lunch, I attended “SELinux: A deep dive” by Rejy M Cyriac. He gave an excellent introduction to SELinux, explaining the underlying concepts and rationale for the same. We also did basic hands-on exercises, but, I could not attend the last section as I had to move to the main conference hall for the flash talks. I sang the Nursery Rhymes version for DevOps. The video is available.

We then headed to the Rootconf party sponsored by Go-Jek!

Day II

The second day started with the talk by Kunal Grover on “Failure resilient architecture with microservice dependencies”. He presented the ways by which disruptions are performed in cloud infrastructure and how recovery mechanisms are tested. Ramya A then gave an interesting talk on “Asynchronous integration tests for microservices”. She had explained the pact.io family of frameworks to support Consumer Driven Contracts testing. Laxmi Nagarajan then gave a high level overview of “Capacity planning for AWS and configuring AWS autoscaling policies” sharing her Industry experience. After a short break, Colin Charles presented his story on “Capacity planning for your data stores” citing real world examples.

I then moved to the DevConf.in track to attend Ruchi Singh’s talk on “Migration of 300 microservices from AWS cloud to Snapdeal cloud”. The time was too short for such a talk, and it was an overview. I would have liked to see more details, given that they use Chef for provisioning and handle more than 16 TB of data as mentioned by Ruchi Singh.

After a quick lunch, I attended “Adventures in Postgres management” by Ramanan Balakrishnan. It was a good technical talk going over the failures and experiences learnt. After the talk I went to the hallway to listen to the Off-The-Record (OTR) session on mistakes to avoid when planning your infrastructure.

OTR session

I returned to the main conference hall for doing some stretching exercises. In my opinion, all conferences should make this session mandatory, especially after you have been sitting for a long period of time. This session was then followed by the “Working with Secrets” talk by Shrey Agarwal, who gave an overview of using Hashicorp’s Vault for managing passwords. It was a very short introduction on the topic.

After a short beverage break, Toshaan Bharvani presented “Living with SELinux”, which was an excellent presentation on the subject. The initial slides had some material that Rejy M Cyriac had introduced the previous day, but, the content and presentation were good. With proper SELinux policies, he said that root in his production servers cannot do much. Rejy and Toshaan both asked people to use permissive mode instead of disabling SELinux altogether, so that you at least know what is being audited.

The last talk of the day was by Anurag Bhatia on “Understanding eyeball routing via RIPE Atlas”. He gave an overview of the RIPE Atlas project and how network metrics are measured and monitored wherever the RIPE device is installed. It is a TP-Link hardware whose firmware can be flashed using Libre software. Unfortunately, at this point the source of the firmware is not released as Free and Open Source Software. I was told that there is still an ongoing discussion on the same.

Conclusion

The talk by Manan Bharara and Rejy’s SELinux workshop were the highlights for day one for me. The content on the second day was much better and had greater depth in my opinion. Overall, it was a useful technical conference, and a good place to meet like-minded people.

I would like to thank Aerospike for sponsoring me to attend the conference.

June 20, 2017 02:30 PM

June 19, 2017

Kushal Das

dgplug summer training 2017 is on

Yesterday evening we started the 10th edition of dgplug summer training program. We around 70 active participants in the session, there were a few people who informed us beforehand that they will not be available during the first session. We also knew that at the same time we had India-vs-Pakistan cricket match, that means many Indian participants will be missing the day one (though it seems the Indian cricket team tried their level best to make sure that participants stop watching the match :D ).

We started with the usual process, Sayan and /me explained the different rules related to the sessions, and also about IRC. The IRC channel #dgplug is not only a place to discuss technical things, but also to discuss about everyday things between many of the dgplug members. We ask the participants to stay online as long as possible in the initial days and ask as many questions as they want. Asking questions is a very important part of these sessions, as many are scared to do so in public.

We also had our regular members in the channel during the session, and after the session ended, we got into other discussions as usual.

One thing I noticed was the high number of students participating from the Zakir Hussain College Of Engineering, Aligarh Muslim University, Aligarh, India. When I asked how come so many of you are here, they said the credit goes to cran-cg (Chiranjeev Gupta) who motivated the first year students to take part in the session. Thank you cran-cg for not only taking part but also building a local group of Free Software users/developers. We also have Nisha, who is a fresh economics graduate, taking part in this year’s program.

As usual the day one was on Sunday, but from now on all the sessions will be on weekdays only unless it is a special guest session where a weekend is a better for our guest. Our next session is at 13:30PM UTC today, at the #dgplug channel on Freenode server. If you want to help, just be there :)

by Kushal Das at June 19, 2017 06:38 AM

June 17, 2017

Dhriti Shikhar

June ’17 Golang Bangalore Meetup

The June Golang Bangalore Meetup was conducted on Saturday, June 17th, 2017. There were around 35-40 people who attended the meetup.

DCf3kQJVwAA8VSC.jpg:large

The meetup started at 10:15 with the first talk by Nurali Virani who works at SAP Labs, Bengaluru. He talked about “Understanding Type System In Go”.

DCgErtoU0AAVDds.jpg:large

Saifi gave an awesome talk about “Working with C code and plugins in Go”. The slides related to his talk can be found here

DCgNU5GU0AAFIhH.jpg:large

Umasankar Mukkara is the Co-Founder and CEO at CloudByte Inc. He talked about OpenEBS and their experience with Golang. The slides of his talk could be found here. OpenEBS is an open source project written in Golang. You can find the source code of OpenEBS here.

Satyam Zode who is also a fellow Golang programmer at OpenEBS presented a talk about “Package oriented design in Go”. The slides related to his talk could be found here

IMG_20170617_115317IMG_20170617_115325

I thank Uma, OpenEBS and Nexus Ventures Partners for helping us to organize the June Golang Bangalore Meetup by providing venue and food. There were also a few goodies for the participants by OpenEBS. Fortuanately, this event was recorded and we will be sharing the recorded videos soon when they will be ready.

 

 


by Dhriti Shikhar at June 17, 2017 01:01 PM

June 16, 2017

Anwesha Das

PyLadies Pune June meet up

The one thing I missed the most, in PyCon US, 2017, was my PyLadies Pune group.

We were hoping to contribute to projects individually and as a group for a long time now. For our June meetup, we planned to give a shape to this idea. Kushal and Sayan readily agreed to become mentors. Then started the long discussion about the format. We finally agreed instead of mentors offering us the ideas for projects, we should come up with it. The mentors will usher us to turn the project into reality.

Conducting a session on Data Science was another request/requirement. Shilpee Chamboli, the Data Science Engineer at Red Hat agreed to guide us. M.K Pai for introducing us to her. This the kind of support without which PyLadies cannot move forward. This time we returned to our old venue - Red Hat. Rupali did magic again to get us venue at “a not so long notice”.
11th June was the date fixed for the meetup. Shilpee was the first one to conduct the session “Exploring Data Science with Python Pandas”. I often find myself in the middle of a conversation of data science and I find myself unable to contribute much to it. I was hoping for this session to give me some insight to the puzzle called data science. I got more than what I was looking for. After an initial introduction, she asked us to download the data of the Titanic disaster from kaggle. We used the Jupyter notebook in the Azure notebook service. Thank you Shilpee for this insightful session.

I was up next. I shared my experiences from PyCon US. More than anything else, I wanted to give them a glimpse of the Python community, the spirit, diversity and above all, its welcoming nature. I asked friends there if they can share their thoughts on PyLadies, Python community in general. Though they shared different stories, the core thought remained that “It is important to give back to the community.”

My heartfelt gratitude to the lovely PyLadies, Lynn Root, Jackie Kazil, Carol Willing, Ewa Jodlowska) for their messages. A special shout out goes to my videographer Sayan. After the session, Rishika exclaimed, “Wow, you actually told them about us ”. It made my day.

Post lunch came the time to work on the projects. Sayan asked about the projects we wished to work on. The different project ideas were jotted down in the Etherpad page.

We ended the session on a hopeful note that we have some projects to work on, learn new things and progress. The first, billion dollar challenge, remains, “What will be the name of the project?”

by Anwesha Das at June 16, 2017 06:03 PM

June 14, 2017

Sayan Chowdhury

PyLadies Pune Meetup - June 2017

Back after a long time. It’s been a long time since I blogged. This was mostly because I was busy with different conferences. Yes,I attended three conferences PyCon Pune, FOSSASIA, and PyCon US since the last time I blogged. I would be back writing reports on all the three events and I have a pending third and the final blog post to be done on fedimg.

Now, let me rollback to the topic for which this blog post is meant to be.

11th June 2017, PyLadies Pune organized the meetup for the month of June. The meetup started a bit late with Shilpee Chamoli taking a 101 class on Data Science. The workshop focused on installing dependencies (Jupyter, Pandas, etc), and working on a dataset on ‘survival on the Titanic’. Since few people were having trouble with installing the dependencies, Kushal and a few other people used Azure Notebooks.

Shilpee Chamoli (Picture by: Kushal Das)

Anwesha and I had recorded videos during PyCon US which had messages from Lynn Root, Ewa Jodlowska, Carol Willing, and Jackie Kazil for the PyLadies Pune group members encouraging them on progressively working ahead and helping the community grow.

Jackie Kazil

Carol Willing

Ewa Jodlowska

Lynn Root

After lunch, a mini-dev-sprint was planned where the participants would come up with a project idea. Chandan, Praveen, Kushal and me were doing the mentoring. I was mentoring a group who are planning to build a recommendation system for restaurants (as of now). Based on my experience, I shared with them on which are the important things to focus first and follow the principle “release early and release often”. On the sidelines, I was also working on my project “invento”

The meetup ended at around 5 PM in the evening, though few people stayed up late working on the project.

June 14, 2017 05:00 PM

June 06, 2017

Farhaan Bukhsh

Design Pattern: Singleton

“Beauty!”, when I see some really amazing code that is my first reaction, but what makes a piece of code beautiful? Is it neatly named variables? Is it the uniform indentation?

Well the answer is yes but there is something a little more than these factors and that is an elegant  solution to the problem. When I say elegant solution what is that I am talking about ? What makes a solution elegant? It is the way you approach a problem.

Design Patterns in the programming world adds to the beauty of the solution, it sometimes feels that it is the missing piece of the puzzle. And the solution so magically fits to solve the problem. The various patterns that I came across are Singleton, Mixin, Pub-Sub etc. The way I approached it and studied them is a little different, design patterns are actually tailored way to react to a given situation.

Let me elaborate on that now suppose there is an emergency and somebody got hurt, what is the first thought that comes to your mind ? It is to handle it using First Aid, this is actually a catered thought which has been imbibed in us from ages and people have design First Aid boxes in such a way that it has all the first come fixes for all the emergencies.

For me I see Design Pattern in the same manner it has gone through the test of time and proved to be the best way to solve a specific type of problem.  It is like a ready made template but you should be aware enough to know the problem and to know the pattern that solves that problem. 

I have read about a lot of design patterns but to be very frank I have seldom seen one being applied in the code-base that I have came across, this could be because I have not appreciated it much and also because I was not able to observe the pattern. It was very recently when I was working with Gautham Sir I began to appreciate the beauty of it. We were writing a utility in jnaapti using EcmaScript 6. He made me feel to appreciate the beauty of it and taught me how to implement it as well.

Let us break it down more and see the type of problems in which Singleton design pattern can be used.

What is Singleton design pattern?

A Singleton design pattern puts a restriction of returning the same object irrespective of how many times the class is being instantiated. This makes sure that whatever is the state of object that state is preserved. Don’t be overwhelmed if you are not able to understand it now it will make more sense once you see the code.

The benefit you get is having a kind of a global store where you can put in data and retrieve it when you desire to.

Lets us make it more clear imagine there is a class Library now through out the life cycle of the software what we want is there should be only one Library object and when ever I get this object I should be able to add and delete books from the library hence modifying the library now when I do this the library object anywhere being use should get this information.

Lets chalk out some code and try to understand it, I have 3 files Library.js, Customer.js and LibraryPlayGround.js.  The content of those file are very straight forward.

es6-12Library.js

Now we need customers or readers for simplifying things i have only included on one method that is return books.

es6-2Customer.js

Once all this is done we need a playground where we can see things happening and experiment with it.

es6-3LibraryPlaygroud.js

Now if you see the code farhaan object has tried to access the same Library object that is being exported. No matter what it well return the same instance which has been instantiated in the beginning of the lifecycle of the software. This is how I tried implementing Singleton .

I have used ECMAScript here to demonstrate that concept and to implement it, I am a learner so there could have been certain things I wouldn’t have made clear, you can leave a comment regarding the same, if you have something to add I would love to know.

Till then Happy Hacking


by fardroid23 at June 06, 2017 07:52 AM

May 01, 2017

Shakthi Kannan

GNU Emacs Lisp

[Published in Open Source For You (OSFY) magazine, June 2016 edition.]

We have covered a lot of ground in our quest to learn the intricacies of GNU Emacs and we trust that you have found your long journey fulfilling. This is the last article in the series.

Introduction

The GNU Emacs editor is written using Emacs Lisp and the C programming language. You can use GNU Emacs as an editor without knowing Emacs Lisp, but, being familiar with it will help you customize it or extend it to your needs. Emacs Lisp is a dialect of the Lisp programming language and is inspired by Maclisp and Common Lisp. The source files end with the filename extension .el and the byte-compiled files end with the .elc filename extension. You can also write scripts using Emacs Lisp and execute them as a batch operation. The code can thus be executed from the command line or from an executable file. Byte-compiling the source files can help you speed up the execution.

Comments

All comments begin with a semi-colon. An Emacs Lisp file usually has the following sections in the code, specified with three semi-colons. These always start in the left margin as shown below:

;;; Module --- Summary

;;; Commentary:

;;; Code:

;;; Module ends here

All comments outside functions begin with two semi-colons. The contents of the scratch buffer, shown below, are an example:

;; This buffer is for notes you don't want to save, and for Lisp evaluation.
;; If you want to create a file, visit that file with C-x C-f,
;; then enter the text in that file's own buffer.

Comments inside functions use a single semi-colon, and if they span multiple lines, they must be neatly aligned. For example:

...
(let* ((sexp (read (current-buffer)))    ; using `read' here
                                         ; easier than regexp
                                         ; matching, esp. with
                                         ; different forms of
                                         ; MONTH
 ...
 ))

Literals

The basic data types are available in Emacs Lisp. Numbers can be represented by integers or floats. Integers can have their sign representation before the digit (+1, -2). Floating point numbers can be represented using a decimal point (3.1415) or with an exponent (314.15e-2). A character (S) is represented by its integer code (83), while a string is a list of characters enclosed within double quotes (“A string”).

A symbol is an object with a name. A keyword symbol is one that starts with a colon (:). A vector is an array and can contain different types ([1 “two” :three]). The Boolean values for true and false are ’t’ and ‘nil’ respectively. A cons cell is an object with two slots. The first slot is called the CAR (Contents of the Address part of the Register number) and the second slot is called the CDR (Contents of the Decrement part of the Register number). A list is a series of linked cons cells. For example, in the list ‘(A B)’, the CAR is A and the CDR is B.

Sexp

Emacs Lisp uses prefix notation which consists of an operation followed by operands (arguments). All programs are represented as symbolic expressions (sexp). For example, the ‘+’ operation is applied to its arguments ‘1’ and ‘2’ in the following sexp:

(+ 1 2)

If you copy the above code in an Emacs buffer, you can evaluate the same by placing the cursor at the end of the expression and using the C-x C-e shortcut. The output ‘3’ will be displayed in the minibuffer.

You can also have nested sexps, wherein the innermost expressions are evaluated first.

(+ 1 (* 2 3))

Similar to the ‘+’ operation, you can use pre-defined keywords or functions in Emacs Lisp programs. The format function is similar to your printf statement in the C programming language.

(format "Hello, World!")

You can store a value in a variable using the setq operation as shown below:

(setq IST "Indian Standard Time")

IST     ; No enclosing parenthesis!
        ; produces "Indian Standard Time"

You can find the data type, using the type-of function. A few examples are shown below:

(type-of 1)                ; produces integer

(type-of 3.1415)           ; produces float

(type-of "A string")       ; produces string

(type-of :foo)             ; produces symbol

(type-of t)                ; produces symbol

(type-of '(1 2))           ; produces cons

(type-of [1 "two" :three]) ; produces vector

In the Bash shell, you can escape evaluation by using the backslash. Similarly, you can prevent the Emacs Lisp interpreter from evaluating an expression using quotes. For example:

(+ 1 2)     ; produces 3

'(+ 1 2)    ; produces the list (+ 1 2)

progn

The progn statement is used to execute several sexps. For example:

(progn
  (setq title "Introduction to Emacs Lisp")
  (setq author "Robert J. Chassell")
  (format "%s by %s" title author))  ; produces "Introduction to Emacs Lisp by Robert J. Chassell"

Functions

You can define your own function using the defun built-in keyword. The ‘say’ function simply prints the string “Hello, World!”" in the following example:

(defun say ()
  (format "Hello, World!"))

In order to execute the function, invoke it inside parenthesis as shown below:

(say)    ; produces "Hello, World!"

Arguments can be passed to a function. The ‘square’ function is demonstrated below:

(defun square (x)
  (* x x))

(square 3)  ; produces 9

You can also store a list of names and retrieve them using the car and cdr functions as illustrated below:

(setq teams '("GL" "DD" "KKR" "MI" "SRH" "RPS" "RCB" "KXIP"))

(car teams)       ; produces "GL"

(cdr teams)       ; produces "DD" "KKR" "MI" "SRH" "RPS" "RCB" "KXIP"

(car (cdr teams)) ; produces "DD"

let

The let statement allows you to bind a value to a variable in a local context. GNU Emacs 24 has lexical binding support. An example is given below:

(defun hello (name)
  (let ((new-name (concat "Hello " name)))
    new-name
      ))

(hello "Mark")   ; produces "Hello Mark"

Conditions

Conditions can be checked using the if and cond statements. The if statement takes a condition, and if the condition evaluates to true, the sexp immediately following the condition is executed. Otherwise, the else-form is evaluated. The syntax is

(if condition then-form else-form)

An example:

(if t
    (format "True")
  (format "False"))  ; produces "True"

The when condition statement is a variant of the if statement written as a macro. Macros are an important feature of Lisp programming that allow you to extend the language. They are primarily code generators. If the ‘when’ condition is true, then it evaluates the then-forms. The syntax and an example are given below:

(when condition then-forms)

(when t
  (print "Abracadabra!"))  ; produces "Abracadabra!"

Looping

You can use the while statement to perform looping in Emacs Lisp. The body of the ‘while’ loop is executed as long as the condition is true. An example that prints the numbers 0 to 4 is shown below:

(progn
  (setq i 0)
  (while (< i 5)
    (print i)
    (setq i (+ i 1))))

The dolist and dotimes macros can also be used for looping. The other approach is to use recursion. A literal definition in Emacs Lisp for computing the Fibonacci series is given below:

(defun fib (n)
  (cond ((= n 0) 0)
        ((= n 1) 1)
        (t (+ (fib (- n 1))
              (fib (- n 2))))))

The cond control structure takes a series of clauses, each has a condition and a body-form. If any condition evaluates to true, the body-form is executed. Otherwise, it proceeds to the next clause.

An iterative version of the Fibonacci series is given below:

(defun fib (n)
  (fib-helper n 0 1))

(defun fib-helper (n a b)
  (if (= n 0)
      a
    (fib-helper (- n 1) b (+ a b))))

(fib 10) ; produces 55

The Emacs Lisp Cookbook is very handy https://www.emacswiki.org/emacs/ElispCookbook.

You are encouraged to read ‘An Introduction to Programming in Emacs Lisp’ at https://www.gnu.org/software/emacs/manual/eintr.html and the Emacs Lisp Reference Manual at https://www.gnu.org/software/emacs/manual/elisp.html.

May 01, 2017 06:15 PM

Anwesha Das

FOSSASIA 2017, my homecoming

Ohh you guys came alone, no Py this time?

No Py this time; missing all the noise and fun around.

(How can you miss the noise? It is supposed to be a disturbance.)

These were some introductory reactions from friends meeting us at FOSSASIA 2017.

Kushal and I learned our lesson last year. So, this year we decided not to take Py (who has only grown to be 1000 times more mischievous than she was the last year). But when the time came to leave her with my mom and go to the airport, I wasn’t very sure. The intelligent me took a backseat as the mother took over. It is an overcompensation I have to go through every time I take a step which does not include her directly.

Attending the FOSSASIA summit is always like a homecoming for me. It is the conference where I delivered my first talk. It is the conference where I found my way, direction in the legal field of the open source ecosystem. It is a place where I meet my best of friends. To cut a long story short, I am in love with FOSSASIA summit.

Meeting the Speakers

FOSSASIA Summit is a conference that is truly diverse in character, almost 200 speakers from over 20 countries. The organizers, every time arrange a speaker's introduction session wherein speakers can actually get together and know each other. This year the meeting had been organized in the Microsoft office. We had the chance to meet other speakers. I had planned the talks to attend. We were also given a nice tour of the Microsoft office and got an opportunity to peep into the workspace of the Microsoft employees.

Day 0 is for PyLadies

September 2016, Hong came to Pune. She conducted a session in PyLadies Pune (love her for that). In a conversation with Hong, I shared with her the PyLadies Pune's journey.
I asked Hong if we PyLadies Pune could be at FOSSASIA. She readily agreed and Pyladies began its journey to FOSSASIA.

I arrived a bit early to set up on Day 0 at Science Center, the conference venue to arrange and set up our PyLadies table. I carried the stuff to set up the booth. Pooja also came in early. We quickly set everything up before the morning coffee break. Kiwi needs to be thanked profusely for all his help.
Our table was ready before the morning coffee break. The crowd poured in. Mostly the regular ones. There were questions.

  • What is PyLadies?
  • Is it only for ladies?
  • What am I (being a lawyer) doing in PyLadies?
  • How to join Pyladies?
  • Do we have an SG chapter?

We answered them. But there was a question that struck me. A Grade student asked, "Do we actually need a woman-friendly environment (to work) in today's day and age?" I was stunned, shocked, sad and happy at the same time. The first three emotions were because I thought how unfortunate it was that she never had any idea about what people outside her sphere has to face. I was happy at the same time that they (if we consider her as the representative) do not have to face what we have to as women.

Among all the props, I carried our famous PyLadies Pune Umbrella that stole all the attention. I was delighted to see people taking photos with that.

Kushal and I wanted to attend a talk - "Let's Make Technology more Inclusive" by Bunnie Huang. Last year, I missed his talk, thanks to Py's treasure hunt. This time, I didn’t want to. But someone has to be there with Pooja at the booth. Pravin and Siddhesh helped.
The talk was truly informative. The after-talk discussion with Bunnie about hardware patent and copyright opened up a new avenue to explore for me. Bunnie has written a book called Hardware Hackers. We managed to get a copy of the book signed by him.

Day 1: PyLadies and talk by legalese

I reached a tad late for the conference because of the new treasure chest I found that was Bunnie's book. I was reading the book till early morning. The book has opened up a new world for me. It gave me the idea of something I wanted to know for a long time - "How hardware is being made?". The community and culture of hardware makers have been pictured beautifully.

The booth has been moved from the place it was on Day 0. I joined Pooja in the booth. Surprisingly, people were less inquisitive about the fact if PyLadies was only for women that day, in fact for the rest of the conference. Maybe the presence of Pravin, Siddhesh, and others echoed the true intention of PyLadies that it is for women and friends.

The next thing on my to-do list was to know how software is eating contract drafting by V.G, legalese. I shared this idea with my lawyer friends. From that very moment,
they have abandoned me. My friends are scared of the job scarcity and competition. I guess this will assure them that software will make your life (typing the whole large document) easy. It can never take away the expertise we have as a lawyer. You may hate me for saying this but this is the future. I was curious to know how the future of the legal business/system will look like.

The Python track was going on in the lab. I did attend a talk and a workshop on MicroPython over there. It is amazing how every time I blink a led by writing something on my laptop.

Day 2: PyLadies and my talk

I went to the PyLadies table for some time in the morning. The curiosity to join PyLadies and to click a picture with the umbrella continued. I met a friend I made last year. She, with her whole family, was the attending this time as well. I loved the fact that she really liked the conference and was attending this year too.

Then it was the time for my talk. It was scheduled for after lunch. So, after a quick lunch, I went to my room - the internet, society and Politics room. My talk was on the trends of choosing licenses in the Python ecosystem.

Projector ready, speaker's view set, ready (I love being perfect and on time), I braced myself and boom, the projector went off. The husband understanding that his wife was approaching paranoia and was in a jolted state, helped me. It could not be fixed. The slides were up but not my speaker's view! There was little time to worry about it though and the scared me began the talk. I discussed different licenses, showed licensing scenarios in Python ecosystem and most importantly the best practices for the developers. I fielded a few questions on license, patent and copyright and applicability of Intellectual Property in general.
While I was explaining GPL was when I was being shown the first time card, the second and the final one during the best practices. I was wobbly seeing that and could not deliver my best. I need to learn quickly that if someone has listened to me before, I would understand something is wrong. While at the same time the first time listeners all praises.
The next part of the day was really interesting for me. I had long chat about different software licenses specifically GPL with Ronald. In spite of being a busy organizer, he answered all my questions, even the silly stupid ones.

See you FOSSASIA next year!

Whenever I come from a conference I come with a

  • Big to-be-read list
  • Big to-do list

More followers and more people to follow on Twitter
Some people I can call friends

I usually return from a conference with a heavy heart but not this time. I knew two cuddly hands and a smiling face is waiting for me back home.

by Anwesha Das at May 01, 2017 05:45 PM

Trishna Guha

I am still alive!

It’s been a month I haven’t posted on my blog. This post is just to let you know that I am still alive!

Well, I just got too busy and engaged with the new team that I joined. Oh wait! I forgot to write about my joining Red Hat as a permanent employee.  Yeah, it has been couple of weeks that I have joined Red Hat as a full time employee on Ansible Engineering team where I am working with the Network engineering team to build Ansible modules for Networking vendor operating systems for Data centers and Cloud networks.

My upcoming future posts will be focused on Ansible automation, hacking Ansible network modules source code, writing Ansible network modules specifically for Arista EOS, Cisco NX OS.

See you later!


by Trishna Guha at May 01, 2017 05:10 PM

April 28, 2017

Subho

Glow LEDs with Google Home

Recently I tried experimenting with Google Home, trying to voice control LEDs. Majorly the whole thing can be split into two parts,

  1. A custom command that makes a web POST request to fetch the result.
  2. A simple Flask app that can receive post request with parameters and glow some LEDs based on the POST request data.

For the part one, the custom commands were possible thanks to Google Actions Apis.  I used API.AI for my purpose since they had good documentation. I wont go into detail explaining the form fields in Api.ai, they have done a good job with documentation and explaining part, I will just share my configurations screenshot for your quick reference and understanding. In Api.ai the conversations are broken into intents.  I used one intent (Default Welcome Intent) and a followup intent (Default Welcome Intent – custom) for my application.

top-intents

Heres my first intent which basically greets the user and asks for a LED colour when the custom command “glow LEDs” is activated.

intent1

As you can see the User says is what defines my command , you can add multiple statements in which you want to activate the command. The Action and Contexts is set when you create a followup Intent. Text response is the part which your Google Home will use as response.

Next is the Followup Intent which basically takes the User response as input context (which is handled automatically when you create the followup intent) and looks for required parameters and tries to process the request.

user_interaction

Here the expected User says would be a colour (red, blue, green) is what I allowed. In Api.ai you can use their ML to process the speech and find your needed parameters and values. I needed colours hence used @sys.color. Their are other entities like @sys.address or @sys.flight etc. If these entities don’t serve your purpose then you might want to go vanilla and process the speech on your web-api end. The later part of the Followup Intent is a bit different, we are fulfilling the user request via web-hook here. Here the Response is the fallback response incase the web request fails, the success response is received from web-hook response body.

home-response

The fulfilment option won’t be activated until you add your webhook in the Fulfillment section. Thats all for the part one. Also you can use Google Web Simulator to test your application On the Go.

webhook.png

In part two , I used a Raspberry Pi, 3 LEDs (red, blue, green) , a 1K ohm resistor some wires, a breadboard(optional)  and a T-cobbler Board(optional). Now, we will write a flask application that will accept a post request and turn on the required GPIO pin output high/low.

You can check with the request and response structure you need from the Api.ai docs. Next, this application receives the calls from api.ai webhook and it triggers the targeted LED depending on the resolvedQuery. The above code was written so that I can test locally with get requests too. I used pagekite.net to tunnel and expose my flask application to the external world. Following is the circuit diagram for the connections.

circuit

Following is the Result,

Some more Reads:

  1. https://arstechnica.com/gadgets/2016/12/google-assistant-api-launches-today-so-we-tested-some-custom-voice-commands/
  2. https://docs.api.ai/docs/actions-on-google-integration
  3. https://developers.google.com/actions/develop/conversation
  4. https://developers.google.com/actions/develop/apiai/tutorials/getting-started
  5. https://developers.google.com/actions/samples/
  6. https://docs.api.ai/docs/webhook
  7. https://docs.api.ai/docs/concept-intents#user-says

 


by subho at April 28, 2017 08:47 PM

April 10, 2017

Jaysinh Shukla

goyo-doc: Vim helpfile for goyo.vim plugin

goyo_doc_plugin

What is Goyo?

Goyo is the vim plugin which allows writers to focus on their writing while they are writing. The plugin deactivates not required fancy windows which are not useful at the time of using vim for writing. It provides certain customizations too.

What is missing in Goyo?

The main problem with Goyo plugin is that it carries very weak vim specific helpfile. A vimmer is habituated to find help at vim specific helpfile first. After few attempts, I have decided to write a good helpfile for the Goyo plugin. I am happy to maintain the documentation I have started with the ongoing development of the plugin until the author of Goyo is providing any concise helpfile for it. The goyo-doc is not carrying any source of Goyo plugin, but only contains documentation for the plugin. I am inviting you to propose improvements if you find any.

Why I decided to write a separate plugin for documentation?

“Documentation is essential. There needs to be something for people to read, even if it’s rudimentary and incomplete.”

K.Fogel, Producing Open source software

I believe the documentation is the most important part of any software. While I was using Goyo plugin, I found it is missing the vim specific helpfile. I discussed this issue with the author and offered the help for improving on this. You can read further about early discussions here. I didn’t get any positive response from the author so I decided to write and launch vim specific helpfile for this plugin. With this plugin, I am expecting to provide the solution to those users who are more familiar with vim specific helpfile than a Github wiki or README file of any project. Below are the links for downloading and using the plugin.

Proofreader: Farhaan Bukhsh

by Jaysinh Shukla at April 10, 2017 12:21 PM

March 27, 2017

Trishna Guha

Customize Packages for Atomic Host : Ansible Automation

My earlier post automate-building-your-own-atomic-host describes how to Automate building Atomic Host with Ansible. But it is not capable of customizing packages for OSTree and build Atomic host based on it.

This post includes Ansible Automation for customizing packages of OSTree and build Atomic Host. Below are the improvements on this updated post :

  • Add packages to OSTree (It is suggested not to delete any pre-existing packages from the OSTree, that might break your Atomic host).
  • No need to create VM from the QCOW2 image will shell script anymore, It will be now all-in-one playbook.

If you do not know about Atomic host, please refer to http://www.projectatomic.io.

Requirements:

The requirements remain the same just like the earlier post. I will use Fedora distribution for the demo, but the same will be applicable for CentOS as well.

  • Make sure Ansible is installed on your system. If you are using Fedora workstation/any other platform, do not forget to install python2-dnf as well.
  • Download Atomic QCOW2 image: Fedora-Atomic.

Procedure:

Clone:

$ git clone https://github.com/trishnaguha/build-atomic-host.git
$ cd build-atomic-host/

Environment Setup:

The following will install requirements on your system, initializes OSTree and starts HTTP server as daemon service. The OSTree is made available via web server at TCP port 35000. After running the playbook you may use ip addr to check the IP Address of your HTTP server.

$ ansible-playbook setup.yml --ask-sudo-pass

Variables:

I am going to use variables applicable for Fedora. If you are using CentOS please modify the variables based on it.

  • Primary Variables.
    vars/atomic.yml
---
# Variables for Atomic host
atomicname: my-atomic                          # OSTree name
basehost: fedora-atomic/25/x86_64/docker-host  # Basehost
httpserver: 192.168.122.1                      # IP Address of HTTP Server
  • Additional packages you would like to have in your OSTree.
    vars/buildrepo.yml
# Variables for OSTree packages
repo: https://pagure.io/fedora-atomic.git
branch: f25
repodir: fedora-atomic
abs_path: /workspace                                # The absolute path to the git repo.
custommanifest: customized-atomic-docker-host.json  # The manifest that goes into the custom host(ostree) content that we are going to build.
sourcemanifest: fedora-atomic-docker-host.json      # The manifest that goes into the actual Base Fedora host(ostree) content.
packages: '"vim-enhanced", "git"'                   # Packages you want to have in your Atomic host.

Add packages like above separate by comma.

  • Variables for the VM
    vars/guests.yml
# Variables for Creating VM
domain: atomic-node                        # Domain name
image: Fedora-Atomic-25-20170228.0.x86_64  # Image name
cpu: 1
mem: 1536
os:
  variant: fedora23
path: /tmp                                 # Path to QCOW2 Image

Main Playbook:

Run the main Playbook which will create VM from QCOW2 image, compose OSTree and perform SSH-Setup and Rebase on OSTree:

$ ansible-playbook main.yml --ask-sudo-pass

Note: user-name: atomic-user, password: atomic are the credentials for the instance.
If you wish to change it, modify the cloud-init user-data.
We will have the credentials as variables/vault later.

To Check the IP Address of the VM running:

$ sudo virsh domifaddr atomic-node

Now SSH to the Atomic host and perform Reboot so that it will reboot in to custom OSTree.

$ ssh atomic-user@IP-ADDRESS-OF-VM
$ sudo systemctl reboot

SSH again and You will have your own OSTRee.

[atomic-user@atomic-node ~]$ sudo rpm-ostree status
State: idle
Deployments:
● my-atomic:fedora-atomic/25/x86_64/docker-host
       Version: 25.1 (2017-02-07 05:34:46)
        Commit: 15b70198b8ec7fd54271f9672578544ff03d1f61df8d7f0fa262ff7519438eb6
        OSName: fedora-atomic

  fedora-atomic:fedora-atomic/25/x86_64/docker-host
       Version: 25.51 (2017-01-30 20:09:59)
        Commit: f294635a1dc62d9ae52151a5fa897085cac8eaa601c52e9a4bc376e9ecee11dd
        OSName: fedora-atomic
[atomic-user@atomic-node ~]$ rpm -q git vim-enhanced
git-2.9.3-2.fc25.x86_64
vim-enhanced-8.0.386-1.fc25.x86_64

If you find any bug/idea please open up issues here. Thanks.

Atomic-Host


by Trishna Guha at March 27, 2017 10:50 AM