вторник, 20 октомври 2015 г.

How to restore ark submenu in dolphin

After the upgrade to plasma5, it turned out I lost all my submenu functionalities in Dolphin, like my favorite ark submenu "extract here". Restoring them, however, was quite easy.
Just copy the content of "/usr/share/kde4/services/ServiceMenus/" to "/usr/share/kservices5/ServiceMenus/" with
$sudo cp /usr/share/kde4/services/ServiceMenus/*.* usr/share/kservices5/ServiceMenus/
Problem solved :) 

сряда, 14 октомври 2015 г.

How to clear cache without reboot

Today I noticed that something is eating my RAM like crazy. After I checked with
$watch -n 3 cat /proc/meminfo
it turned out something is caching huge memory for no good reason. So this is what I did (source):
$sudo sh -c "sync; echo 3 > /proc/sys/vm/drop_caches"
and it immediately released like 7GB of RAM. Which is quite a lot. And nothing has crashed so far.
Obviously (from here) you can also do is only partially:
$sudo sh -c "sync; echo 1 > /proc/sys/vm/drop_caches"
$sudo sh -c "sync; echo 2 > /proc/sys/vm/drop_caches"
I haven't yet tried them, because it seemed I need to drop everything.
A side thing - I just discovered (well, by googling it) that if you type shift +E while in top, you can change the units from KB to GB. Which is much easier to read. Yay!

четвъртък, 30 юли 2015 г.

How to clean up tmpfs without rebooting

The problem: my /tmp is always full.
I manually deleted stuff from it (it's generally safe) and also from /var/tmp (which might not be that safe) but this didn't help. It turned out the problem is that systemd mounts /tmp into the RAM trough tmpfs (or at least I understand it so, I might be wrong). So even though /tmp as a directory is empty, it's still full somewhere on the RAM. Which creates problems, because even though I have plenty of RAM, the system thinks your tmpfs is full, because its size is the one written in /etc/fstab
.
One thing to do is to change the memory limit to a higher number, but this makes sense only if you know how to reset the tmpfs. Well, it turned out there is a way.
Zero step: check with:
$df
that the problem is indeed in /tmp and not that your disk is simply full. 

Then, first before deleting anything, check that there's nothing important in your running apps that needs it. You can do:
$lsof /tmp
$fuser -m /tmp
To see what is currently using the /tmp directory. I guess it's a good idea to stop those processes before proceeding.
In mode details:
jane@linux $ fuser -m /tmp 
/tmp:                 2229  2258  3869c  6464 13163m 21380
jane@linux $ ps auxw|grep 21380
jane  7241  0.0  0.0  92088  2448 pts/1    S+   16:31   0:00 grep --colour=auto 21380
jane  8456  1.5  2.0 1856540 341412 ?      Sl  Jul28  46:02 /usr/lib64/firefox/plugin-container /usr/lib64/nsbrowser/plugins/libflashplayer.so -greomni /usr/lib64/firefox/omni.ja -appomni /usr/lib64/firefox/browser/omni.ja -appdir /usr/lib64/firefox/browser 21380 plugin
jane 21380 12.9 23.8 5670228 3889432 ?     Rl   Jul28 395:20 /usr/bin/firefox
Then you kill whatever is on your way.
Afterwards, you need to become
$su
And then 
$umount -l /tmp/
$mount  /tmp/
And ideally, you're a happy person. This should work safely, but still, it's a good idea to close or save anything important for you before umounting /tmp.
Btw, there is a way to turn off the mounting of the tmpfs to RAM by:
echo 'MINTMPKB=0' > /etc/default/mountoverflowtmp
but people are not recommending that and I didn't do it.

You can also mount /tmp with:
$mount -t tmpfs -o size=1048576,mode=1777 overflow /tmp
where the size should be whatever you like. Which probably is the better way to mount it, because automatically, it mount is with size=8156484, which probably is related to the amount of free RAM, but I'm not sure.
You can check your free RAM with:
$free -m -t

понеделник, 22 юни 2015 г.

Restart plasma-desktop without logging out

It turns out this is quite easy and works fine:
Alt+F2
killall plasma-desktop
Alt+F2
plasma-desktop & 
And that's it. It will take couple of seconds but it loads ok. Also, killing krunner and restarting it from Konsole doesn't seems to be a problem. For those of you, which see something like 4GB for plasma-desktop and 2GB for krunner. 
By the way, this seems to be the problem also with "kdesu firefox" not working (it returns a stub). 

четвъртък, 9 април 2015 г.

Cool uses of sed

I really fell in love with this site: sed - 20 examples to remove / delete characters from a file . 
To remove first character only if it is a specific character:
$ sed 's/^F//' file > file.new
Pretty cool when you need to deal with 10 000 incompatible ways to comment in Fortran.
Also, one Fortran note to self:
To fix deprecated assign to and go to:

(a) change each of the ASSIGN N TO NEXT (where N is some number) statement to a simple NEXT = N statement (where N is the same number), and

(b) replace each of the GO TO NEXT, (x, y, z, ...) statement with the following computed goto statement

GO TO (1,2,3,4,5,6,7,8,9,10,11) NEXT

сряда, 1 април 2015 г.

How to limit RAM usage of Fortran

Obviously, numerical computing is a BITCH! Recently, my system went havoc because of one integration taking more than 10GB RAM. In principle I have 16GB RAM but I had tons of stuff going on and I never expected the fortran code to take so much resources. Which was kind of naive from my side, but anyway.
So here is how you can limit the memory usage of your programs.
The easiest way is:
$ ulimit -v
unlimited
$ ulimit -v 100000
$ python -c '[ "x" * 100000000 ]'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
MemoryError
This is from here.
Also, you can mess with the stacksize this way.
        ulimit -S -s
      
For me, it gives "8192". To increase it:
        ulimit -S -s 16384
      
or:
        ulimit -s unlimited
      
I would recommend against this, however, unless the program explicitly complains against the stacksize. I remember doing this for Maple and it turned out a disaster. And in Maple at least, there is another way to increase the heap size which solves most memory related problems.
Anyway, this method is not very good, because it requires constant change of the ulimit.
Another more interesting option is the use of cgroups:
$gcreate -g memory:/myGroup
$ echo $(( 500 * 1024 * 1024 )) > /sys/fs/cgroup/memory/myGroup/memory.limit_in_bytes
$ echo $(( 5000 * 1024 * 1024 )) > /sys/fs/cgroup/memory/myGroup/memory.memsw.limit_in_bytes
cgexec -g memory:myGroup pdftoppm
/source site/
Note that in order to set the limits on the swap, you need to add
GRUB_CMDLINE_LINUX_DEFAULT="cgroup_enable=memory swapaccount=1"
to /etc/default/grub
 For a very detailed info on cgroups you can see here.
Also in the ArcWiki (cgroups) there is a great example how to limit the memory of matlab for example. But in my case, I think it's easier to just create a group and launch my program from within it.
We'll see about that.

вторник, 24 март 2015 г.

How to change XP language to English

Oh, well, don't ask why I had to do that.
But here is how. It works. More or less :)
How To Change Windows XP To Any Language 
Just follow the instructions.
Download SP3 in English
Change the language code in the registry to 0409
Reboot
Install SP3
And well, it has English. Partially. Some things are in English, other not. But most things are actually in English, which is good. Note, it also works if you already have SP3 installed.
I hate M$.

вторник, 10 март 2015 г.

How to remove gimp association with pdf in Firefox

Quite easily, actually. Note, my only problem was that the Download manager of Firefox opened pdf-s with GIMP, otherwise, pdf-preview work ok.
So edit:
sudo nano /usr/share/applications/mimeinfo.cache
find the line starting with:
application/pdf=
and make sure it becomes:
application/pdf=kde4-okularApplication_pdf.desktop;
Ctrl+o + enter and you're done
Of course, you can change Okular to whatever else you use to read pdfs. But I like okular.
You can check the shortcuts in /usr/share/applications to see what other pdf viewers you have.
Cheers.

петък, 6 март 2015 г.

How to remove remember the milk from panel

Seriously, I never believed I'll write that stupid post, but anyway.
So, I wanted to try Rember The Milk to manage to-do lists and so on.
I added it as a widget to my top panel and tested it for a while. Then I wanted to remove it.
And as unbelievable as it is, I couldn't. There was no Remove Icon/Widget in the context menu. That freaked me for a while, but in the end I managed to remove it. The only way to do it turned out to be:
 Unlock Panel -> Add a new row to panel-> Move the unwanted Icons on the new row and then Right click on Panel and choose Remove Panel.
And yeah!
Oh well. It's simple once you know it, but I actually googled removing remember the milk, then googled where KDE stores the panel data, then checked the files in question, then realized it's too complicated to edit them and came up with this solutions.
Btw, if a good app for to-do reminders is Firefox "Reminder Fox". It works, it doesn't require registration or cloud services and it's easy to uninstall. And it's ridiculously annoying. Which is the point, when you want to set up a reminder, right? :)
Cheers.

четвъртък, 26 февруари 2015 г.

How to remove trovi /windows 7/

A little M$ "fun" which I had to suffer to help a colleague.
The Trovi and Omiga monsters. It turned out it's a complete disaster to remove them.
First I installed SpyHunter with a patch (for obvious reasons). It scanned and cleaned out the registry, but the trovi remained in new tabs. Furthermore, the SpyHunter started killing the windows.
So, here's the deal:
0. Install SpyHunter and let it remove the malware and adware from the registry. If at this point everything is ok, just uninstall SpyHunter and go to step 7. Else, go to 1.
1. Start Windows in SafeMode with Network.
2. Try removing Trovi and Omiga from Add/Remove Programs (or whatever its name is in win 7)
3. Go to "http://support.microsoft.com/mats/Program_Install_and_Uninstall" and use the script to remove everything you want to remove.
4. Go to Program Files (or Program Files x86) and remove the folders of the programs you managed to uninstall.
For example, I wanted to remove SpyHunter.
So I uninstalled it with the script, then I removed its folder from Program Files x86.
Then :
5. Start->msconfig
6. Go trough the tabs and clean everything you find unwanted (google whatever you're not sure for)
Especially, go trough StartUp and Services.
Click Apply.
Restart.
You can find more on this here.
So ideally, with this we have successfully removed SpyHunter. 
Then, in the case of this computer, one could still see Trovi when hitting New Tab in Mozilla. To remove this: 7. Start->Command Prompt
8. cd C:\Users\XXX\AppData\Roaming\Mozilla\Firefox\Profiles\XXX.default (this is the profile folder you find by typing in start)
9. findstr /m /s /i trovi *.*
findstr turned out to be the only practical way to find the files which contain certain word, in our case "trovi"
So you get a list of the suspicious files.
10. Edit with Notepad replacing "trovi.com" with say "google.com"
- prefs.js
- search-metadata.json /here you can as well delete all the unwanted things, just keep in mind to match all the {}
11. Additionally, you might want to check all your Shortcuts to Firefox (Desktop, Start Menu etc) right-clicking and selecting Properties. There, in the "Target" and "Start In" fields, you might find some long string containing "trovi", "omiga" and other stuff. Just remove everything after .exe and close with a " (you need to have one " in the beginning and one " in the end of the field.
Click ok/apply and do it for all the shortcuts you see this long string leading to Trovi.
Ideally, this should get rid of the idiotic adware (or malware or spyware, don't know what it is).  Even more ideally, please use Linux, because your colleagues usually have better things to do than wasting days on helping you clean up your Windows.

понеделник, 23 февруари 2015 г.

A working tabs-restore plugin for gedit-3x

Yup, once you know what to look for, it's pretty obvious. I was quite desperate to find a plugin to save my tabs session and restore it on restarting gedit. I quickly found one, and tried to install it, but it never worked and I kept on getting all kind of odd errors (like "error loading python" or "error launching plugin"). Things are additionally worsened by not being able to see the tickmarks on the Plugins settings in Preference.
Anyway, it turned out the problem is that the pluging I was trying to install was for gedit-2. So I found this plugin to actually work *YAAAY*!
To install it, follow the steps on the page, i.e.
1. Download,
2. Copy the extracted files to ~/.local/share/gedit/plugins/ 
3. Copy and compile the settings schema as sudo/root: 
$sudo cp org.gnome.gedit.plugins.restoretabs.gschema.xml /usr/share/glib-2.0/schemas/
$sudo glib-compile-schemas /usr/share/glib-2.0/schemas/
4. Enable the plugin from Edit-Preferences-Plugins
Ok, there is a similar plugin which I didn't try, but you can find here.
Additionally, I found this useful list of actual gedit-3x plugins: Third party gedit plugins - versions 3.0 to 3.6 You might give it a try. 
Finally, if you ask the logical question why I'm using gedit when I'm actually under KDE, well, it has pretty cute IDE controls, it's ridiculously light and dumb that I wouldn't use it for anything but one particular project. Which doesn't apply fro kwrite for which I have in any moment like 5 opened windows. Of course, Kate has a pretty good session manager but then I couldn't find a proper way to use it as IDE, which decreases significantly its value. Anyway, now my Gedit has a tabs-restore! :)

събота, 10 януари 2015 г.

How to convert color eps to grayscale

That turned out more complicated that it seems. The default ways didn't seem to work for me, because the eps was produced by Maple (so there is a bitmap graphics inside).

Here is what it worked for my figure.eps:

$epstopdf figure.eps
$gs  -sOutputFile=output.pdf  -sDEVICE=pdfwrite  -sColorConversionStrategy=Gray  -dProcessColorModel=/DeviceGray  -dCompatibilityLevel=1.4  -dNOPAUSE  -dBATCH  figure.pdf
$ pdftops -eps output.pdf

This can be done easily to a script like this:

#!/bin/bash
epstopdf $@ -o output_eps.pdf
gs -sOutputFile=output.pdf -sDEVICE=pdfwrite -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray -dCompatibiltyLevel=1.4 -dNOPAUSE -dBATCH output_eps.pdf
pdftops -eps output.pdf

Save it as epstograyscale.sh
$sudo chmod +x  epstograyscale.sh
$sh epstograyscale.sh figure.eps

It worked on my PC.

вторник, 6 януари 2015 г.

Card reader stopped detecting my SD card

A little card reader fun before going to bed.
So we needed to format a 16GB SD card to ext4, it was formatted as fat32 (who the hell uses this format besides cameras?). So at first, my Sabayon wasn't detecting it at all. After starting gparted it appeared, but it couldn't be formatted to ext4 (gave couple of errors). Then we tried formatting it manually and we got:
$sudo mkfs.ext4 -n 'LUbuntu' -I /dev/sdb1
   mkfs.ext4: invalid inode size - /dev/sdb1
Another try to reformat it as fat32.
$sudo mkfs.vfat -n 'LUbuntu' -I /dev/sdb1
mkfs.fat 3.0.26 (2014-03-07)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
mkfs.vfat: unable to open /dev/sdb1: Device or resource busy
 $ sudo mkfs.vfat -n 'LUbuntu' -I /dev/sdb1
mkfs.fat 3.0.26 (2014-03-07)
mkfs.fat: warning - lowercase labels might not work properly with DOS or Windows
/dev/sdb1: No medium found
Then the card reader stopped detecting the card at all and it wasn't visible with $df or $fdisk -l.
I checked dmesg:
sudo dmesg|tail  
[238472.867688] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.867742] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.867825] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.867891] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.867965] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868054] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868131] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868207] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868277] FAT-fs (sdb1): Directory bread(block 8192) failed
[238615.530731] sdb: detected capacity change from 15803088896 to 0
After some googling it turned out that there is a solution. I did:
$sudo fsck.vfat -nVv /dev/sdb1
fsck.fat 3.0.26 (2014-03-07)
fsck.fat 3.0.26 (2014-03-07)
Logical sector size is zero.
which changed my dmesg to:
sudo dmesg|tail
[238472.867825] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.867891] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.867965] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868054] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868131] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868207] FAT-fs (sdb1): Directory bread(block 8192) failed
[238472.868277] FAT-fs (sdb1): Directory bread(block 8192) failed
[238615.530731] sdb: detected capacity change from 15803088896 to 0
[240604.657313] sd 7:0:0:0: [sdb] 30865408 512-byte logical blocks: (15.8 GB/14.7 GiB)
[240604.786064]  sdb: sdb1
YAY!
Then I started gparted and formatted it to ext4 without any problem.
It's great when things end well, right? :)
Now let's see this Banana Pi.