Linux Download / Upload Limiter

Posted in Uncategorized on April 17th, 2013 by OneOfOne

I recently ran into a bandwidth problem using Skype, and I found no easy way to limit it, trickled doesn’t work udp, and after some research I came across QoS / tc shaping.

I cooked 2 different scripts and here’s what I came with :
It works for me (TM)

#!/bin/sh
IF=wlan0
ULIMIT=25kbps
DLIMIT=40kbps
U32="tc filter add dev $IF protocol ip parent 1:0 prio 1 u32"
IP=xxx.xxx.xxx.xxx

case "$1" in
	stop)
		tc qdisc del dev $IF root
		tc qdisc del dev $IF ingress
		;;
	show)
		tc -s qdisc ls dev $IF
		;;
	*)
		tc qdisc add dev $IF root handle 1: htb default 30
		tc class add dev $IF parent 1: classid 1:1 htb rate $ULIMIT ceil $ULIMIT
		$U32 match ip dst $IP/32 flowid 1:1
		
		tc qdisc add dev $IF handle ffff: ingress
		tc filter add dev $IF parent ffff: protocol ip prio 10 u32 match \
		ip src $IP/32 police rate $DLIMIT burst 80kbit drop flowid :1
		
		tc -s qdisc ls dev $IF
		;;
esac

References :
0154 | script limit bandwidth UDP
[LARTC] Qos wiht HTB for ADSL/Home

Pasting in VIM from KDE’s clipboard

Posted in Linux Development on January 19th, 2011 by OneOfOne

For some reason I couldn’t find it anywhere, but the register for the KDE clipboard (ctrl-c / ctrl-v) is + not * .

To paste from the KDE clipboard in insert mode : CTRL-R +, in normal mode : “+p .

To map it to ctrl-v : :imap +, this way you can just press ctrl-v in insert mode to paste the system clipboard.

To paste from the system selection (mouse middle button) in insert mode : CTRL-R * or in normal mode “*p .

To paste from the VIM buffer in insert mode : CTRL-R “.

To set the system clipboard as the default clipboard for vim (for yy,dd,cc,p) : :set clipboard=unnamedplus .

Also make sure to check :registers .

Tags: , , , , , ,

Speeding Chromium start up

Posted in Linux Development on January 14th, 2011 by OneOfOne

If you have been using Chromium like me, you know it can get pretty slow on the first start up after a couple of months of usage.
It’s mainly because of all the SQLite 3.x databases it uses for history and other settings.
So here’s a simple script to defrag and reindex all the databases chromium uses.

1. Install SQLite3 :

# install sqlite3
emerge sqlite:3 #gentoo
aptitude install sqlite3 #ubuntu/debian based

2. Close Chromium.

3. Execute this in bash :

cd ~/.config/chromium/Default #where recent chromium store its settings

find -type f -exec file '{}' \; | perl -ne 'print "$1\n" if /(.*?): SQLite/' | while read fname; do 
    sqlite3 "${fname}" VACUUM; 
    sqlite3 "${fname}" REINDEX; 
done

VACUUM : The VACUUM command rebuilds the entire database.
REINDEX : The REINDEX command is used to delete and recreate indices from scratch.

4. Results (I ran this a couple of weeks ago so the result isn’t as good as it would be the first time. :

-rw-r--r-- 1 oneofone oneofone 37M Jan 14 17:27 History
-rw-r--r-- 1 oneofone oneofone 34M Jan 14 18:01 History
.................
-rw-r--r-- 1 oneofone oneofone 39K Nov 23 10:11 History Index 2010-08
-rw-r--r-- 1 oneofone oneofone 9.0K Jan 14 18:03 History Index 2010-08

-rw-r--r-- 1 oneofone oneofone 32M Jan  2 14:12 History Index 2010-09
-rw-r--r-- 1 oneofone oneofone 12M Jan 14 18:03 History Index 2010-09

-rw-r--r-- 1 oneofone oneofone 93M Jan 14 17:29 History Index 2010-10
-rw-r--r-- 1 oneofone oneofone 71M Jan 14 18:08 History Index 2010-10

-rw-r--r-- 1 oneofone oneofone 169M Jan 14 16:06 History Index 2010-11
-rw-r--r-- 1 oneofone oneofone 161M Jan 14 18:20 History Index 2010-11

-rw-r--r-- 1 oneofone oneofone 152M Jan 14 01:43 History Index 2010-12
-rw-r--r-- 1 oneofone oneofone 137M Jan 14 18:22 History Index 2010-12

-rw-r--r-- 1 oneofone oneofone 93M Jan 14 16:16 History Index 2011-01
-rw-r--r-- 1 oneofone oneofone 92M Jan 14 18:24 History Index 2011-01
.................
Tags: , , , , ,

Change CPUFreq governor on all CPUs

Posted in Linux Development on November 22nd, 2010 by OneOfOne

While I love KDE, I still prefer to use command line for almost everything.

A simple bash function to set/list all governors.

set-cpufreq() {
	if [ -z "$1" ]; then
		echo "Available : $(cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_available_governors)"
		find /sys/devices/system/cpu -name scaling_governor | while read f; do echo $f : $(cat $f); done
	else
		find /sys/devices/system/cpu -name scaling_governor | while read f; do echo $1 > $f; done
	fi
}
Tags: , ,

Workaround for Wine/World Of Warcraft Crashing on Linux 64bit systems with > 4gb of RAM.

Posted in Linux Development, World Of Warcraft on February 24th, 2010 by OneOfOne

I recently got a new computer with 8gb of RAM, and since then World Of Warcraft crashed very often with out of memory errors.
After banging my head for hours every time I crashed in dalaran or coming out of the arenas, I finally discovered setarch(8).

Usage: setarch  [options] [program [program arguments]]                                                               

Options:
 -h, --help               displays this help text
 -v, --verbose            says what options are being switched on
 -R, --addr-no-randomize  disables randomization of the virtual address space
 -F, --fdpic-funcptrs     makes function pointers point to descriptors       
 -Z, --mmap-page-zero     turns on MMAP_PAGE_ZERO                            
 -L, --addr-compat-layout changes the way virtual memory is allocated        
 -X, --read-implies-exec  turns on READ_IMPLIES_EXEC                         
 -B, --32bit              turns on ADDR_LIMIT_32BIT                          
 -I, --short-inode        turns on SHORT_INODE                               
 -S, --whole-seconds      turns on WHOLE_SECONDS                             
 -T, --sticky-timeouts    turns on STICKY_TIMEOUTS                           
 -3, --3gb                limits the used address space to a maximum of 3 GB 
     --4gb                ignored (for backward compatibility only)
setarch i386 -3 -L -B -R wine wow.exe -opengl

While it isn’t a perfect solution, it work’s for the most part.

Tags: , , ,

Using CMake + Mingw to Cross-Compile Windows Apps.

Posted in Linux Development on November 23rd, 2009 by OneOfOne

As promised, here’s the second part of the tutorial on how to use cmake to build Qt4/OpenSSL Apps for Windows using mingw on Linux.

Assumptions :

1. You already followed the tutorial on how to setup Qt4/OpenSSL using mingw.
2. You have cmake installed.
3. You have a working wine setup or a way to test the executables.

Part 0 : Setup Wine

You can ignore this if you will test on windows.

  1. Run winecfg, go to Drives, add drive and set the path to your win32 dev (we will use the letter G for this).
  2. Run wine regedit, go to HKEY_LOCAL_MACHINE -> System -> Session Manager -> Enviroment -> edit PATH and append G:\qt-win-opensource-src-4.5.3\;G:\openssl-0.9.8l to the end.

Part 1 : Custom CMake Rules

We need to create a custom cmake rules file, we will name it lin-mingw.cmake for now :

if(WIN32)
	#We haven't built Qt with debug support, so no point setting debug flags.
	set(CMAKE_BUILD_TYPE "Release")
	ADD_DEFINITIONS(${QT_DEFINITIONS})
	SET_PROPERTY(DIRECTORY APPEND PROPERTY COMPILE_DEFINITIONS_RELEASE QT_NO_DEBUG)

	#set the default pathes, should be changed to match your setup.
	set(WIN32_BASE /home/dev/win32/)
	set(QT_BASE ${WIN32_BASE}/qt-win-opensource-src-4.5.3)
	set(OSSL_BASE ${WIN32_BASE}/openssl-0.9.8l)
	set(APP_ICON_RC ${CMAKE_CURRENT_SOURCE_DIR}/win32_icon.rc)

	set(MINGW_PREFIX "i686-pc-mingw32-")

	# set "sane" default cxxflags for windows, the -mwindows so it wouldn't open a command dos window.
	set(CMAKE_CXX_FLAGS_RELEASE  "${CMAKE_CXX_FLAGS_RELEASE} -march=pentium4 -mtune=pentium4 -mwindows -O2")
	# we need -static-libgcc otherwise we'll link against libgcc_s_sjlj-1.dll.
	SET(CMAKE_SHARED_LIBRARY_LINK_CXX_FLAGS "-Wl,--no-undefined -static-libgcc -Wl,-O1 -Wl,--as-needed -Wl,--sort-common -s")

.............. etc etc ............

Download the file.
Read more »

Tags: , , , , , , , ,

Mingw + OpenSSL + Qt4 for Windows on Linux

Posted in Linux Development on November 17th, 2009 by OneOfOne

This is slightly outdated, will upload a new version with OpenSSL v1.0.0, also fixed the link to the mingw-openssl.sh script.
For the longest time I used Mingw + cmake on top of wine to cross compile my Qt4 apps for windows, then I was bored one day, tired of how slow it is to recompile qt4 on wine and decided to try to get it to work with a native gcc instead of the overhead with wine.
So here goes.

This was done on Gentoo Linux, please don’t ask me how to do it on other distros.

Assumptions :

1. You know your way around the linux shell and have portage privileges.
2. You’re not scared from compiling things by hand.
3. You already have Qt4 installed and it is the same version as the windows source we gonna build.
4. Your working path will be ~/win32.
5. You have a working wine setup.

Part 1 – Meet the Toolchain :

# Change 32 to 64 if you're trying to build for Win64, of course you'd need a 64bit Linux toolchain as well.
export cross=i686-pc-mingw32
emerge -av crossdev
# I decided to use the latest gcc version, however there's nothing stopping you from using 3.x.
# Start building the tool chain, go make some coffee, watch tv, or play a game until it's done.
crossdev --gcc 4.4.2 ${cross}
# Fix a bug in Qt4's corelib, also make sure to change 4.4.2 to whichever version of gcc you decided to use.
ln -s /usr/${cross}/usr/include/float.h /usr/lib/gcc/${cross}/4.4.2/include/g++-v4

*Important* due to the way the gentoo build works, you have to use -static-libgcc while compiling with mingw’s g++ to elemenate the dependacy on libgcc_s_sjlj-1.dll.

You don’t need root access anymore.
Read more »

Tags: , , , , , , , ,

Priest macros

Posted in World Of Warcraft on November 17th, 2009 by OneOfOne

As a priest for the longest time (recently switched mains to a deathknight), I had a lot of macros I used with grid (and clique), and a buddy was asking me about them and I decided to post them here.

Greater Heal / Flash Heal / etc. (pretty much any targetted spell) :

#showtooltip Greater Heal
/cast !Inner Focus
/cast [mod:alt,target=player][target=mouseover,exists][help] [target=targettarget,exists][target=player] Greater Heal

Macro explanation :
Read more »

Tags: , , , , , ,