euccas.github.io

why a developer writes

Start Unit Testing in Python

| Comments

When is the best time to start unit testing in your Python project? My answer is before you writing the first line of code of this project. Unit testing is the fundamental of Test-driven development, which specifically improves the quality and design of your project.

In this post, I’m writing about how could you do unit testing in Python with the unittest module.

Python 2 (starting on version 2.1) and Python 3 now both have unittest in the standard library. The unittest module provides the unit testing framework, and it’s based on JUnit, which is a unit testing framework for Java.

Rake: Automake Your Tasks in Ruby

| Comments

Rake is the build language for Ruby programs, originally developed by Jim Weirich. It’s a standard library in Ruby 2.1. You can define tasks with Rake: named code blocks that carry out specific actions, such as running unit tests, deploy your code to github, etc. In this post, I’ll write about the basics of Rake and how to use it to automate the tasks of your Ruby projects.

Rakefile

In order to use Rake to define tasks, first you need a Rakefile. A Rakefile is a Ruby source file that has access to some special methods: task, file, directory, and a few others. A task defined in the Rakefile can be run by the command-line rake program, or be called as a dependency by other tasks. The name of Rakefile can be Rakefile or rakefile.

Rails: Get Data From PostgreSQL Database Without the Model

| Comments

In Ruby on Rails, Active Record is the M in MVC - the model. Model is the layer of the system which represents business data and logic. Active Record facilitates the creation and the use of business objects whose data requires persistent storage to a database. In some cases, however, you may want to use databases in Rails applications without the Model. What you can do is using the pg gem to directly manipulate the data you need.

Create a database connection

If the database is not declared in Rails app’s config/database.yml file, you won’t be able to use the establish_connection method in ActiveRecord. But you can still use the pg gem to directly connect to the database.

Ruby Class and Instance Methods

| Comments

If you ever get confused about Class Methods, Instance Methods, Class Variables and Instance Variables in Ruby, read this post and you’ll understand it better :)

Class Methods

  • Class methods belong to a class in Ruby, and it can be used without instance any class object.
  • The definition of class methods has a “self” prefix.
1
2
def self.show_name
end

高效Jenkins用户的第3个习惯

| Comments

本文内容部分来源于Andrew Bayer发布在SlideShare上的 7 habits of highly productive Jenkins Users (2014 Edition).

习惯 3: 让Jenkins任务自动化

1. Script Console 和 Scriptler 插件##

使用(Scriptler插件)[https://wiki.jenkins-ci.org/display/JENKINS/Scriptler+Plugin],保存和重用Groovy脚本

2. 一些Scriptler可以做的事情的例子

  • 通过匹配,控制一些job的开关 (enable, disable)
  • 清除build queue
  • 为所有的jobs设置log rotation/discard old builds等等配置参数:如果采用手工的方法,需要分别对每一个job进行配置,步骤繁琐
  • 对所有的jobs设置取消夜晚时间的SCM Polling: 这个功能其实就是批量设置jobs schedule
  • 对所有jobs执行log rotator

这只是一些例子。可以看出,使用scriptler可以方便对job的配置进行批量操作