Configure Mailgun settings in Rails app

Recently I’m learning to create a Rails 5 api only application with an android mobile application. I want to send a activation email after user registered from the android app, and I found there is a free Mailgun add-on on Heroku. It’s perfect choice to start to play with because you can send up to 100 messages/hour without being charged. The documentation is good enough but I do found several steps confusing.

Firstly, you need to create a Mailgun account and add your credit card information, otherwise you can’t send to recipents other than authorized ones(which means test only).

Then, use the test domain(XXX@XXX.mailgun.org) to ensure Mailgun not being blocked by your test mail address(In my case I use qq mail at first, it actually blocks all traffic from mailgun). After that, you need to add a custom domain. Go to your domain name provider and configure DNS settings as following the steps of Mailgun instructions. In my case I use Namecheap and it took me a while(a cup of coffee) for Mailgun to verify my domain.

After your custom domain is active, configure your development environment and make sure it works. In my case I use smtp instead of api call, the settings are for example:

  config.action_mailer.delivery_method = :smtp
  config.action_mailer.smtp_settings = {
	:address => "smtp.mailgun.org",
	:port => 587,
	:domain => mydomain.club',
	:user_name => "postmaster@mydomain.club",
	:password => XXXX
  }

Then start your rails server and see if the mail was delivered. I spent quite a few hours here because at first my emails weren’t delivered. I refered to the log and showed Mailgun accepted the mail address, and one minute later a ESP throttling message showed up. The reason is Mailgun being blocked by certain ISP(like qq mail, in this case I have to use an extra mail hosting service), so I couldn’t see any mail sent inbox.

If OK in development environemnt, change your production settings as well, it should work as well.


如何在ubuntu16通过终端设置shadowsocks实现科学上网

给三年前买的旧笔记本重装了Ubuntu桌面版,第一件要做的事就是科学上网啦。

┗(・o・)┛ナハ┗(・o・)┛ナハ

shadowsocks的安装有两种方法,一是安装shadowsocks-qt5 GUI版,二是通过终端运行shadowsocks。我试过了第一种GUI安装,但是一直连不上服务器,发现输出的json配置文件格式是错误的,于是选择了第二种, 具体步骤如下:


1. 下载shadowsocks

sudo apt-get update
sudo apt-get install python-pip
sudo apt-get install python-setuptools m2crypto
pip install shadowsocks


2. 设置配置文件

{
"server":"XX.XX.XX.XX",
"server_port":XX,
"local_port":1080,
"password":"your password",
"timeout":600,
"method":"aes-256-cfb"
}


3. 启动shadowsocks

sslocal -c /your/path/shadowsocks.json

如果启动成功了可以看到如下信息(/home/momoko/shadowsocks/ss-config.json是我存放配置文件的路径)

INFO: loading config from /home/momoko/shadowsocks/ss-config.json
2016-12-06 19:31:54 INFO     loading libcrypto from libcrypto.so.1.0.0
2016-12-06 19:31:54 INFO     starting local at 127.0.0.1:1080


4. 设置浏览器

接下来需要设置浏览器,代理到shadowsocks指定端口(默认情况是1080)

我使用的浏览器是Ubuntu下的Chromium,chrome插件本来可以在chrome商店里下载到,成功翻墙之前是进不去的。这里推荐从github上下载SwitchyOmega,里面有中文下载说明, 网址如下:

https://github.com/FelisCatus/SwitchyOmega/releases/

还有配合GFWList的使用方法:

https://github.com/FelisCatus/SwitchyOmega/wiki/GFWList

下载结束之后需要设置代理选项,情景模式里选socks 5, 端口号1080,其余设置参考上述链接。

打开youtube或是facebook测试一下,有点小惊喜呢。┌ ≧∇≦


5. Attention

值得注意的是,虽然浏览器可以翻墙了,但是用终端访问比如curl www.google.com 还是没有响应,这里需要安装额外的插件,我使用的是proxychains4,具体安装方法请自行搜索。如果你运行的是例如polipo全局代理的插件,在终端运行某些命令会失败(比如说git clone),这时候暂时关掉代理插件即可。

什么?不会安装?浏览器都能翻墙了还不谷歌一下。 ( ̄▽ ̄人)) ((人 ̄▽ ̄)


自从学会科学上网,看youtube视频根本停不下来。

へ( ̄ ̄へ)(ノ ̄ ̄)ノ パラパラ♪

最后推荐一个颜文字网站:

http://kaomojiya.com/


Troubleshooting with Installing Broadcom Wireless Drivers in Ubuntu Desktop

Days before, I changed the operating system of my old laptop from Windows7 to Ubuntu Desktop, I installed Ubuntu from a USB stick from my friend. After installing I found I Broadcom wireless driver wasn’t installed so I couldn’t connect to my WiFi. I tried several ways then found the solution, hope it my be helpful.

To download the driver from Internet, you need to connect with Ethernet.

Open Software and Update from system and configuration, open the fifth tab optional drivers and see if wireless driver comes out or not.

Make sure allowing downloading drivers from Internet is checked in the first tab Ubuntu Software.

If it still doesn’t come out, you need to manually install it from terminal, use lspci -nn -d 14e4: command to see which network card you’re using, then install the corresponding driver. http://askubuntu.com/questions/55868/installing-broadcom-wireless-drivers offers an excellent guide.


My Experience And Thoughts on Remote Working as A Junior Programmer

About Me And My Job

I started my current job a year ago when I was an exchange student in Japan, I was second year in university then. I worked in the office for 9 months, after that my exchange year ended, I went back to my home university and started remote working since then. Until now, it has been half year.

I rent an apartment and lived alone near my university. I’m not full-time employed, I worked for about 5 hours a day, every day in the week because I found this schedule suits me better. When I’m not working, I go to classes, playing the piano or reading books.

My Half Year on Remote Working

good parts

The best part of remote working is much more free time. I don’t have to wake up early and spend hours on a crowded subway to the office, I could spend more time on doing whatever I want to do.

Also for me, working from home is easier to concentrate because there are fewer distractions.

My desktop and my friends o(●´ω`●)oわくわく♪

challenges for a junior programmer

For me, the biggest challenge is finding out the solution to the problem independently. As a junior developer, I don’t have much experience, when I encounter a problem that appears for the first time, it’s hard to get response from my colleges immediately, more often, I have to find out how to handle it by myself, sometimes it’s quite hard because I really don’t know what to do with it, and have to dig really deep on the problem.

The second is about confirming specification. When I just started remote working, it’s quite often to get confused with specification in junior year, and confirming specification online usually takes more time than face to face, and I have to make sure my colleges are available at that time.

Another challenge is about building up habits. For me, I don’t have a fixed working schedule, sometimes I find it hard to get myself backing to working from the lure of reading Reddit or watching Youtube videos. It needs self-discipline to keep myself from slacking off.

mental challenges

It’s easy to feel emotionally detached with other people. Since I live alone, and my colleges are all in another country, I feel lonely from time to time. I can’t keep being productive if I feel lonely. It’s not healthy to keep sitting in front of a desktop for all day, going out and networking is also important.

My Thinkings

I loved my current living style. I can get my work done and do whatever I want to do. For me, it’s not easy at first, half year later, I enjoy more and more.


Use class_eval and instance_eval

current object and current class

Everything is an object in Ruby, there is an current object and current class referred to in every line of code. We use self to refer to current object (there is no keyword for current class).

When call a method on an object, self(current object) is the receiver of the method. In a class definition, self(current object) is the class itself.

Though there is no keyword for current class, it’s easy to refer to as long as we know what is our current object.

class_eval

Module#class_eval is used for modifying current class. It’s commonly used when we don’t know the exact name of class we want to refer to. For example,

def add_method_to(my_class)
  my_class.class_eval do
    def foo
      puts 'foo'
    end
  end
end
			
add_method_to(String)
"bar".foo
#=> "foo"

One example in Rails is putting common code for several models (just like what model conern does). For example, I want to add common validations for my models, I can create a module and use class_eval to add methods in classes that include it. In order to get that class, we need a hook method self.included, and put class_eval part inside this method.

module SomeCommonModule
  def self.included(base)
    base.class_eval do
      validates_presence_of :balabalabala
    end
  end
end

instance_eval

instance_eval is used for modifying current object (self), it breaks encapsulation, be careful with it.

An example is to change instance variable of an object:

class Foo
  def bar
    @bar = "bar"
  end
end

foo = Foo.new
foo.bar
puts foo.instance_eval { @bar }
 #=> "bar"
foo.instance_eval { @bar = "bbbbar" }
puts foo.instance_eval { @bar }
 #=> "bbbbar"

   Tags
life ( 4 )
music ( 1 )
programming ( 11 )
spirituality ( 1 )
中文 ( 2 )
language-learning ( 1 )

About Me

I'm a university student in the last year, also a web developer. I love exporing cultures, learning languages and making BGM music!