Blog

Trust everyone

Added by Christoph Kappel 4 days ago

Dealing with SSL is a pain, dealing with self-signed certificates is something perfectly suited for hell. One of the easiest way is to add your own custom CA certificate to the list of user-supplied CAs. Just copy the .crt file to your Android (>=4.x) device, double tap on it and install it the Certificate Installer.

That works properly for most of the apps with the funny side effect of a warning that informs you about being monitored by a third party.

..but sometimes this isn't enough and/or your own invocation of eg DefaultHttpClient won't work.

Just add this little method into your code, call it when you are sure you want to trust all certificates and never complain if that completely breaks your SSL chain of trust.

 1 private void
 2 trustEveryone()
 3 {
 4   try
 5     { 
 6       HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier()
 7         {
 8           public boolean
 9           verify(String hostname, SSLSession session)
10           {
11             return true;
12           }
13         }
14       );
15 
16       SSLContext context = SSLContext.getInstance("TLS");
17 
18       context.init(null, new X509TrustManager[]
19         {
20           new X509TrustManager()
21             {
22               public void checkClientTrusted(X509Certificate[] chain,
23                 String authType) throws CertificateException {}
24               public void checkServerTrusted(X509Certificate[] chain,
25                 String authType) throws CertificateException {}
26               public X509Certificate[] getAcceptedIssuers()
27               {
28                 return new X509Certificate[0];
29               }
30             }
31         }, new SecureRandom());
32 
33       HttpsURLConnection.setDefaultSSLSocketFactory(context.getSocketFactory());
34     }
35   catch(Exception e)
36     {
37       e.printStackTrace();
38     }
39 }

You must not use 8-bit bytestrings

Added by Christoph Kappel over 1 year ago

One of my many python scripts suddenly presented me with following error:

sqlite3.ProgrammingError: You must not use 8-bit bytestrings unless you use a text_factory that can interpret 8-bit bytestrings (like text_factory = str). It is highly recommended that you instead just switch your application to Unicode strings.

After a hell of a search with many hints and possible solutions here is a one liner that fixes this issue for sure: Just set the text_factory property right after opening the connection:

conn = sqlite3.connect("../database.db" 
conn.text_factory = lambda x: unicode(x, "utf-8", "ignore")

Section, subsection, subsubsection?

Added by Christoph Kappel over 6 years ago

Someone might say, when you need more than tree levels you are screwed or should use another doc class, but sometimes it's really useful. To enable more than the three default levels just add the following to your preamble:

Numbers: on /offsetcounter{secnumdepth}{5} % Enable level 4-5
setcounter{tocdepth}{5}    % Include level 4-5 in TOC

This enables this hierarchy:

% Default levels
section{}       % Level 1
subsection{}    % Level 2
subsubsection{} % Level 3

% New levels
paragraph{}     % Level 4
subparagraph{}  % Level 5

Trouble with indentation

Added by Christoph Kappel over 6 years ago

irssi doesn't provide indentation stuff like weechat, but this can be archieved with a little perl trick: Just prepend the nickname with whitespaces or cut it after some letters.

This works fine until nickcolor.pl comes into play. First, I thought this is a bug in irssi and I tested various things and version. Then I asked google and to my surprise someone had the same issue

Based on that, the whole thing was easy to fix. Since nickcolor.pl overwrites the format I need to change exactly that:

 1 --- a/.irssi/scripts/nickcolor.pl    Sat Jan 08 21:47:43 2011 +0100
 2 +++ b/.irssi/scripts/nickcolor.pl    Sat Jan 22 16:13:19 2011 +0100
 3 @@ -93,7 +93,8 @@
 4    }
 5 
 6    $color = "0".$color if ($color < 10);
 7 -  $server->command('/^format pubmsg {pubmsgnick $2 {pubnick '.chr(3).$color.'$0}}$1');
 8 +  #$server->command('/^format pubmsg {pubmsgnick $2 {pubnick '.chr(3).$color.'$0}}$1');
 9 +  $server->command('/^format pubmsg {pubmsgnick $2 {pubnick '.chr(3).$color.'$[-11]0}}$1');
10  }
11 
12  sub sig_private {

irssi vs weechat (2 comment)

Added by Christoph Kappel over 6 years ago

There are two curses based IRC clients that compete with each other: irssi and weechat

Nowadays most of the guys I know use weechat and I am still a irssi guy. I thought they might use it for a good reason so time for me to give it a try. This whole thing is funny for me, because I usually witness when people try to use subtle and adapt it to their daily workflow and now I am forced to change my own.

First steps

After my first few minutes with weechat, it's somehow different and somehow similar to irssi. It almost felt like they made all scripts that I used in irssi before to builtins. Nickcolor is well included, also the trackbar and a reasonable chanact.

There were many defaults that really confused me, like the behaviour to toggle between the last window and the current one, when I press the window switch key again. This was really easy to turn off, just needed to read the settings thoroughly.

Customization

The docs of weechat are a bit odd and probably need rework, I was usually lost finding the information I needed. The open and very kind community and other weechat users made this still to a solvable task. Another thing that surprised me was, that weechat doesn't use themes files like irssi. Changing the colors can be done via /set which is quite easy during runtime.

Biased comparison

Here is a table of scripts/things I would like to have in my IRC client and if this is possible in both clients:

Script/thing irssi (0.8.15) weechat (0.3.3)
Draw a separator when I switch windows trackbar.pl builtin
Alternate colors of nicknames nickcolor.pl builtin
Activity bar of channels with names chanact builtin
Nickserv integration nickserv.pl None found, probably scriptable
Edit topics via sed topicsed.pl None found, probably scriptable
Search in buffer history builtin (/lastlog) grep.py
Readable /names list (e.g. in columns) builtin (/names) None found, probably scriptable (nicklist is no option)
Multiserver handling (e.g. join channel) builtin (e.g. /join -prefix #channel) builtin (probably scriptable)
Send \a on highlight to set urgency builtin (see Urgent on highlight) None found (probably scriptable1)
Hide status windows /window immortal off; /window close Impossible currently
Nick indentation via theme builtin

I moved back to irssi after two weeks, I don't have time to write all the scripts that I need. Killing argument for me was the names list and the lack of a way to send \a on highlight1.

1 My first attempts caused a freeze of weechat once in a while.

Urgent on highlight

Added by Christoph Kappel over 6 years ago

I seldom have my irssi urxvt not on a current view, but whenever this happens, a notice about any highlight would be welcome. This can be done with only a few steps:

  1. Launch the irssi urxvt with −urgentOnBell
  2. In case screen is used enable audible bells with ^A^G
  3. Set following values in irssi:
    Numbers: on /off/set beep_when_window_active ON
    /set beep_when_away ON
    /set beep_msg_level MSGS NOTICES DCC DCCMSGS HILIGHT
    /set bell_beeps ON

This basically tells irssi to send a (alarm) on highlights. Then on such an alarm, urxvt sets the urgency hint and the window manager, if it supports urgency at all, will try to inform you about that.

Adding a compose key (1 comment)

Added by Christoph Kappel over 6 years ago

Sometimes it's useful to be able to type accented characters, especially when you use the nodeadkeys option, which effectively removes any way to type them. Known from the old days, there is the compose key. It advises xorg, that the next two keys pressed after the compose key belong together.

Examples:

compose + " + a => ä
compose + ` + e => è
compose + , + c => ç
compose + o + c => ©

There are two ways to enable it when input hot-plugging is disabled:

1) Enable it per user session e.g. in $HOME/.xinitrc

setxkbmap -option compose:caps

2) Put it into xorg.conf to enable it globally:

Section "InputDevice" 
  Option  "XkbOptions"  "compose:caps" 
EndSection

This basically turn your caps lock key into a compose key. Here is a list of the things you can compose: http://www.hermit.org/Linux/ComposeKeys.html

Gem on debian moved permanently (1 comment)

Added by Christoph Kappel about 7 years ago

Debian seems to have big problems with gem and the different versions, you will notice when you see this:

1 > gem list --remote
2 
3 *** REMOTE GEMS ***
4 
5 ERROR: While executing gem ... (Gem::RemoteFetcher::FetchError)
6 bad response Moved Permanently 301 (http://gems.rubyforge.org/latest_specs.4.8)

Apparently there is an easy fix, just update the sources of gem:

 1 > gem sources
 2 *** CURRENT SOURCES ***
 3 
 4 http://gems.rubyforge.org/
 5 
 6 > gem sources -r http://gems.rubyforge.org/
 7 http://gems.rubyforge.org/ removed from sources
 8 
 9 > gem sources -a http://production.s3.rubygems.org/
10 http://production.s3.rubygems.org/ added to sources

Unknown encoding in ruby 1.9.1-p429 (4 comment)

Added by Christoph Kappel about 7 years ago

Updating Ruby is usually a task that breaks many things, therefore I avoid it if possible. Being archuser, the maintainer of the Ruby decides when I need to face new problems.

This time they just added filesystem encoding stuff in p429:

Error loading gem paths on load path in gem_prelude
unknown encoding name - filesystem
<internal:gem_prelude>:69:in `find'
<internal:gem_prelude>:69:in `set_home'
<internal:gem_prelude>:38:in `dir'
<internal:gem_prelude>:76:in `set_paths'
<internal:gem_prelude>:47:in `path'
<internal:gem_prelude>:286:in `push_all_highest_version_gems_on_load_path'
<internal:gem_prelude>:355:in `<compiled>'

There exists still now sane way to init the gem path of Ruby so we can start with our hack from Setup gems load path in embedded ruby and add the required encoding stuff. This problem is known in the ruby redmine and the changesets to this issue give at least some hints what need to be done:

Numbers: on /off 1 #include <ruby/encoding.h>
 2 
 3 VALUE encoding = Qnil;
 4 
 5 void Init_prelude(void);
 6 
 7 RUBY_INIT_STACK;
 8 ruby_init();
 9 ruby_init_loadpath();
10 ruby_script("subtle");
11 
12 /* Get encoding from file system */
13 encoding = rb_enc_from_encoding(rb_filesystem_encoding());
14 
15 /* Set internal and external encoding */
16 rb_enc_set_default_internal(encoding);
17 rb_enc_set_default_external(encoding);
18 
19 /* FIXME: Fake ruby_init_gems(Qtrue) */
20 rb_define_module("Gem");
21 Init_prelude();

Logitech Wave (3 comment)

Added by Christoph Kappel about 7 years ago

I finally made a decision and chose the Logitech Wave after reading about it with all the pros and cons. Yesterday it arrived and I am really satisfied with the layout and especially with the wave design, it really makes typing a bit more pleasent. Overall it's not as heavy as it looks and it's well manufactured.

The mini usb receiver is a bit bigger than something I would call mini and to connect mouse and keyboard you need to press the connect keys manually. After that both work properly.

Wave and linux

On the linux console no problems at all, but under xorg many keys didn't work like expected and I am not speaking of the multimedia keys. This is probably a fault of my xmodmap though. Generally almost all of the multimedia keys have keycodes that aren't in the range of the supported keycodes(0-255) of the kbd driver. After some goodling I found the suggestion to use the evdev driver for this, here is my config for mouse and keyboard:


Section "InputDevice" 
  Identifier  "Mouse1" 
  Driver      "evdev" 
  Option      "Device"            "/dev/input/by-path/pci-0000:00:04.0-usb-0:9:1.1-event-mouse" 
  Option      "ZAxisMapping"      "4 5" 
EndSection

Section "InputDevice" 
Identifier  "Keyboard0" 
 Driver  "evdev" 
 Option  "Device"      "/dev/input/by-path/pci-0000:00:04.0-usb-0:9:1.0-event-kbd" 
 Option  "XkbModel"    "evdev" 
 Option  "XkbLayout"   "de" 
 Option  "XkbVariant"  "nodeadkeys" 
 Option  "XkbOptions"  "ctrl:nocaps" 
 Option  "evBits"      "+1" 
 Option  "keyBits"     "~1-255 ~352-511" 
 Option  "Pass"        "3" 
EndSection

The devices need to be adjusted for your config, by-path is a bit more pleasent than just relying e.g. on event0. This can avoid trouble when you switch usb ports.

Multimedia keys

There are many multimedia keys on the keyboard, some of them work and some of them don't. Currently I am only using the keys to control mpd.

Here is my Xmodmap for this:


keycode 121 = XF86AudioMute
keycode 122 = XF86AudioLowerVolume
keycode 123 = XF86AudioRaiseVolume
keycode 165 = XF86AudioPrev
keycode 171 = XF86AudioNext
keycode 172 = XF86AudioPlay
keycode 174 = XF86AudioStop

You can use the keynames than in your config, like I don in my subtle:

1 grab "XF86AudioMute", "amixer set Master toggle" 
2 grab "XF86AudioRaiseVolume", "amixer set Master 2dB+" 
3 grab "XF86AudioLowerVolume", "amixer set Master 2dB-" 
4 grab "XF86AudioPlay", "mpc toggle" 
5 grab "XF86AudioStop", "mpc stop" 
6 grab "XF86AudioPrev", "mpc prev" 
7 grab "XF86AudioNext", "mpc next" 

1 2 Next »

Also available in: Atom RSS