Tumblelog by Soup.io
Newer posts are loading.
You are at the newest post.
Click here to check if anything new just came in.

June 15 2017

Sébastien Wilmet: Gtef library renamed to Tepl – Text editor product line
Zeeshan Ali: Help me test gps-share
Matthias Clasen: Container secrets: size allocation, part 5

June 14 2017

Matthias Clasen: Container secrets: size allocation, part 4
Alexandru Ionut Pandelea: Restoring tabs

Sankar P: golang range Tickers

Update: Please use the playground/gist urls for reading code. Blogger's code formatting is terrible and does not support embedding gists either.

Yesterday Praveen sent me an interesting piece of golang code. Read the following code and tell what the answer will be:

===
type LED struct {
state  bool
ticker *time.Ticker
}

func toggle(led *LED) {
led.state = !led.state
}

func looper(led *LED) {
for range led.ticker.C {
toggle(led)
}
}

func main() {

fmt.Println("Initial number of GoRoutines: ", runtime.NumGoroutine())

led := &LED{state: true, ticker: time.NewTicker(time.Millisecond * 500)}
go looper(led)
fmt.Println("Number of GoRoutines after a call to looper: ", runtime.NumGoroutine())

time.Sleep(2 * time.Second)

led.ticker.Stop()
fmt.Println("Number of GoRoutines after stopping the ticker: ", runtime.NumGoroutine())

runtime.GC()
fmt.Println("Number of GoRoutines after gc: ", runtime.NumGoroutine())

}
===


Golang playground URL: https://play.golang.org/p/1as5QN1r2c
Gist URL: https://gist.github.com/psankar/8af76ba183b0203ec141bca8156f5955

I will explain roughly what the code is doing.

There is a LED struct which has a Ticker and a state variable. While creating an instance of the led struct, we initialise the state and the Ticker.  There is a looper function will toggle the state, whenever the Ticker fires an event.

Now when the program is launched, there will be one goroutine (the initial main thread). After we call looper in a goroutine, the goroutineCount will be 2. Now, comes the tricky part. We stop the Ticker, after a particular amount of time. We even call the gc.

It was observed by Praveen that this piece of code was leaking go routines and the number of go routines was never going down, inspite of the Ticker getting stopped.

The reason why the leakage is happening is because, the "range" loop is never exiting. If the range loop was on a channel, you could "close" it. The ticker.C channel however is a receive only channel and you cannot close it.

How do we fix this, so that none of the goroutines are leaking ? If you have watched the talks, golang concurrency patterns by Rob Pike and Advanced golang concurrency patterns by Sameer Ajmani, then you will realise that it is quite easy to add another parameter to the looper function, which could just exit the loop. So the updated code will be:

===
type LED struct {
state  bool
ticker *time.Ticker
}

func toggle(led *LED) {
led.state = !led.state
}

func looper(led *LED) {
for range led.ticker.C {
toggle(led)
}
}

func looper2(led *LED, q chan bool) {
for {
select {
case <-led.ticker.C:
toggle(led)
case <-q:
fmt.Println("Exiting the goroutine")
return
}
}
}

func main() {

fmt.Println("Initial number of GoRoutines: ", runtime.NumGoroutine())

led := &LED{state: true, ticker: time.NewTicker(time.Millisecond * 500)}
q := make(chan bool)
go looper2(led, q)
// go looper(led)
fmt.Println("Number of GoRoutines after a call to looper: ", runtime.NumGoroutine())

time.Sleep(2 * time.Second)

led.ticker.Stop()
fmt.Println("Number of GoRoutines after stopping the ticker: ", runtime.NumGoroutine())

q <- true
        fmt.Println("Number of GoRoutines after sending a message on the quit channel: ", runtime.NumGoroutine())
}
===


Playground URL: https://play.golang.org/p/NlWbyHLHvA
Gist URL: https://gist.github.com/psankar/4e5b2e563038ce3e9c17eb208c76168a

Let me know if you have any comments.

June 13 2017

Matthias Clasen: Container secrets: size allocation, part 3
Emmanuele Bassi: This week in GTK+ – 36

Christian Hergert: Hello world in a handful of languages

The other day, Sri asked me for a quick Gtk example for a talk. Basically he just needed a window with a header bar. So I put together this repo on github with some examples in a variety of languages. After a few contributions from our community, we have even more examples.

I think it would be neat if people submitted pull requests for more languages. Take a peek and see if something you know about is missing. Ideally the example should use GtkApplication, Gtk templates (and resources if possible), and a window with a header bar.

Having these available will make it easier for me to make templates in Builder for more exotic languages.

Georges Basile Stavracas Neto: Smarter half tiling in GNOME Shell/Mutter

June 12 2017

Ekta Nandwani: Adding TODOist Provider

The first milestone of the project – writing a TODOist Provider for gnome-online-accounts. This provider will be used for authentication of user and providing authorization to read/write todo-lists from Recipes to TODOist.

The API documentation for TODOist is available here.

    • The process started from registering Recipes and getting the client_id and client_secret from the TODOist.
    • Then comes coding the GoaTodoistProvider that implements GoaOAuth2Provider. Subclasses must implement these methods from GoaOAuth2ProviderClass:
      • GoaOAuth2ProviderClass.get_authorization_uri: getting the authorization url
      • GoaOAuth2ProviderClass.get_token_uri : getting the token url
      • GoaOAuth2ProviderClass.get_redirect_uri : getting the redirection url (which is https://localhost/ for Desktop Clients)
      • GoaOAuth2ProviderClass.get_scope : decides the level of access to ask from the user
      • GoaOAuth2ProviderClass.get_client_id : getting the client_id obtained from TODOist.
      • GoaOAuth2ProviderClass.get_client_secret : getting the client_secret obtained from TODOist
      • GoaOAuth2ProviderClass.get_identity_sync : to obtain the presentation_id (email id in this case) from the json object returned using REST API by reading user’s properties
    • Additionally, the GoaProviderClass methods (that should chain up to its parent class) must be implemented: GoaProviderClass.get_provider_type, GoaProviderClass.get_provider_name , GoaProviderClass.build_object

The final view of how the provider looks like this:

LOGIN INTO TODOIST

 

TODOIST ACCOUNT IN GOA
Federico Mena-Quintero: Exploring Rust's standard library: system calls and errors
Colin Walters: On dm-verity and operating systems
Matthias Clasen: Container secrets: size allocation, part 2
Matthias Clasen: Container secrets: size allocation
Isaque Galdino de Araujo: GNOME Notes 3.24
Yash Singh: GSoC ’17 project on GNOME Calendar
Yash Singh: We can now detect recurrent events in GNOME Calendar

Ekta Nandwani: Hello world!

About Myself

I am Ekta Nandwani, an open-source enthusiast, a foodie and a music lover. I’ve done my major in Computer Science at L.D. College of Engineering. This summer I’ve been selected as a Google Summer of Code Intern under GNOME Foundation. I am quite excited about the opportunity to work in such a great community this summer.

 

I’ll be blogging about my GSoC project which is Sharing of Shopping lists from Recipes (Desktop App) to Todoist (Web + Mobile App). Here is the

Ekta Nandwani: And the official coding period begins…

Hello there ! This is my first post about my GSoC project.

About Project

As the title says Sharing of shopping lists from Recipes to TODOist which is self explanatory.

Implementation

There would be addition of minute details as and when the steps gets implemented. The implementation is basically divided into two steps.

  1. Implement gnome-online-accounts Provider for TODOist. (Along with that taking care of the fact that Recipes being non-core app,if isn’t installed, this implementation doesn’t end up having TODOist account that serves no purpose)

  2.  Implement sending shopping list/s from Recipes to TODOist along with sync in the deletion of items

    Onto the implementation of step one. I am digging my way through gnome-online-accounts to write a TODOist provider. Stay tuned for more details! 😉

Older posts are this way If this message doesn't go away, click anywhere on the page to continue loading posts.
Could not load more posts
Maybe Soup is currently being updated? I'll try again automatically in a few seconds...
Just a second, loading more posts...
You've reached the end.

Don't be the product, buy the product!

Schweinderl