About jontas

I like to make things that people find useful.

Linux: Converting a file encoded in ISO-8859-1 to UTF-8

If you have a file that is saves as ISO-8859-1 (or ISO-LATIN-1 if you like to call it that) and wish to convert it to UTF-8 you can use:

 iconv --from-code=ISO-8859-1 --to-code=UTF-8 ./oldfile.htm > ./newfile.html

This will create a new file with the converted encoding.

iconv can of of course convert to and from several other charsets. To see a list of all the encodings that iconv can work with use:

 iconv -l

If you wish to massconvert files find can be used with exec

 find . -name "*.txt" -exec iconv -f ISO-8859-1 -t UTF-8 {} -o {}.utf8 \;

apt-get update The following packages have been kept back

 apt-get upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
The following packages have been kept back:
  bind9-host dnsutils libbind9-50 libdns50 libisc50 libisccc50 libisccfg50 liblwres50 linux-generic linux-generic-pae linux-image-generic
  linux-image-generic-pae
0 upgraded, 0 newly installed, 0 to remove and 12 not upgraded.

The message has been kept back most often means that the upgrade was kept back due to dependencies that are not met.

Some possible solutions

  • A simple way is to invoke dselect to help out with the update. dselect performs the actions necessary to realize that state (for instance, the removal of old and the installation of new packages).
     apt-get dselect-upgrade
  • While apt-get and aptitude are basically the same, aptitude is sometimes better at handling dependencies than apt-get
     aptitude upgrade
  • Another solution is to install the package using apt-get install to install the upgraded package and let apt-get install the missing dependencies
     apt-get install dnsutils

svn: Checksum mismatch for file expected: md5, actual: othermd5

What has (most likely) happened is that the .svn/entries file has gotten corrupt somehow; this can happen if a svn client dies halfway in a commit, or for other reasons, but that is not what this post is about.

Recently got the error message “svn: Checksum mismatch for ‘/var/www/magento/app/locale/sv_SE/template/email/sales/.svn/text-base/testfile.svn-base’; expected: ‘2b991059e896f837f33875df8070e1ab’, actual: ’71d7d03cf41d65b6c28471dd2e96c2e1′”

A quick fix this issue is to

  • Remove the .svn directory from the sales folder.
  • Move the folder sales to sales_real
  • Update the email folder (this will recreate the sales folder)
  • Move all the files from sales_real to sales
  • Commit sales
  • Delete sales_real

Obligatory disclaimer: This worked for me, it keeps the file history and all should be well.
If the sales folder would have been larger (and or my connection to the svn server slower) perhaps some other solution is preferred; but this was quick and worked.

Credit to dr. chuck for the original post

How to read the pingbars in Modern Warfare 2

By default the maximum amount of bars are 4, and each of the bars represent 100ms (latency to the host and back)
So all 4 bars means that you have 0-100 ms, 3 bars 101-200, 2 bars 201-300 and just one bar 301 (and up).

The important thing to note is that the ping is measured to the host (the person hosting the multilayer game); so if only one person has a good ping and the rest don’t, then the person with the good ping is the host.

If you wish to get a more detailed view of the ping, then it is possible to change the numbers of bars and the time each bar represents.
Edit the file (default location, if you have installed steam somewhere else, change accordingly) C:\Program files\Valve\Steam\steamapps\common\Call of duty Modern Warfare 2\players > config_mp.cfg
For now two lines are interesting, and to note is that “//” means that a comment starts, so nothing after that on a line is used by the game. I recommend that comments are used to be able to find the lines faster if you wish to tweak later on, also storing the default value is imho a good idea.

//Each bar represents this many ms ping (default is 100)
seta cg_ScoresPing_Interval "50"
//How many ping bars to show 1-10 (default is 4)
seta cg_ScoresPing_MaxBars "6"

I use 50 and 6 since I think that is sufficient and easy to count. Some others suggest for instance 20-25 ms and 10 bars, test what feels right for you.

Doing these modifications to the config shouldn’t ban you from steam, but be careful when editing the config.
Each command should be on a separate line, if it isn’t when you open the file: Close it and use another editor (for instance word pad).

This is somewhat based on a post in the iw forum

Quickly configure shorewall on Debian

By definition shorewall is not a firewall, it is a way to (more) easily configure iptables to work as a firewall.

  • First install shorewall “$ apt-get intall shorewall”
  • Enter /etc/shorewall
  • Copy the example files from /usr/share/doc/shorewall-common/default-config/ (might also be located in /usr/share/doc/shorewall/default-config/) “$ cp /usr/share/doc/shorewall-common/default-config/* .”
  • Edit the files and enter the data that your system has
    • First create zones “$ nano zones”
       #ZONE   TYPE            OPTIONS         IN OPTIONS                OUT OPTIONS
      fw      firewall
      net     ipv4
      vpn     ipv4
    • Connect zones with interfaces”$ nano interfaces”
       #ZONE   INTERFACE       BROADCAST       OPTIONS
      net     eth0            detect          tcpflags,blacklist,dhcp
      vpn	tun0		-
    • Create policies “$ nano policy”
       #SOURCE         DEST            POLICY          LOG LEVEL       LIMIT:BURST
      fw              net             ACCEPT
      vpn             net             ACCEPT
      vpn             fw              ACCEPT
      fw              vpn             ACCEPT
      net             all             DROP            info
      all             all             DROP            info
    • Create rules “$ nano rules”
       #ACTION SOURCE          DEST            PROTO   DEST    SOURCE          ORIGINAL        RATE            USER/
      #                                               PORT(S) PORT(S)         DEST            LIMIT           GROUP
      ACCEPT          net             fw             tcp     22 # ssh
      ACCEPT          net             fw             tcp     80 # web
    • Verify that the rules are fine “$ shorewall check”
    • Edit /etc/default/shorewall and set startup to 1
       # prevent startup with default configuration
      # set the following varible to 1 in order to allow Shorewall to start
       
      startup=1
    • Start the firewall “$ /etc/init.d/shorewall start”

If you later decide to update rules, zones etc run “$ /etc/init.d/shorewall restart” to load the changes.

Linux: Turning off window scaling

A fairly common issue on the Internet is that some routers can’t handle window scaling.
This will might give some odd messages to email servers (such as not being able to send mails over a certain size to one receiving mail server)

On option is to turn off window scaling by editing sysctl.conf and adding the following lines

# Uncomment to turn off window scaling (most usefull for linux MTA)
net.ipv4.tcp_window_scaling = 0

A warning about doing this; In the long run throughput will not be optimal on this server, but sending mails should work better (so best used on a dedicated mail server).

Magento: Adding piwik tracking

Using piwik to track Magento visitors is a easy thing to do.

In Magento Connect there is a plugin to install

See my earlier post if you don’t wish to turn your site to alpha on all packages.

For the settings, most are self explaining, the token can be found in piwik under API and is labeled API key, please read the warnings about using it and consider if you will need it.

Magento: Failed to download package X within preferred state “stable”, latest release is version 0.4, stability “alpha” (or “beta”), use “channel://…

If you do not wish to move your entire server to use alpha mode (or beta) but keep the mainline in stable, but still wish to install the actual package; you just
enter the information from channel and on and the plug in will install.

$:/var/www/magento$ ./pear install magento-community/Florent_Piwik
Failed to download magento-community/Florent_Piwik within preferred state "stable", latest release is version 0.4, stability "alpha", use "channel://connect.magentocommerce.com/community/Florent_Piwik-0.4" to install
install failed
$/var/www/magento$ ./pear install channel://connect.magentocommerce.com/community/Florent_Piwik-0.4
downloading Florent_Piwik-0.4.tgz ...
Starting to download Florent_Piwik-0.4.tgz (4,163 bytes)
.....done: 4,163 bytes
install ok: channel://connect.magentocommerce.com/community/Florent_Piwik-0.4

Magento: Starting SOAP (adding a user)

In order to get SOAP up and running you will need to add a web services user in the admin panel.

    First add a role for the user. (Roles are used to limit the permissions of the user)

    • System->Web Services->Roles->Add new role
    • Give the role a name
    • Set permissions for the role
  • Then create the user with these permissions
    • System->Web Services->Users->Add new user
    • Add information about the user (the API key is the password used for SOAP)
    • Under roles bind the user with the previously created role