# Setting up a Fetch-Only Remote

It may happen that you have a remote to which you have push rights but will never want to push. If you are afraid of pushing your changes to it by accident or just want to play it safe, this command may be of assistance:

git remote set-url upstream --push disallowed


This makes the push url of the upstream remote (use whatever name your remote has) an invalid address that will prevent accidental pushes.

# What CS Majors Should Know

This post is a collection of highlights from this fantastic article about what every computer science major should know by Matt Might.

# Portfolio over Resume

A resume says nothing of a programmer’s ability.

Every computer science major should build a portfolio.

# Communication

Modern computer scientists must practice persuasively and clearly communicating their ideas to non-programmers.

# Unix

Given the prevalence of Unix systems, computer scientists today should be fluent in basic Unix.

# Programming Languages

While it is important to teach languages relevant to employers, it is equally important that students learn how to teach themselves new languages.

The best way to learn how to learn programming languages is to learn multiple programming languages and programming paradigms.

# Mathematics

Computer scientists must be fluent in formal mathematical notation, and in reasoning rigorously about the basic discrete structures: sets, tuples, sequences, functions and power sets.

# User Experience

Programmers too often write software for other programmers, or worse, for themselves.

User interface design (or more broadly, user experience design) might be the most underappreciated aspect of computer science.

# Databases

It’s useful to understand the fundamental data structures and algorithms that power a database engine, since programmers often enough reimplement a database system within a larger software system.

# There is more

There is much more than this on the original post. It is also supposedly an alive post, so you should definitely check it out from time to time. There is also some really nice stuff about which languages the author thinks provide a reasonable mixture of paradigms and practical applications that I did not quote because it is fairly long.

# Improving JTextPane Performance

After I started benchmarking how much time commands took to complete in Dungeon, I noticed that writing a full world map (a grid of colored ASCII characters) to the screen was reasonably slow. Then I set forth to find the solution to my problem.

Basically, there are two causes for slow JTextPane updates: each insertion triggers a re-rendering of the display and some methods in the DefaultStyledDocument class are synchronized, so there is the overhead of acquiring locks.

I worked on the first issue and was able to reduce the overhead of insertion substantially. I wrote a class that keeps two StyledDocuments: one inactive and one set to the JTextPane the class is responsible for. When text is written to this object, it will update the StyledDocument that is inactive, swap both documents, and then update the now inactive StyledDocument. Why keep two documents? Some insertions are just small increments, that really benefit from not having to rewrite a long passage of text multiple times.

How to make it faster? Instead of running the second document update (the user has already seen the update one because the swap has already taken place) on the same thread, delegate it to a worker thread. Note that this approach will block this object for a while. To keep it simple and avoid premature optimization, I did not even code this multithreaded version. But I am mentioning it here just in case someone (maybe me) needs it in the future.

For reference, the issue related to the post.

# Getting the Size of an Object in Python

Recently, I found myself wondering how much memory a Python list I had in my environment was using. So I searched and found the following very handy function for the curious minds or desperate debuggers.

sys.getsizeof(object[, default])

Return the size of an object in bytes. The object can be any type of
object. All built-in objects will return correct results, but this does
not have to hold true for third-party extensions as it is implementation
specific.

Only the memory consumption directly attributed to the object is
accounted for, not the memory consumption of objects it refers to.

If given, default will be returned if the object does not provide means
to retrieve the size. Otherwise a TypeError will be raised.

garbage collector overhead if the object is managed by the garbage
collector.


# Adding a GPG Key Manually

I was trying to install MongoDB 3.0 in my production machine and in order to be able to do that via apt-get I needed to import the MongoDB GPG public key.

It went wrong. It went really wrong.

After a huge delay at

gpg: requesting key 7F0CEB10 from hkp server keyserver.ubuntu.com


I would get

gpg: keyserver timed out
gpg: keyserver receive failed: keyserver error


The first solutions I found on the internet for this problem were modifying other commands to look like mine. So I already had the “best command”.

After some more Googling I found that I could grab the key manually and add it without a request to a server.

So I tried and got the key.

Ran

sudo apt-key add 10gen-gpg-key.asc


And the shell told me

OK


That was it. I decided to post about this so that if you find yourself in a similar scenario (cannot get keys via the command line), you have an idea of how to solve the problem. It also serves as a future reference to me, as StackOverflow didn’t do it this time.