teleren/devto huggingface dataset:
Time.use_zone for different timezones in Rails app
Tags: rails
Published: 2019-07-20 18:42:46

---
title: Time.use_zone for different timezones in Rails app
published: true
tags: rails
canonical_url: https://prathamesh.tech/2019/07/11/use-time-use_zone-to-navigate-timezone/
---

 ![Time.use_zone for different timezones in Rails app](https://prathamesh.tech/content/images/2019/07/luis-cortes-QrPDA15pRkM-unsplash.jpg)

Almost all the web apps that I work with these days allow user to set their own timezone. Rails makes it really easy with all the Active Support timezone goodies.

One just needs to save the user's timezone in database and then it can be easily changed in the controller action per user session.

Time and time again, I have come across code which actually changes the application's timezone while trying to change the user's time zone.

<!--kg-card-begin: code-->
```ruby
before_action :set_current_user_timezone

def set_current_user_timezone
  if current_user
    Time.zone = current_user.time_zone
  end
end
```
<!--kg-card-end: code-->

I have also come across code in other parts of the application which changes timezone as well.

<!--kg-card-begin: code-->
```ruby
Time.zone = user.time_zone

SyncUserData.new(user).process
```
<!--kg-card-end: code-->

This is even more dangerous because nobody knows what code will followup these two lines and it can run into weird issues because of using user's time zone instead of app time zone.

Instead a better way is to use `Time.use_zone` which accepts a block and returns to the original timezone after the end of the block.

<!--kg-card-begin: code-->
```ruby
def perform_in_users_timezone(user)
  Time.use_zone(user.time_zone) do
    # perform
  end
end
```
<!--kg-card-end: code-->

This is much better solution as we are hundred percent sure, that the change of timezone is only happening inside the block and there is no chance at all of it leaking out in other parts of the code.

Our original example of changing user's timezone per request can be achieved with the help of `around_action` callback along with `Time.use_zone`.

<!--kg-card-begin: code-->
```ruby
around_action :set_current_user_timezone

def set_current_user_timezone
  if current_user
    Time.use_zone(user.time_zone) { yield }
  else	
    yield
  end
end
```
<!--kg-card-end: code-->

So to recap, avoid setting time zone using `Time.zone=` as much as possible. I will go ahead and say that just don't do it! Always use [Time.use\_zone.](https://api.rubyonrails.org/classes/Time.html#method-c-use_zone)
Kubernetes for Java Developers - Debug Application
Tags: java, docker, kubernetes, containers
Published: 2019-07-11 18:03:56

---
title: Kubernetes for Java Developers - Debug Application
published: true
description: Kubernetes for Java Developers - Debug Application
tags: java, docker, kubernetes, containers
series: Java Kubernetes
cover_image: https://thepracticaldev.s3.amazonaws.com/i/efa0toi8knmzcbvbiuj2.png
---
##Debug application

At this point, we deployed our application within a local cluster. But now we have a problem. How do I debug my application that is inside the docker that is inside the kubernetes that is inside a virtual machine?

##Prepare to debug

In this case, we will use a remote Java debug.

###First step:

Prepare your Dockerfile:

```yaml
FROM openjdk:11.0.3-jdk-slim
RUN mkdir /usr/myapp
COPY target/java-kubernetes.jar /usr/myapp/app.jar
WORKDIR /usr/myapp
EXPOSE 8080
ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -jar app.jar" ]
```

This ENTRYPOINT allows you to pass options to the java through $JAVA_OPTS environment variable.

###Second step:

Changing `app-configmap.yaml` file to fill `$JAVA_OPTS`.

```yaml
JAVA_OPTS: "-agentlib:jdwp=transport=dt_socket,address=*:5005,server=y,suspend=n -Xms256m -Xmx512m -XX:MaxMetaspaceSize=128m"
```

###Third step:

Building and deploy app:

```bash
mvn clean install
eval $(minikube -p dev.to docker-env) && docker build --force-rm -t java-k8s .
kubectl apply -f kubernetes/app/
``` 

###Fourth step:

Exposing debug port to localhost:

Get pods:
```bash
kubectl get pods -n dev-to

NAME                     READY   STATUS    RESTARTS   AGE
myapp-7796bc89bf-h2f82   1/1     Running   0          3h3m
```

Expose pod 5005 port:
```bash
kubectl port-forward -n dev-to myapp-7796bc89bf-h2f82 5005:5005
Forwarding from 127.0.0.1:5005 -> 5005
Forwarding from [::1]:5005 -> 5005
```
**Change your pod name as necessary**.

Create a remote debug on your IDE:

On IntelliJ, go to **Run/Debug Configurations**.

- Add new remote configuration like this:

![](https://thepracticaldev.s3.amazonaws.com/i/xnvm0go9ox6gdmu2n4fj.png)


After that, run the configuration. You should see the message below:

```bash
Connected to the target VM, address: 'localhost:5005', transport: 'socket'
```

###Check if works:

Now, you can set a breakpoint in the `HelloController`.

![](https://thepracticaldev.s3.amazonaws.com/i/mf5ws3rt0ivvcyr7pkqx.png)

```bash
minikube -p dev.to service -n dev-to myapp --url
http://192.168.99.100:32301
```

```bash
curl http://192.168.99.100:32301/hello
```

![](https://thepracticaldev.s3.amazonaws.com/i/s1u88q02d9v176g64dg5.png)


##Conclusion

In this part, we learned about how to debug application inside a local kubernetes cluster.

In the next part, we will see some good practices and how to access application with friendly URL using Ingress.

See you soon!


[![](https://thepracticaldev.s3.amazonaws.com/i/gmrz82bjwhej1f1iqb1e.png)](https://twitter.com/sandrogiacom)
What is the plugin? The handy hand for any software.
Tags: computerscience, beginners, todayilearned, todayisearched
Published: 2019-07-11 18:02:11

>***What is Plugin?***
A plugin is a software that adds specific feature or functionality to existing software.

In most cases, plugins are used to adds some functionality to existing software to make it more powerful and useful.

Plug-in, add-in, add-on, or extension are the different name of plugins.

For example, your chrome is browser, it’s work is to help you in browsing the internet. And chrome does it very well.

But there are too many ads disturbing you while you browsing the internet. So, in that case, you will go to the chrome web store and download ad-blocker. And your job is done. Now you can enjoy ad-free browsing.

In the above example, you want a specific feature and that is some software that can block ads in websites. And here ad-blocker is one kind of plugin that helps you in achieve that results. And chrome is an existing software on which the plugin (ad-blocker) is installed.

Here ad-blocker just adds some functionality to chrome.

#####Applications support plugins for two main reasons:
1. **Adds new functionality on the platform —** Plugins make it easy for third-party developers to add new features on the platform.

2. **Reduce software size —** Plugins helps in reducing the software size. You can create software with limited functionality and can provide a wide range of plugins via the store. So when a user needs it they can download it. Just like Chrome, Mozilla is doing the same.


##Different scenarios of plugin usage
---
* Media players use plugins to support different file formats.

* Email clients use plugins for encryption and decryption.

* Graphic software uses plugins to support different file formats and advanced image processing.

* Text editors and IDEs uses plugins to support programming languages and some mostly used functionality.

* Audio editors use plugins to process and analyze sound.

* web browsers use plugins to adds new features and functionality.

So these are some common scenarios where plugins are useful. Feel free to know me if I miss something.

Till then Keep Coding, Keep Loving. Catch you up in the next article.

Jai Hind, Vande Mataram 🇮🇳

Wanna get in touch with me? Here are links. I’ll love to become your friend. 😊

- [My Site] (https://www.jaytillu.in)
- [My Blogs] (https://blogs.jaytillu.in)
- [Twitter](https://twitter.com/jay_tillu)
- [Facebook](https://www.facebook.com/jaytillu.1314/)
- [Instagram](https://www.facebook.com/jaytillu.1314/)
- [Medium](https://medium.com/jay-tillu)
- [LinkedIn](https://www.linkedin.com/in/jaytillu/)
- [Github](https://www.github.com/jay-tillu)
- [Stack overflow](https://stackoverflow.com/users/8509590/jay-tillu)
or just mail me at jd.tillu@gmail.com
Two Little Tricks To Improve Your Productivity
Tags: productivity, beginners
Published: 2019-07-11 17:44:55

#Introduction

This is a short article where I share 2 little tricks I find powerfull to improve productivity. Let's discover them !

##1) Micro-naps

I define as micro-nap a 10-20 min break you spent lying in a quiet environment. 
Basically. 

The exact duration of the nap depends on your preferences, but I recommend to not exceed 20 min because you can enter a kind of cycle which it will be really unpleasant to leave.

For me, this type of break is much more effective than a coffee break, discussing with others or listening podcasts and musics. It gives a real space to your brain and allows him to rearrange all the stuff you work on. It's also a good way for your body to rest.

By the way, you can't take a nap anywhere. Obviously, there's probably no bed in your office and even if that was the case, it would be embarrassing to sleep in front of your colleagues and boss. So I consider it like a luxury that I can afford to when I work at home. Even if that just concern the end of the afternoon after the workday or the moments when you work at home, I invite you to try micro-naps. Same for people who take lunch at home.

##2) The 5s technique

This is a very tiny trick but I love it for its simplicity. Anyway, don't attend to get huge benefits with it.
The principle is just to count from 5 to 0 (the order is important) just before engage in a task or a period of time where you want to be concentrated.
That's just a way to emerge and put away all the thoughts that hold you to act.

#Conclusion

I really invite you to test these 2 tricks. Schedule notifications for a week or two and fix yourself to apply one of these techniques. Despite what you might think during this week, don't stop and take a moment to wonder if that was usefull AFTER the period of test.
If that works for you in some ways, I would be happy that I could help you in your dev journey ;) !
If not, you would get some experience in testing things and that's fine too.


That's all for this article. Thanks for your time and attention. I hope that you enjoy reading it and for sure, give me your feedback in the comments or contact me on [Twitter](https://twitter.com/CoolCode3)!
condition inside map array - React Native
Tags: reactnative, react
Published: 2019-07-11 17:42:06

Hi i want to login with a local data array but i cant get an error alert when the username and password is worng. please can you guide me? 



    constructor (props) {
        super(props);
        this.state = {
            
            username: '',
            password: '',
            login:2,
    
        };
    }



onButtonPress = () => {



              data.map((dataItem) =>{
                if(dataItem.user == this.state.username && dataItem.pass == this.state.password  ){
  
  this.setState({   login: 1 }, () => {

        Alert.alert("Welcome");
        this.props.navigation.navigate("Home");



    });



  }



             }  )


             if (this.state.login = 2) {
                 Alert.alert("Error");

             }



              }
State of Brave by Brendan Eich
Published: 2019-07-11 17:11:01

{% youtube h_jtopVp8dk %}

The web is seen as a major asset in today’s tech world but also comes with a few problems Brave is trying to solve.

The current web can be expensive, slow, invasive, insecure, and complex. Tracking methods and ad-blocking in browsers such as Chrome or Microsoft Edge end up costing users a significant amount in data and load times.
The Brave Browser was created to offer a fast and secure browsing experience. Brave’s mission is to eliminate browser features that cost the user in time and security. By obstructing data consumption of ad-tech, Brave has decreased load times by 3–7 times on both Android and iOS. This difference in load time makes for a very appealing platform, but the features don’t stop there:

#Security
By preventing pop-up ads and tracking on sites, Brave increases security around the user. When using Brave, common security risks like domain sharks and malware planted in pop-ups are eliminated from the user experience.

#Privacy
Brave puts a shield around the user to keep data safe on their device by limiting the access of middle men advertising mechanisms to user information.

#Easy to use

Unlike other browsers that require additional plugins and configurations that may not work well with one another, Brave includes everything you need into one box and conducts regular testing. This results in being able to engineer around common issues that many ad-blocking plugins run into.

#More than fixing browsing
Brave has private tabs, anti-fingerprinting, and the best security. It has a built in micropayment system, composed of a simple UI that is completely automatic by default. The system allows for automated payments made to the users’ top sites as well as enabling them to use patronage system. This allows users to compensate their top sites for the cost of security and privacy afforded to them through Brave.

Brave also provides a blockchain-based digital advertising platform. Currently, advertising stakeholders aren’t doing too well. They have an ecosystem that is complex and have has issues such as measurement error, measurement fraud, innocent errors, and more. Brave offers a more efficient platform which helps to combat these problems.

![image alt text](https://thepracticaldev.s3.amazonaws.com/i/tl6udrm9u4e3acm707g7.jpeg)

Using BAT — Basic Attention Token, Brave looks at helping the user, publisher, and advertiser, in dealing with revenue fraud and improve their services.

To learn more about the way that Brave is changing the way browsing works, check out their site at [https://brave.com/](https://brave.com/) or follow Brendan Eich on Twitter @BrendanEich.

By Necoline Hubner & Trinh Kien

*Need JavaScript consulting, mentoring, or training help? Check out our list of services at [This Dot Labs](thisdot.co).*
WordPress SSO with Auth0
Tags: wordpress, programming
Published: 2019-07-11 17:10:30

---
title: WordPress SSO with Auth0
published: true
description: WordPress SSO with Auth0
tags: #wordpress #programming 
canonical_url: https://auth0.com/blog/wordpress-sso-with-auth0/
---
Auth0 is an identity platform that offers comprehensive authentication solutions to cover customers in every market sector. One of our most popular features is Single Sign-On or SSO, for short. This feature lets users sign in only once to gain access to different sites and mobile and web applications.

To help secure one of the most popular web platforms in the world with the flexibility and power of SSO, Auth0 offers WordPress developers the Login by Auth0 plugin, which provides SSO between different WordPress installs and applications on any other platform.

The concept of SSO can be a little confusing for developers and site administrators that may be new to it. So in this post, we'll explore the different concepts associated with SSO and how our WordPress plugin can help you.

[Continue Reading 📖](https://auth0.com/blog/wordpress-sso-with-auth0/?utm_source=dev&utm_medium=sc&utm_campaign=wordpress_sso)
Decrease Your Time-to-First-Success
Tags: pedagogy, selflearning, diy
Published: 2019-07-11 17:06:59

---
title: Decrease Your Time-to-First-Success
published: true
description: The less time it takes to achieve something small but meaningful, the more likely you'll be interested in making something bigger.
tags: pedagogy,self-learning,diy
---

Start with the smallest possible goal when learning something new.

When you're learning music theory, make it a priority to write a tiny jingle consisting of just a melody. Make a lot of these! Consider them complete when the melody is finished.

When you're learning game design, try using a game with a level design feature, or design modded levels / steam workshop things for a game you like.

When you're learning to code, spend some time creating static webpages on a LAMP setup before doing anything else.

Your ability to stay engaged with the development of a skill might largely be governed by time-to-first-success. The shorter that time, the more quickly you get hooked in a positive feedback loop. And I don't mean build something like this as part of turning it into something bigger. I mean that the small thing you're trying to build should function as the MVP. When you've finished it, you start a new project, and can feel a sense of accomplishment from finishing something meaningful to you, no matter how small.
Building an Audio Player app with Angular and RxJS
Tags: angular, javascript, programming
Published: 2019-07-11 17:06:44

---
title: Building an Audio Player app with Angular and RxJS
published: true
description: Learn how to create an Audio Player app using Angular, Material Design and RxJS.
tags: #angular #javascript #programming 
canonical_url: https://auth0.com/blog/building-an-audio-player-app-with-angular-and-rxjs/
---
TL;DR: In this article, you will learn how to develop an audio player app using Angular and RxJS. You will handle audio operations and application state using RxJS. To secure your application, you will use Auth0. If needed, you can find the final code in this GitHub repository.

Introduction
Creating an audio player is always an intimidating task, especially if you think about managing the media's state, reacting to media events, and reflecting these changes correctly on the UI (User Interface). So, in this article, you will use Angular and Angular Material (with some other libraries) to easily tackle these challenges.

To handle media playback in a reactive way, you will wrap JavaScript's Audio object with an RxJS Observable and you will also use RxJS to manage the state of your audio player.

To provide a secure user experience through your application, you'll add user authentication through Auth0.

Prerequisites
Since you are going to use Angular, you will need to install Node.js in your development machine. So, if you haven't done so yet, go to the download page of Node.js and follow the instructions there.

[Continue Reading 📖](https://auth0.com/blog/building-an-audio-player-app-with-angular-and-rxjs/?utm_source=dev&utm_medium=sc&utm_campaign=angular_rxjs)
freeCodeCamp's JavaScript Calculator project built in Elm
Tags: elm, freecodecamp, webdev, showdev
Published: 2019-07-11 17:05:11

---
title: freeCodeCamp's JavaScript Calculator project built in Elm
published: true
description: 
tags: elm, freecodecamp, webdev, showdev
cover_image: https://thepracticaldev.s3.amazonaws.com/i/v65lydu4g0e516myj0t2.png
---

I enjoyed thinking my way through this [project](https://learn.freecodecamp.org/front-end-libraries/front-end-libraries-projects/build-a-javascript-calculator/). To make it a little more challenging I had two additional goals of my own.

1. To have a clean [separation between the UI and the application logic](https://dev.to/dwayne/separating-application-logic-from-the-ui-in-elm-8nj).
2. To have [an example](https://github.com/dwayne/elm-calculator/commit/87c49787dea873d1897317ffce799f6ae5b76586) where tests (in spite of types) are helpful in catching bugs.

You can read more of my thoughts [here](https://github.com/dwayne/elm-calculator#thoughts) in the project's README.

Here's my [demo](https://dwayne.github.io/elm-calculator/) and the [source code](https://github.com/dwayne/elm-calculator).

Whether you choose to just read the code or to build the project you will learn the following:

1. How to separate UI and application logic via a concrete example.
2. How to [represent a state machine](https://github.com/dwayne/elm-calculator/blob/8524029c188d519e3a34c5e45d6b535ac129c625/src/Calculator.elm#L15) using union types. The state machine is what drives the input to the calculator and it is [fully tested](https://github.com/dwayne/elm-calculator/blob/8524029c188d519e3a34c5e45d6b535ac129c625/tests/Test/Calculator.elm).
3. How to write [tests in Elm](https://github.com/dwayne/elm-calculator/tree/8524029c188d519e3a34c5e45d6b535ac129c625/tests/Test).
4. The importance of testing even in a typed functional language.
5. How to implement a [stack](https://github.com/dwayne/elm-calculator/blob/8524029c188d519e3a34c5e45d6b535ac129c625/src/Stack.elm).
6. How to implement the [shunting yard algorithm](https://github.com/dwayne/elm-calculator/blob/8524029c188d519e3a34c5e45d6b535ac129c625/src/Expr.elm#L17).
7. A [neat algorithm](https://github.com/dwayne/elm-calculator/blob/8524029c188d519e3a34c5e45d6b535ac129c625/src/Rational.elm#L101) for displaying rational numbers as decimals, for e.g. displaying `1/6` as `0.1(6)`.
8. How to iteratively add features to an application, [commit by commit](https://github.com/dwayne/elm-calculator/commits/master).

If you want to learn by doing or even contribute to the project then you can try tackling these [issues](https://github.com/dwayne/elm-calculator/issues).

Let me know in the comments if you'd be interested in a more detailed analysis of this project via a tutorial or otherwise.
Hello
Tags: hello, checkitout
Published: 2019-07-11 16:20:15

Hello! We Have Made A Website Called 
http://venatus.club

We'd Greatly Appreciate It If You Checked It Out And Give Us Some
<i>Constructive Criticism </i>



Glowing Regards,
  Venatus Team
<img src="http://venatus.club/images/glowing.png" width=40%/>
How To: install ubuntu on VirtualBox
Tags: ubuntu, linux, virtualization, howto
Published: 2019-07-11 16:13:45

Hi, In this article, we will see how to use Linux in a virtual machine and how gives you the option to try Linux within Windows. 
This step-by-step guide shows you how to install ubuntu server inside Windows using VirtualBox.

# What is virtualization?
Virtualization is technology that allows you to create multiple simulated environments from a single, physical hardware system.
 

## Install ubuntu server on VM virtualbox: 
1.Open Virtualbox and click at New button.
Setup Wizard will appear, Enter your Virtual Machine name, and choose your guest OS and architecture (32- vs. 64-bit) from the dropdown menu and click Next button.
![](https://thepracticaldev.s3.amazonaws.com/i/8vn5jo6h1m159pvn9ami.png)
2. Enter memory (RAM) to reserve for your virtual machine and click Next button.
![](https://thepracticaldev.s3.amazonaws.com/i/384f2hqj1dw7fez6ufot.png)
3.Tick at Startup Disk and Create New Hard disk and click at Next button.
Choose the type of file that you want to use for virtual disk and click Next button.
![](https://thepracticaldev.s3.amazonaws.com/i/30k1wjnc3egrb011v147.png)
3.2 Choose your storage detail and click Next button.
![](https://thepracticaldev.s3.amazonaws.com/i/q138cbw4k85uy0exfroe.png)
4. Enter the size of your virtual disk (in MB) and click Next button.
Put how much space you need depending on your hardisk and finish the wizard by clicking the create button.
![](https://thepracticaldev.s3.amazonaws.com/i/zd7vgn1yo7iso5ab9lo6.png)
You will see the detail of your input here. Click Create button to continue.

The "New Virtual Machine Wizard" will close and back to VirtualBox Manager. Select your Virtual Machine and click Start button.
![](https://thepracticaldev.s3.amazonaws.com/i/2encn0azh8pyrbn5yyad.png)

Click at 'folder' icon and choose your Ubuntu iso directory, then Select your Ubuntu iso file and click Next button.
click Start button to show ubuntu screen when it start boot.
![](https://thepracticaldev.s3.amazonaws.com/i/y0g7annu91zb0m0bg20b.png)