Posts

Showing posts from 2016

List all Rails helper methods

Image
Just wanted to share a snippet of code to get all Rails helper methods:

Pusher with Redux

Image
You might have heard about a wonderful service called Pusher . It is a service which allows you to make live updates without handling infrastructure on your own. When I wanted to add it into my React - Redux application I was surprised to find out that there are no libraries which help you. So I decided to write my own. I called it pusher-redux . I think it turned out to have a very convenient API you can call anywhere from your Redux application. Let me explain how to use it below. First you need to configure Pusher in your app.js: Then you need to subscribe to it in your component: This is how you handle it in your reducer Pusher-redux dispatches actions of the following format, you can find data you send in action.data:

Smart page titles in Ruby on Rails

Image
Having separate titles for each page in Rails application is a very common requirement and yet RoR does not provide any built in ways to deal with it. I am going to present you with some handy code that can solve this problem without use of gems. There are going to be 3 ways to define a page title: For tho whole controller. For a specific action inside a controller. Implicitly from a controller name. Last is gonna be especially useful, you can just drop the following code into your application and have reasonably good titles. So lets add code to our parent ApplicationController: And reference page title in our layout: After that setting pages titles is extremely easy. You don't even have to do it if you are naming your controllers properly.

DNS over HTTPS

Image
In the land of Russia where your freedom is becoming ever more limited goverment is trying to censor the Internet. Those who are not content with website bans have to find ways how to get around this problem. One way to get around the block is to use Google's DNS instead of the DNS provided by your ISP. After reading Hacker News today I stumbled on an intersting arcticle. The gist is that Google provides an encrypted way to access DNS (unlike traditional UDP which can be easily monitored by your ISP). Unfortunately there's no way to just point your router or computer to it because DNS has a protocol and since Google secure DNS doesn't conform to it existing programs can't access it directly. So in this article we are going to set up our own DNS server, and yes, it can have blackjack and promiscuous women. Some kind soul has written a Go package to interact with this secure DNS server. It is located here: https://github.com/wrouesnel/dns-over-https-proxy . We a

Easy error handling in Rails

Image
Let me start by asking what do you think about errors? Many people hate errors and are trying to avoid them as much as possible. But today I want to show how errors can make your life easier! Let's say user submitted some form in your application. Where do you check if it's valid? In the controller? Controller's should not be concerned with all that is going on in our models. Should the controller ask a model if data is valid or not? Model should be already checking incoming data.What is you introduce some change deep inside your code, you can't expect to know all the place where it's used! In Java World (and in others) errors are not actually called "errors", they are called "exceptions" and they can help you to handle exceptional situations. Ruby language has similar exception system. Errors can be raised and rescued. Let's distinguish between 2 types or errors. 1) Ones that we can actually anticipate and fix. 2) All