ltsBlog

Fixing “Wrong type argument: characterp, return” in !Emacs

A few months ago, I ran into an issue with Emacs that I just found the solution to. In Emacs term-mode (or ansi-term, or multi-term), hitting Enter doesn’t work, and the mini-buffer displays Wrong type argument: characterp, return, and the term doesn’t see the keystroke.

I dented about it on identi.ca, and no one was able to help me. This turned out to be a mistake, because I kept seeing the dent as I Googled/DuckDuckGo’ed for a solution.

Anyway, I finally found the solution on the Korean blog Seorenn SIGSEGV.

The problem is basically that autopair had remapped the return key to an autopair function, which didn’t jive with term-mode. At least, that’s what Seorenn said.

If it were that simple, I would have noticed it when I installed autopair. Only in some environments does the problem manifest. For example, on Ubuntu, where I started using autopair, the problem never appears. When I switched to Fedora (and later Parabola), I figured it was some issue with the X server, because it worked fine when running in a terminal.

Now knowing that the problem was related to autopair, I can’t figure out how it ever worked.

Anyway, the fix is to add the following to your .emacs:

(add-hook 'term-mode-hook
  #'(lambda () (setq autopair-dont-activate t)))

(Code segment from emacs-fu, via Seorenn SIGSEGV.)

Posted in Computers | Leave a comment

[Emacs] autopair problems when using term-mode

I found this awesome blog post on the Korean blog Seorenn SIGSEGV.

Using Google translate, I was able to extract the information I needed. However, Google translate quite botched it, as did Yahoo and Bing translate. I’ve used a combination of these three tools, and my understanding of Emacs, to put together a more reasonable translation.

I’m posting the full English text of it here because this is a problem I’ve had, and would like to help others find the solution. I don’t mean to rip off the original author, his blog seems quite good, worth reading, if you don’t mind poor translations (or, can read Korean).

The original post can be found here here.

In Emacs term-mode (M-x term) and multi-term-mode pressing the Enter key causes an error to appear in the mini-buffer, and the keystroke appears to have been eaten.

This problem only occurs when using autopair. are thought to In addition to or RET (Enter) as a separate feature for all modes of binding may also occur. if autopair the last of the solution are presented.

See below sum up shoveling machine.

Issue

During term-mode RET does not work. The mini-buffer shows the error message Wrong type argument: characterp, return. RET has been bound to something here, or maybe you saw the state I had a feeling heard nil.

Alternative

Fortunately, I was able to replace the RET key with C-j. This is used as a temporary measure to work with.

Cause Analysis

In term-mode use C-h k to find the function that RET is bound to. autopair that certain functions were bound.

As a result, be sure that autopair is the culprit.

Attempted Solution

In term-mode C-h k with C-j to determine the function bound to: term-send-raw.

In conclusion, I believe you will solve the problem in the RET key bindings by using define-key to bind the key to term-send-raw in term-mode-map.

But the code encounters an error. Is not allowed to do something it felt like.

Solution

The code below. Not two lines were able to solve it.

(add-hook 'term-mode-hook
  #'(lambda () (setq autopair-dont-activate t)))

Source of the above code: http://emacs-fu.blogspot.com/2010/06/console-apps-in-emacs-with-multi-term.html

Posted in Computers | 1 Comment

Why `sed -i’ exists

I’ve decided to to a morning-pages type thing here, just to get info out. This means that I’ll be posting 250-ish word weblog post
snippits sharing whatever, and fairly frequently posting, if this works.

So, what is the purpose of the -i flag to sed? Simply, it edits the file in place, instead of dumping the edit to stdout.

Those of you familiar with “cat -v Considered Harmful” or just traditional UNIX design will say “bah, what a useless flag, just use sed 's/regex//' < file > file to write the changes back to the file.

But there’s a problem with this. There is a race condition, the file has been opened twice, once for reading, and once for writing. If they get closed in the wrong order, you will end up with an empty file. In my experience this very seldom happens. However, when you have a shell script that usually works, but just occaisionally corrupts your `database’, you’ll see why sed -i‘s important.

Posted in Computers, morning-pages | Leave a comment

Questions about copyright of the deceased

I recently acquired a fairly recent printing of Why We Can’t Wait by Martin Luther King Junior. Now, I assumed that the copyright of the book would have passed to either his children, or some foundation. However, feeling curious I decided to check.

Following is the copyright page at the beginning of the book. I’ve collapsed some sections that are not relevant to my question into [...]. Emphasis mine.

SIGNET CLASSICS
Published by New American Library, [...]

Penguin Books, Ltd., [...]

Published by Signet Classics, [...]

First Signet Classics Printing, January 2000
30 29 28 27 26 25 24 23 22 21

Copyright © Martin Luther King, Jr., 1963, 1964
Introduction copyright © Reverend Jesse L. Jackson, Sr., 2000
All rights reserved

Printed in the United States of America

Without limiting the rights under copyright reserved above, no part of this
publication may be reproduced, stored in or introduced int a retrieval system,
or transmitted, in any form, or by any means (electronic, mechanical, photo-
copying, recording, or otherwise), without prior written permission of both
the copyright owner
and the above publisher of this book.

If you purchased this book without a cover [...]

The scanning, uploading, and distribution of this book via the Internet of via
any other means without permission of the publisher is illegal and punish-
able by law.
Please purchase only authorized electronic editions, and do not
participate in or encourage electronic piracy of copyrighted materials. Your sup-
port of the author’s rights is appreciated.

(To those who will comment on it, my posting of the above text is firmly within fair use.)

So, my questions are:

  • Is MLK still the copyright holder? Yes: Getting his permission is a little hard. No: Whose permission do I need?
  • Is distribution without permission of the publisher really illegal? What legal stake do they have to the text of the book? Isn’t it really the copyright holder’s permission I need? (for the text anyway, I’m not concerned about things like typesetting and cover art).
  • I find it humorous that they end their plea for me to not pirate the book with a thank you for supporting MLK’s rights. Because he totally appreciates his copyright to draw a profit from the book right now. Because he’s more concerned about other not making copies of the book than spreading the message, especially now that he’s dead, and can’t draw a profit from it anyway.
Posted in Uncategorized | Leave a comment

Pointers in Java

This was originally posted to Facebook by me at 2010-08-02 23:20.

Note: For purposes of anyone interested in this, pointers in Java are more commonly referred to as references, because everything in Java must have it’s own name (method vs. function). This makes operating the Google DuckDuckGo machine easier. I wish I had known that when I wrote this.

In Java there are a few `primitive' datatypes, the rest of the datatypes are
implemented as classes.  They are:

byte
short
int
long
float
double
char
<pointer>

Normally, when declaring a primitive, you write the type of the primitive as
the variable type.  However, the reason I wrote pointer in brackets is that you
DON'T write pointer when declaring a variable storing a pointer.

For example, when I write
java.util.Stack stack = new java.util.Stack();
The variable stack does NOT store an object. It stores a /pointer/ to an object.
A pointer stores the memory address where a object is stored.

ALL VARIABLES STORE PRIMITIVES, IT IS IMPOSSIBLE TO STORE AN OBJECT.
For this reason, it is possible for the JVM to manage memory for you; it keeps
track of the pointers, and once there are no more pointers pointing to a
particular object, it can be deleted.

Why does this matter?  Well, consider that `String' is a class
(`java.lang.String'), not a primitive.  Consider the following code:

String str1 = "foo";
String str2 = "foo";
return (str1 == str2);

If String were a primitive, it would return true; but it returns false.
Strings are a little complex because they contain syntactic sugar.  Let's do
the same example with an integer instead:

Integer int1 = new Integer(5);
Integer int2 = new Integer(5);
return (int1 == int2);

The `java.lang.Integer' class is a class wrapper around the `int' primitive.
The `new' operator creates a class, and returns a pointer to it.  The source
code to the java.lang.Integer class contains the:
    private int value;

    public Integer(int val) {
        value = val;
    }

So, the above example generates to objects belonging to the java.lang.Integer
class.  Even though the .value's of the two objects are the same, they are
separate objects.  Therefore, int1 and int2 store two separate memory locations.
These two locations in the memory store the same data, but it is stored at both
locations.

The `==' operator takes two primitives, and compares their direct values.
Since int1 and int2 store two different memory locations, `(int1 == int2)'
evaluates to false.

Note: as pointed out by Ari Consul, everything following is false. The JVM does not copy the objects, it returns the pointer directly (no magic, as I’d suggested). The JVM will free() the object when there are no more pointers to it, via basic reference-counting

About copying objects:  when returning a private pointer, the JVM makes a copy
of the object that the pointer points to, and returns a pointer to the new
object, NOT the original pointer.

For example if I declare the method:

public static Integer getInt() {
    Integer val = new Integer(5);
    return val;
}

It does NOT actually return `val'; it returns a new pointer to a copy of the
object that val pointed to.
Posted in Computers | 2 Comments

Java has issues

This was originally posted to Facebook by me at 2010-09-02 23:19. It was edited by me there 2010-07-03.

Java is an alright language. There are a lot of things it does right, but there
are a few things it doesn’t.

  1. Distinction between classes and packages. I should be able to create
    sub-classes the same way as I add classes to a package; a package should
    just be an empty class.
  2. Too many primitives. I should be able to (re-)construct more of the
    language.
  3. No preprocessor/inlines. OO isn’t an excuse for this, make me do it at the
    class level (or rather, source file, not supporting `#include’ is fine). I
    should at least be able to add `#define int8=byte’ like in C. This
    wouldn’t be as much of an issue if all these things weren’t primitives; I
    could just do “public class int8 extends byte”. (yes, I could extend the
    `Byte’ class, but it wouldn’t come with all the syntactic sugar primitives
    get.)
  4. Numbers: names. Yes the names used are long-standing convention in CS.
    These include some of the worst short-sighted mistakes in all of
    hackerdom… because they stuck. Yet, most reasonable languages can still
    support them, and sane equivalents.

    • byte -> int8
    • short -> int16
    • int -> int32
    • long -> int64
    • float -> float32
    • double -> float64

    This would easily be fixed if they weren’t all primitives (point 2), or if
    I had a preprocessor (point 3).

  5. Numbers: unsigned. How about unsigned integers (uint16)? This would be
    easy to implement, if everything weren’t a damn primitive.
  6. Give me an actual `struct’, like in C. I’m not asking for full manual
    memory management, just the ability to organize a chunk of it; you can
    still manage it for me. It would make serialization hellofalot
    easier.
  7. It’s inconsistent about whether it uses the system encoding or it’s
    internal encoding. The String object just became worthless to anyone
    wanting to do any amount of I18N.
  8. It’s internal encoding is junk. It maps UTF-16 symbols onto the `char’
    primitive, which is 16 bits.

    1. UTF-16 is junk, use UTF-8
    2. With any UTF encoding you must allow for a dynamic bit-length, for
      UTF-16 it’s 16-32 bits, UTF-8 is 8-32 bits

    I understand how/why it arrived at the solution it uses; at the time Java
    was designed, it was using UCS-2, which is a 16-bit encoding, and was
    superseded by UTF-16 in 1996 with Unicode 2.0. However, this is one of
    those things where you specify a new JVM version, and switch to UTF-8. You
    can even leave a legacy mode in the JVM that still uses UCS-2.

  9. Octal prefix: `0′ is used as the prefix to specify an octal literal. Any
    third-grader can tell you why using a 0 as a prefix to a number is a bad
    idea; the number might just have padded zeros. Let’s look at the prefix
    used for hexadecimal: `0x’. This is great:

    1. It starts with a numeric character, which means that it must be a
      literal. If it started with an alphabetic character, it might be a
      variable name.
    2. The second character is a alphabetic character that is not used in
      any number system that is used in computer science. This allows it
      to serve a a unique identifier.

    Given these reasons, let’s think of a new prefix for octal… how about
    `0o’. That took literally less than 10 seconds for me to realize why `0′
    sucked, and to think of a better one.*

All-in-all, its still better than C++

* although, writing this gave me an even
better idea, but it would break `0x<value>’ for hex, which is incredibly
common among many languages:
`<base-in-decimal>x<value>’
so octal would be `8x<value>’
and hex would be `16x<value>’
It would be incredibly understandable, and, depending on implementation allow
simple arbitrary-base literals.

Posted in Computers | Leave a comment

FUSE is crazy

Well, I suppose just I’m only talking about Linux FUSE, I haven’t fiddled with FUSE on any other kernel. Anyway, FUSE screws with the idea of the root user:

$ ls
Makefile
build.log
...
$ sudo ls
ls: cannot open directory .: Permission denied
$ 

For those who don’t get it, the user with user ID `0′, usually with the username `root’ is the supreme administrator account — it is locked out of nothing, the kernel doesn’t even check file permissions when the user is root. The sudo (switch user do) command runs the following command as root. Anyway, even though the kernel doesn’t check file permissions when the user is root, FUSE does, in fact, it forces a umask of 0077, which means that even if the file permissions say “anyone logged in can read this file”, only the owner of the file can actually read it. I’m sure that this can be configured, but that doesn’t mean that it’s not brain damaged by default.

Posted in Computers | Leave a comment

Suicide as an Act of Optimism

If you have been personally touched by suicide, please don’t be offended, I do not entirely agree with the sentiment of this essay. The prompt here was “Write about suicide as an act of desperation.”. We had just listened to a lecture about how most student’s essays end up being the same for the same prompt; any unique or different essay will score better. Additionally, you can’t lead me that much in the prompt. Sure I agree that suicide is a bad thing, but we can’t treat that as a given.
~ Luke Shumaker

You are not a beautiful, unique snowflake of specialness. You are made of the same decaying, organic matter as everything else. Accept that you are going to die and let go. It is the only way to find freedom. The only way to live life to the fullest is to accept, and embrace, that life does not matter. Suicide can be an act of optimism.

You are going to die. Everyone you have ever loved or cared for is going to die. Everyone you have ever met is going to die. If you’re having trouble wrapping your mind around this, perhaps a religious interpretation may help; God’s ultimate plan for you: to die. Everything you create will fall apart and be forgotten. Nothing you will ever do will matter. Losing all hope; this is nihilism.

To commit suicide is therefore to accept our place in the universe, and embrace our fate. To embrace “God’s will” for us, to fulfill our divine mission, surely is a noble act, a positive act of optimism. We don’t have to do anything; we fulfill our mission by being born, living for a while, then dying.

When we accept this, accept our mortality, and the futility of life, a massive burden is lifted. When we accept that our mission in life is to die, we no longer must worry about fulfilling it; we will. We no longer have an obligation to be significant, to make a difference. We become free. Losing all hope, and finding freedom; this is existentialism.

Plato wrote that Socrates had taught of “reluctant leadership.” That the “enlightened” must return from their “enhanced world,” to lead those who had not attained enlightenment; they were obligated to, though they would not want to. He believed that philosophers should govern society. Perhaps you remember Plato’s allegory of the Cave? In it, the individual who found his way outside of the cave, and saw the true world had to return to the cave to watch over those who did not realize that there was a world beyond the cave. I can’t be the only one who found this horribly depressing. You attain enlightenment, and are rewarded by being forced to return and govern idiots who think you a fool for believing in a world beyond the cave. I don’t want to hack an awesome piece of software, then spend my days running its mailing list.

To find freedom, we must give up all that matters to us; for it does not matter. We must come to what are possibly the most painful realizations a person can have. We must give up the life we know, the life that matters. We must accept that we are going to die, and stop caring. Then we can enjoy what we have, the way we want to. The phrase “live and let live” is a good start, but how about “live and let be?” Why must the other person in the phrase live? The phrase embodies allowing others to make their own choices, regardless of what you think, so shouldn’t they get the choice to not live a life? In order for us to find our freedom, and them to find their freedom, we must accept that life does not matter. We don’t all have to kill ourselves, but accept that life does not matter.

Posted in Essays, School | Leave a comment

Who am I?

I am the nerd, the geek, the hacker. In most aspects, I am the stereotypical nerd. I wear glasses, a belt, a button down shirt, and a pocket protector. I play Dungeons and Dragons. I’m smart and have a passion for computers. I keep mostly to myself. However, in contrast to the stereotypical nerd, people like me. While I would expect myself to have some friends, the acceptance I have among my peers is something that continually surprises me. This is not something that has always been true, but has been for most of high school. The most logical reasons for this seems to be the emotional maturity of high-schoolers, combined with the publics’ increasing acceptance of nerds. Still, it feels like I’m doing something wrong as a nerd, and that I’ve betrayed my people.

The quality of my relationships with other people seem to vary inversely with quantity. For much of my life I have had a small inner circle of friends that I was very close to. As I branched out, the I have drifted from the friends I was once extremely close to. That is not to say that I am not still close to them, but that we are not as close as we once were. Since I mostly keep to myself, most of my friendships seem to form by others seeking to be friends with me. For this reason it is not infrequent that I am not sure whether I am currently friends with someone who I once was.


I am mildly insane. Somehow that became my concession. In Poe’s Tell-Tale Heart the character desperately insists that he is sane. I gave up on that plea long ago, now it’s, “don’t worry guys, I’m only slightly insane.” It’s okay though, I’m sane enough to function, but insane enough that it’s interesting. To delve into precisely in which way I am insane is neither something that would fit in this document, nor something I am entirely comfortable sharing.


I am a hacker. I think. I used to tell people that I was aligned with the hacker ethic, and followed the practices of hackers, but that I felt the term denoted s level of proficiency that I had not reached. I’m not sure I’ve progressed significantly since then, but I now feel comfortable telling people that I am a hacker.

I should probably clarify what “hacker” means. A hacker is someone who enjoys hacking, and subscribes to the hacker ethic. Now I must define “hack,” which is an incredibly hard word to define. To quote hacker Phil Agre, “The word hack doesn’t really have 69 different meanings. In fact, hack has only one meaning, an extremely subtle and profound one which defies articulation. Which connotation is implied by a given use of the word depends in similarly profound ways on the context.” I would say that most accurately, but least helpfully, hacking means “creative problem solving.” Hacker esr characterizes hacking as “an appropriate application of ingenuity.” Some hackers do apply this to breaking computer security, many, many more do not. I should also note that when hackers do break security, it is not with malicious intent, to do that would be a violation of the hacker ethic. Hacking normally applies to computer programming, but it can be applied to anything.

When I inform some people that hacking does not mean security breaking, as the mainstream media has them think, they act like I am nitpicking at a definition, or being stubborn. Let me assure you that when I hear hacker used in such a way, I am confused for a moment before I realize that many people use the term to mean security breaker.


I am lazy, but smart. Perhaps I am using a slightly different meaning of “lazy” than is normal, it is not that I avoid work, but tend to do other work instead, or avoid unnecessary work. It is commonly said that laziness is a sign of a good programmer; he will put thought into the design of his code to avoid more work later. When I don’t do a school assignment, it isn’t because I idly wasted my time; I was probably up until the wee hours of the morn working, but on hacking instead of another exercise that I don’t perceive to benefit me (other than the grade). Perhaps rather than lazy, this could be described as having bad priorities. This is probably true, and the reason I haven’t changed is that I still get away with it. I’ve gotten reasonable grades in classes by getting a “0” on homework, then setting the curve on the test. This isn’t the usual situation, though, I can usually get the work completed in a few minutes before class.

This brings me to my attitudes towards school. I enjoy learning, but I don’t care about grades. I know that they will help me out later; I know I’ll wish I did care when I’m applying to colleges; but they don’t matter to me. I come to school to learn, not to play some game with grades. Once I learn a topic I am not likely to spend more time on it doing 150 more practice problems, when I could be hacking, teaching myself, reading, researching, or teaching someone else.


I’m informed that many of these attributes are not atypical of people of my intelligence and passion for learning. However, I do not believe I have met anyone (in my age group, at least) that remotely fit this description.

Posted in Essays, School | Leave a comment

ICB Journals

A while back I had to do a bunch of journals on the book In Cold Blood.
I have decided to post several of these journals, they are very incoherent.
Each journal had a passage associated with it, which have not been reproduced here.

#3, Page 20 – The Last to See Them Alive

Perhaps this is a bit of a tangent, but this passage makes me wonder “What makes someone become a life insurance agent?” It must be the most depressing job ever, next to working in a cemetery/crematorium/funeral home. Even if one can claim ignorance of that fact when entering the field, what makes someone want do do that? Are there high-school students who want to sell insurance when they grow up?

#7, Page 65 – Persons Unknown

I tried to read her story, however, she kept using the phrase “hot as Hades,” and I couldn’t take her seriously (does this make me an awful person?). I find the phrase “hot as Hades” to be humerus; a hot hell is a distinctly Christian concept, the Greek Hades was cold, icy. This certainly fits much of the imagery of death, the “cold grip of death,” bodies get cold when they die, and you get the chills when one is scared (exposed to death). It appears that my mind is wandering, I’m going to attribute this to lack of hacking. Relatedly, I should probably finish the book Hackers, (I have to write a review of it, as I got a free “review copy”) I’ll do that as soon as I finish this book.

#15, Page 147-148 – The Corner

It’s funny how the events we build up in our heads end up not being fulfilling as we imagine them to be. Whatever this journal was going to be just got derailed by my recollection of a paper I once read. The paper essentially stated that individuals with depression are the sane people, and that we are all the ones with the disorder. It asserted that we have a condition that causes us to over-estimate how future events will affect us, both good events and bad. Individuals with depression actually function properly, but without the unfounded optimism fount in the rest of us, they fail to be motivated or feel good. If this is correct, it means that the world just sucks. It would seem here that Dewey indeed does not have depression, for he is subject to our condition of falsely inflating gratifying events.

Posted in Essays, School | Tagged | Leave a comment