Skip to main content

Variable-Size Directories

QA teams sometimes send requests like this:

For testing purposes, I need the /opt/test/xxx directory limited to 10 Megabytes. This directory is used by the abc123 application, which runs as user tester.

Can a directory’s size be limited in Linux? Yes. You need to:

  1. Use the directory as a mount point for a size-limited storage device.
  2. Set mount options so the specified non-root user has full access.
  3. Disable SELinux (easy) or allow that particular user to access data on mount points (complicated).

Choosing the storage device

There are several options:

Read full post gblog_arrow_right

On Companies and Career Paths – a Personal Overview

Starting a career in computer science is hard enough, and landing with a good company is mostly down to luck. I won’t argue with that: you do need plenty of luck to get off to a good start. My aim is simply to show where the train you’ve just boarded might take you, or might not. Switching trains is always possible, but it gets harder with age.

At a high level, companies fall into two main categories:

Read full post gblog_arrow_right

The First Linux Certification (LPIC-1): How To

I recently earned my LPIC-1 certification (verify here). Here’s what I learned, in case you want to try it and aren’t sure where to start.

Introduction

LPIC-1 is granted after passing two exams:

  • Exam 101: more theory-oriented, with many general questions.
  • Exam 102: more practice-oriented, with an emphasis on scripting, networking and security.

You can take these exams in any order, and the certification is awarded automatically once you’ve passed both. Higher levels require the lower-level certification first. For example, any LPIC-3 certification requires passing a total of 5 exams, again in any order.

Read full post gblog_arrow_right

Python: Crazy Interview Questions

1. The Mutable Default Argument Trap

Imagine an interviewer hands you a slip of paper with this on it:

def foo(bar=[])

No context, just the question: what’s wrong with this code?

Strictly speaking, nothing. It’s valid Python (aside from the missing colon and function body), and a bug is only a bug when the code behaves differently from what the programmer intended.

Read full post gblog_arrow_right

Linux Performance Monitoring (an Introduction)

1. Classification

“Performance” is a broad term, so it helps to split it into categories first. Two questions do most of the work:

  1. What do we want to monitor? The whole system, or one particular application?
  2. What kind of monitoring do we need? Basic statistics gathered by the kernel, or in-depth analysis?

Combining the answers gives four categories, each with its own set of tools:

Read full post gblog_arrow_right

Python Cheat Sheet: Lambdas

Do you think list comprehensions are a tricky topic? After reading this post, you may well change your mind about what counts as “complicated” in Python.

Lambdas

A lambda is a small function defined right where you need it, typically for light data-processing jobs. There are two main reasons to use them:

  • Speed: a compiler can optimize them, first by eliminating an actual function call, and then by opening the door to further internal code re-arrangements.
  • Brevity: you write less code.

Here is a lambda that squares a number:

Read full post gblog_arrow_right

Python Cheat Sheet: Dictionaries

Python dictionaries are built on hash tables. They can hold arbitrary key-value pairs, and the keys and values don’t have to share a single data type. Dictionaries are unordered, meaning no ordering between elements is defined, so you can’t rely on any particular sequence when iterating over them.

Note: Unless stated otherwise, all examples use Python 2 syntax.

Creating an empty dictionary

D = {}

Initializing a dictionary

D = dict((i, False) for i in xrange(1, 11) if i % 2 == 0)   # Python 2
D = {i: False for i in range(1, 11) if i % 2 == 0}          # Python 3

Note: the second form is known as a dictionary comprehension.

Read full post gblog_arrow_right

Note to Self: HTTP Server KeepAlive Timeout

Note: I have ran into this problem on Apache httpd, but it could just as easily affect any other HTTP server.

HTTP KeepAlive

The idea behind “KeepAlive” is straightforward: instead of opening a new connection for every request, the browser opens one connection to the server and reuses it to fetch many resources, such as the main page, stylesheets, JavaScript files, and images. In theory, this cuts page load times and gives visitors a better experience. So far, so good.

Read full post gblog_arrow_right

Python Cheat Sheet: Lists

Lists are ordered, linear collections that offer constant-time element lookup by index. They can grow or shrink, be searched, and be sorted (including with a custom comparison function). They also aren’t limited to one data type, so a single list can hold a mix of values. Python lists are zero-indexed.

Note: Unless stated otherwise, all examples use Python 2 syntax.

Creating a pre-filled list of 10 numbers (all zeros):

A = [0] * 10

Creating a pre-filled list of 10 numbers (powers of 2):

A = [2**i for i in xrange(0, 10)]

Note 1: xrange in the example above produces the values 0 through 9, inclusive.

Read full post gblog_arrow_right