teleren/devto huggingface dataset:
GO kullanarak BASH üzerinde basitçe komut çalıştırma
Tags: go, bash, linux, cpu
Published: 2020-07-21 20:27:42

GO dili kullanarak bash üzerinde bir komut çalıştırıp, çıktısının veya hata çıktısının alınabilmesini sağlayan ve hatta hata çıktısını log olarak oluşturan basit bir GO uygulaması örneği aşağıdaki gibidir.

Örneğimizde basitçe GNU/Linux sistemler üzerinde sistemde hangi işlemci olduğunu göstermektedir. İlgili kod parçacığını **cpu.go** isminde kaydedebilirsiniz.

```go
package main

import (
    "fmt"
    "log"
    "os/exec"
)

func ogrenCPU() {
    cmd:="lscpu | grep 'Model name:' | cut -d':' -f2 | sed -e 's/^[[:space:]]*//'| tr -d '\n'"
    out, err := exec.Command("bash","-c",cmd).Output()
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("CPU Bilgisi: %s\n", out)
}

func main() {
    ogrenCPU()
}
```

İlgili komut sonrasında GO kodunuzu aşağıdkai gibi derlemeniz gerekmektedir:

```bash
go build cpu.go
```

Derlendikten sonra aşağıdaki gibi çalıştırabilirsiniz:

```bash
./cpu
```

Aut disce aut discede
How do you manage multiple customers in a SaaS?
Tags: webdev, discuss, javascript, node
Published: 2020-07-21 20:27:36

---
title: How do you manage multiple customers in a SaaS?
published: true
description: 
tags: webdev, discuss, javascript, nodejs
//cover_image: https://direct_url_to_image.jpg
---
I have been trying to start [an analytics SaaS](https://www.tractific.com). I'm completely new to this kind of architecture, and saw that there is a huge debate online about multi-tenancy vs single-tenancy. Which one do you prefer, why, and how do you implement it? Since it's an analytics service, I am leaning towards creating a database for each customer for the added privacy.
The 7 Most Popular DEV Posts from the Past Week
Tags: top7
Published: 2020-07-21 20:24:34

---
title: The 7 Most Popular DEV Posts from the Past Week
published: true
description: A round up of the most-read and most-loved contributions from the community this past week.
tags: icymi
cover_image: https://thepracticaldev.s3.amazonaws.com/i/sfwcvweirpf2qka2lg2b.png
---
Every Tuesday we round up the previous week's top posts based on traffic, engagement, and a hint of editorial curation. The typical week starts on Monday and ends on Sunday, but don't worry, we take into account posts that are published later in the week. ❤️


### 1. Build Better

Kethmar opens the vault of their lessons learned over many years developing websites and reviewing portfolios. This post is especially useful for those of you currently overhauling your portfolios.

{% link https://dev.to/kethmars/what-i-learned-after-reviewing-over-40-developer-portfolios-9-tips-for-a-better-portfolio-4me7 %}

### 2. Authentication -- The Nuts, Bolts, and Beyond

Kim serves up a totally awesome step-by-step guide to identity management. Just look at the comments… this post is _helpful_.  

{% link https://dev.to/kimmaida/authorization-and-authentication-for-everyone-27j3#resources-and-whats-next %}

### 3. Gotta Tweet ‘Em All 

Pokémon + Twitter bots using AWS Lambda? Jeannie appeals to both our inner (always) child and grown-up dev selves with this fantastic tutorial. 

{% link https://dev.to/jeannienguyen/building-a-twitter-bot-with-python-and-aws-lambda-27jg %}

### 4. Working With What You Have

Tobe explains that while it’s always good to upgrade your computer if you have the means to, many folks in the world aren’t in this position. These tips help us empathize with developers who don’t have the latest shiny thing _and_ helps the DEV members in this exact position now. 

{% link https://dev.to/tobenxe/tips-for-programming-with-a-low-end-pc-42aa %}

### 5. Beware the Tutorial Trap

Andrew makes us think hard about a common and understandable pitfall for newer devs: getting stuck in the cyclone of endless tutorials with frustratingly little retention. Be kind to yourselves but _also_ embrace failure!

{% link https://dev.to/andrewlundydev/how-to-get-out-of-or-completely-avoid-the-tutorial-trap-m27  %}

### 6. Where in the World?

In this post, Amakah builds a full-fledged Vue country directory with a dark mode theme. Such a fun challenge!

{% link https://dev.to/saucekode/understanding-vue-by-building-a-country-directory-app-part-1-2n9 %}

### 7. Keeping the Job Search Real

Big congrats to Victoria, who landed an awesome new job after a long search! In this post, they crunch the real numbers to give you an honest portrait of one dev’s hunt. 

{% link https://dev.to/torianne02/444-days-later-tori-hit-the-jackpot-3o4p %}
 -- 


_That's it for our weekly wrap up! Keep an eye on dev.to this week for daily content and discussions...and if you miss anything, we'll be sure to recap it next Tuesday!_
No ir a dormir sin aprender algo nuevo
Published: 2020-07-21 20:23:13

Aprender es doloroso, requiere de esfuerzo, dedicación y todos esas habilidades establecidas (poco aplicamos) para una buena persona promedio.

Llevo tres meses intentándolo a conciencia, con un 90% cumplido. 90 de las 100 veces que he ido a dormir lo he hecho con un conocimiento nuevo.

Y la realidad es que en 24h se puede hacer mucho, el problema era yo.
Me relajaba mucho. Dejaba pasar el tiempo, no establecía objetivos claros y perdía el camino.

Un día acostado, con ganas de hacer la depresión. Me levante y empecé a escribir en una hoja. Lo que voy a conseguir y el tiempo que tengo.

Solo queda darlo todo y re leer esa hoja cada que sea necesario, para no olvidar los objetivos(sueños) y el tiempo que hay para lograrlos.
How to inline SVG files in your Bridgetown site
Tags: tutorial, beginners, bridgetown, ruby
Published: 2020-07-21 20:18:38


A short tutorial on how to use [bridgetown-svg-inliner](https://github.com/ayushn21/bridgetown-svg-inliner) to inline SVG assets on your [Bridgetown](https://bridgetownrb.com) website.

Previously this post was about [andrewmcodes/bridgetown-inline-svg](https://github.com/andrewmcodes/bridgetown-inline-svg) but that plugin has since been put into maintenance mode in favor of this MIT licensed library by [Ayush Newatia.](https://twitter.com/ayushn21)

## Prerequisites

This tutorial assumes that you already have a Bridgetown website up and running. If you don't, check out [Bridgetown's Quick Instructions](https://www.bridgetownrb.com/docs/#quick-instructions) for instructions on how to generate your first site.

## Install

Run the following command to install the [plugin](https://github.com/ayushn21/bridgetown-svg-inliner) in your site:

```bash
bundle add "bridgetown-svg-inliner" -g bridgetown_plugins
```

## Usage

Bridgetown creates an images folder by default at `src/images`, which you can use to store your SVG assets or you can create your own folder like `assets`, just make sure it is nested under `src/`.

For this tutorial, I used the annotation outline icon from [Heroicons](https://heroicons.com).

### Basic Usage

Create a SVG called `icon.svg` at `src/images/icon.svg` and call it using the Ruby helper or Liquid tag:

```erb
<!-- ERB -->
<%%= svg "/images/icon.svg" %>
```

```liquid
<!-- Liquid -->
{% svg "/images/icon.svg" %}
```

This will inline the SVG as is in your file once the page renders.

## Advanced Usage

You can pass options to the plugin which will then be applied to the resulting element. If it already exists in your SVG file, it will be overwritten.

For example, this snippet:

```erb
<!-- ERB -->
<%%= svg "/images/icon.svg", class: "foo", width: "100%" %>
```

```liquid
<!-- ERB -->
{% svg "/images/icon.svg", class: "foo", width: "100%" %}
```

will result in the following HTML:

```html
<svg xmlns="http://www.w3.org/2000/svg" class="foo" fill="none" viewBox="0 0 24 24" stroke="currentColor" width="100%">
	<!-- ... -->
</svg>
```

## Reference

- [ayushn21/bridgetown-svg-inliner](https://github.com/ayushn21/bridgetown-svg-inliner)
How to fix a terrible bug StackOverflow cannot fix?
Tags: beginners, productivity, developers, codenewbie
Published: 2020-07-21 19:54:08

Have you ever faced a bug that brought you to your down to your knees to say a prayer? 

There are times when you get stuck while writing code. Most of the time it's because you have been coding for some time and now you are facing a terrible error which you are struggling to fix. You Google the error only to find out that all the links are purple but still you have no solution. You have opened all the StackOverflow links, Github, the documentation, other helpful forums, and your only hope is the place where no-one has been, the second page of the Google search, you go there but still, there is no solution. 

You have tried everything and at this point, you start questioning yourself or yelling at your stupid computer. What if I told you that the solution is there and you might have browsed through it? Of course, there is a bug in your code but the huge bug here is that you are **exhausted**.

I have been through such times I could not fix a bug not because I didn't have a powerful internet connection or enough coffee, trust me I had enough of everything but still, I couldn't fix even a missing semicolon error. Why? because I was tired. Tiredness is one bug caffeine, StackOverflow or any other popular site you can think about cannot fix. It affects both your body system and your computer system. Well, let's jump into the important part, how to fix it?

The solution is simple, close all the browser tabs and get **some rest**. If you are coding at night, leave everything, and go to sleep. During the day taking a walk or doing anything that is not related to coding helps. The goal is to refresh your mind by taking it away from your bug for a moment. Now you are asking yourself, is this guy crazy telling me to sleep or rest like there is no problem? I know you need to fix this to meet your deadlines but you are likely to spend five hours trying to do something that you can do in 5 minutes or less. The problem with coding when you are exhausted is that you are likely to create more errors or end up creating something that you will spend the rest of life debugging. 

After taking some rest come back and start debugging your code or start searching for your error. You are likely to find out that among all the purple links that you thought had no solution one of them had a solution but you were too drained to notice. This has helped me to fix a missing semicolon and other errors, I'm sure it will work for you.

And that's how you fix a terrible bug StackOverflow cannot fix.

Image credit _quora.com_
Lazy state initialization in functional components.
Tags: javascript, react, webdev
Published: 2020-07-21 19:34:02

This brief post will focus on `lazy` state initialization when using `useState` hook. If you don't know what `useState` hook is, you can read about it in my introductory article on `useState` hook [Here](https://dev.to/nibble0101/what-is-usestate-hook-and-how-do-you-use-it-3d71).

If you want to initialize state in functional components, you can use `useState` hook. This hook takes the initial state as its argument and it returns an array of two entries. The argument passed is set as the initial state.
```javascript
const[state, setState] = useState(1)
```

Sometimes instead of passing a primitive value, an object or an array as argument, you can also pass a function. The value returned by the function passed is used for initializing state.That is referred to as **lazy state initialization**. **Lazy state initialization** is necessary if you are performing a computationally expensive process for initializing state. Consider the example below:

```javascript
import React from "react";

function initializer() {
  return Math.random();
}

function App() {
  const [state, setState] = React.useState(initializer());
  const clickHandler = React.useCallback(() => {
    setState(prev => prev + 1);
  }, []);
  return (
    <div className="App">
      <h1> {state} </h1>
      <h2>
        <button onClick={clickHandler}> Click </button>
      </h2>
    </div>
  );
}

```
In the example above, `initializer` is defined outside the component. It returns a random number which is used for initializing state. The initial state is ignored in subsequent renders but the function `initializer` which is used for initializing it is invoked in every re-render. This might not be a big problem if you are simply returning a random number like in the above example however it  causes performance problems if `initializer` performs a computationally expensive process.

## How do we get over this problem?

To solve the problem described above, you can pass a function which calls `initializer` as an argument, like:

```javascript
 const [state, setState] = React.useState(() => initializer());
```
or else pass `initializer` to `useState` without invoking it like:
```javascript
 const [state, setState] = React.useState(initializer);
```

The above two approaches ensure `initializer` is invoked on first render but ignored in subsequent re-renders.

Thanks for reading this article to the end. If you found it informative, consider sharing it on [twitter](https://twitter.com/login?lang=en) or any other social media platform. Others might find it useful too.

## References

- [react documentation](https://reactjs.org/docs/getting-started.html)
Grant for the Web awardees list
Tags: webmonetization, grantfortheweb
Published: 2020-07-21 19:08:49

---
title: Grant for the Web awardees list
published: true
description: After going through the Grant for the Web blog posts a few times looking for details of a few grantees I realized I'm missing a list of all the creators awarded with a grant in one place, and since I couldn't find anything, I decided... to do one myself.
tags: WebMonetization, GrantForTheWeb
cover_image: https://dev-to-uploads.s3.amazonaws.com/i/p9d7eu0evvnh6hhb1yuh.png
---
After going through the Grant for the Web blog posts a few times looking for details of a few grantees I realized I'm missing a list of all the creators awarded with a grant in one place, and since I couldn't find anything, I decided... to do one myself.

By visiting [end3r.github.io/GrantForTheWeb-Awardees/](https://end3r.github.io/GrantForTheWeb-Awardees/) you'll find basic info like the date when the content creator was announced (along with the link to the announcement itself), name, type (awardee or ambassador), short description, and action items - what the creator will be working on as part of the grant. All that information is taken from the announcement posts on the Grant For The Web blog.

![Grant for the Web table](https://dev-to-uploads.s3.amazonaws.com/i/mp6ygveyp59cbz4ngzl6.jpg)

I've decided to host it on GitHub Pages to make it open sourced - anyone can submit their updates or fixes. I've also added my Web Monetization meta tag to see if there's going to be any traffic coming from paying Coil members.

Ps. Please take into account I switched from front-end to gamedev almost a decade ago, and hacked this together from scratch in a few hours. It's tabular data, so it looks ugly on mobile - feel free to send pull requests if you'd like to fix this, thanks!
Custom cursor in Flutter Web...
Tags: codepen, flutter, dart, webdev
Published: 2020-07-21 19:04:14

So for the 3rd week of Codepen's flutter challenge we had to use [implicit animations](https://flutter.dev/docs/codelabs/implicit-animations) in flutter, using them I kind of made a custom cursor for the website. 
We are not actually changing the system cursor to another like [in this blog](https://medium.com/@aflutterdev/handcursor-for-flutter-web-6552bed19f91), rather its a trick, we are hiding the real one and adding a widget to the current hover position.

## Lets get started
First we need to wrap our scaffold's body with [MouseRegion](https://api.flutter.dev/flutter/widgets/MouseRegion-class.html) widget, with it we can get the cursor position in real-time and it also have property named `cursor` through which we can change the actual cursor or replace with other system cursors.
In our case we will hide cursor and set pointer on Hover, like this :
```
body: MouseRegion(
          cursor: SystemMouseCursors.none,
          onHover: (eve) {
            setState(() {
              pointer = eve.position;
            });
          },
          child: ...
      ),
```

Second step is to add a widget at the `pointer`'s position. For that we will use `Stack` widget and `Positioned` widget to position our custom made cursor in the stack. Make sure your stack have full width and height.

```
Stack(
   children: [
       Positioned(
           left : ...
           top : ...
          ),
       OtherWidgets(),
     ],
   )
```
Now we need to add child to `Positioned` widget, I made the simple Cursor (its just a circular ring).
```
Container(
      height: 200,
      width: 200,
      decoration: BoxDecoration(
           borderRadius: BorderRadius.all(Radius.circular(100)),
           border: Border.all(
                 width: 4,
                 color: Colors.white,
                 style: BorderStyle.solid)),
     ),
```
Now just one this is left i.e., to position this cursor. For that we will just use the `dx` and `dy` from the pointer offset. So the complete code will look like : 
```
      Positioned(
         left: pointer.dx - 100,
         top: pointer.dy - 100,
         child: Container(
           height: 200,
           width: 200,
           decoration: BoxDecoration(
               borderRadius: BorderRadius.all(Radius.circular(100)),
               border: Border.all(
                   width: 4,
                   color: Colors.white,
                   style: BorderStyle.solid)),
          ),
       ),
```
Why `-100` ? you know it :)  

Here we go, you got yourself a custom Cursor in flutter web. But there is something missing? cursor movement is kind of stiff, right? Here comes the implicit animations part.

Just simply use `AnimatedPositioned` widget instead of `Positioned` and add duration to it.

#Result
I have added other animations as well using the same criteria in the following pen. 
Preview : https://flutteranimations.netlify.app/#/
{% codepen https://codepen.io/iamSahdeep/pen/JjGxoRd %}

Thanks for reading :)
Easy toggleable boolean in Ruby on Rails
Tags: rails, toggle, ajax
Published: 2020-07-21 18:38:25

---
title: Easy toggleable boolean in Ruby on Rails
published: true
description: Easy toggleable boolean in Ruby on Rails with unobtrusive javascript
tags: Rails, toggle, AJAX
cover_image: https://www.12voltplanet.co.uk/user/products/ON-OFF_toggle_switch_20A@12V_decal_1.jpg
---

There are occasions where we only have to update an attribute within a Rails model and in this case, change only one boolean from True to False or vice versa. To avoid having to enter the model form, check the checkbox, save and be redirected somewhere, it is easier if you implement a couple of lines of code to support toggle with the benefits of Ruby on Rails.

## Scenario

We have a model called Banner which has a boolean called published and we need to provide a easier interface to toggle that boolean from a list of banners

### 1.- Define a Controller action

We make use of an ActiveRecord::Base method called [toggle!](https://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-toggle-21)


```ruby
# app/controllers/banners_controller.rb

def toggle_published
  @banner.toggle! :published
end
```

### 2.- Define the member route to our new action

```ruby
# config/routes.rb

# Others routes
resources :banners do
  member do
    post :toggle_published
  end
end
```

### 3.- Use Rails unobtrusive javascript to update the value

Suppose we have our index.html.erb file with a list of banners. We have to make sure of 2 things, include the helper dom_id and add a link to our new route using the remote option to do the request throught AJAX

```erb
# app/views/banners/index.html.erb

<tr id="<%= dom_id(banner) %>">
  <td class="published">
    <%= link_to banner.published_icon, toggle_published_banner_path(banner), remote: true, method: :post, title: t(:update_published) %>
  </td>
</tr>
```

### 4.- Update the DOM with the new content and profit (?)

```js
// app/views/banners/toggle_published.js.erb

$("#<%= dom_id(@banner) %> .published a").html("<%== @banner.published_icon %>")
```
Cookie switch (pure CSS, no SVG)
Tags: codepen, css, html
Published: 2020-07-21 18:31:24

Building an animated 🍪 cookie switch 🍪 in pure CSS and without using SVG, was a lot of fun for me on CodePen.

👇🏻👇🏻👇🏻 Try it out... 👇🏻👇🏻👇🏻

{% codepen https://codepen.io/agalliat/pen/RwrEqOG %}
A command-line tool to create your GitHub profile using a template
Tags: swift, commandline, github
Published: 2020-07-21 18:26:21

As you might have noticed, you can now create a [GitHub profile](https://dev.to/web/design-github-profile-using-readme-md-8al) by creating a repository with the same name as your GitHub username. I wanted to add content that changes often, but I didn't want to do it manually. So I created [Octoprofile](https://github.com/rderik/octoprofile).

Octoprofile is a small command-line tool that allows you to build your GitHub Profile using a template, and you can extend the template by using plugins. The plugin system is quite simple, but that's the point, anyone can extend it and create their own plugins.

The tool is open-source, and the point is to help others. If you are a beginner and want to contribute, I think this project is an excellent place to start.

Ok, I hope it is helpful. Here is the link to the GitHub repository:

[https://github.com/rderik/octoprofile](https://github.com/rderik/octoprofile)
React/Redux Project
Published: 2020-07-21 18:12:30

Where has the time gone? To think I’m writing the blog post for my last project is surreal to me! I decided to push my limits and step outside of my comfort zone for this project. I decided to build a typing game for my final project. For me, this seemed difficult because I’ve never built a game before, all previous labs/lessons have been a review app or something similar, never a game. At first I wasn’t confident in my abilities to create what I had in mind, but I did it and it is truly an amazing feeling knowing that I did!

The Typing Game is the name of the app, and it is just that, a typing game! To play the game, First select which difficulty you’d like to play on. Easy is 4 letter words, Medium is 5-6 letter words and Hard is 7 letter words. You have 5 seconds to type each word, and each word you type adds one point to your score. After the game is over you’re asked for a display name so your score can be displayed on the scoreboard. The scoreboard only displays the top 3 scores for each difficulty.

I really enjoyed creating the project and plan to add more onto it in the future. React and Redux are such a powerful combination. I’m excited to dive deeper into React now that I have a good grasp of the basics!
What kind of maintenance has to be done for servers ?
Tags: discuss, devops, linux, help
Published: 2020-07-21 18:12:03

I Basically do some sanity check beginning of month for all these 3 servers.
 + App server 🖥️
 + Web server 🌐
 + Database server 🗄️

>Note: Asked in an interview

Now would like to know how you categories you maintenance based upon these 3 servers. There is something I need to know, maintenance done in different manner for these 3. Like if your app machine runs a Java server the update process and maintenance is very easy. But in case of your db server requires some care. 

Thanks in advance folks.🥰😇👍🏼