Saturday, December 14, 2019

How to use the nvidia gpu on-demand on ubuntu 19.10 for optimus laptops (a short reminder for myself)

I am currently on Ubuntu 19.10. I used 'prime-select' to select the 'on-demand' option thus:

$ sudo prime-select on-demand

Then rebooted. Now, all programs seem to use the default Intel graphics. To use steam and other programs with nvidia, I run then thus:

$ __NV_PRIME_RENDER_OFFLOAD=1 __GLX_VENDOR_LIBRARY_NAME=nvidia steam

And then from steam, I can see from my system information that the nvidia gpu is indeed being shown, which is not true (and shows the intel card) without the above options.


Monday, August 4, 2014

Using xdg-mime to set default programs to open certain filetypes in Linux

Recently I had a need to set xpdf as the default program for opening pdf files instead of evince. I decided to use the command line to achieve this. Turns out that I can do this using xdg-mime.

To know what is the filetype (in the mime 'language') of pdf files:

 $ xdg-mime query filetype Programming.pdf  
 application/pdf  

Once I know the mime type of pdf files, I can see the default program currently used to open pdf files:

 $ xdg-mime query default application/pdf  
 evince.desktop  

So, now I know that evince is being used as the default pdf file opener, and that there is a desktop file by the name of evince.desktop. The location of this file can easily be found using programs like 'locate':

 $ locate /evince.desktop   
 /usr/share/applications/evince.desktop  

Now I know where such desktop files are kept on my system. After installing xpdf, xpdf.desktop also turned up there (if not it is easy to create such a desktop file). So now I can make xpdf as the default program for opening pdf files using the following:

 $ xdg-mime default xpdf.desktop application/pdf   

That's it. Now if I try to click on a pdf file, xpdf is used to open it.


Thursday, July 31, 2014

Making git know about my http and https proxy server

Following is the general syntax of the commands that will set the http and https proxy servers for git:

 git config --global http.proxy http://proxyuser:proxypassword@proxyserver:proxyport  
 git config --global https.proxy http://proxyuser:proxypassword@proxyserver:proxyport  

For example, if I want to set the http and https proxy servers to 192.168.10.10:3128, then I would use the following command (assuming my proxy server requires no authentication):

 git config --global http.proxy http://192.168.10.10:3128
 git config --global https.proxy http://192.168.10.10:3128


Sunday, June 15, 2014

Go away Desktop icons... again!

I want my desktop to be clean. That means no icons. Recently I have been trying various window managers, and finally I settled down to i3 for the past few weeks. I love it.

Today, I just wanted to log into Unity just for change, and found things have changed since I last logged into it. That's strange since I never did this and nobody is using my PC. I was seeing desktop icons!

I wanted to get rid of those. So I used gsettings to find out 'who' was responsible for this. It turned out to be some program called nemo. The following command:

 ➜ ~ gsettings list-recursively | grep -i desktop | less  

turned up, among other things, this:

 org.nemo.preferences desktop-is-home-dir true  

So, to set things right, I had to do this:

 ➜ ~ gsettings set org.nemo.desktop show-desktop-icons false  

Now, things are right again.

Now that I think about this, I did play with Cinnamon recently, didn't quite like it, and then forgot all about it. Maybe, this was a result of that adventure... nemo being a part of Cinnamon...

(Oh, in case anyone was wondering, those command prompts are due to oh-my-zsh that I am using nowadays)

Wednesday, June 4, 2014

Getting audio volume go beyond 100% in Ubuntu Gnome

In some videos I find the audio volume to be too low, even after the I turn the volume up to 100%. However, from gnome's sound control, I can see that I can use the mouse to make the volume go beyond 100% so that the audio becomes louder.

So, I was looking for a command line that would do that for me, so that I can assign that to a keyboard shortcut so that every time I needed louder sound, I would not have to use my mouse to reach out for the gnome sound control.

I turned out that the pactl command (from pulseaudio-utils package in Ubuntu) can be used for this purpose.

To make the volume go up by 10%, the command would be:

 pactl set-sink-volume 0 +10%  

And to make the volume go down by the same amount, the command would be:

 pactl set-sink-volume 0 -- -10%  

(The '--' in the command above is necessary otherwise it is interpreted as a command line option and I get an error. The '--' basically stops the shell from option parsing from that point onward)

This command allows me go beyond 100%

Now I have assigned this command to a shortcut key in Gnome and my problem is solved :-)

BTW, if there are more audio devices, the index may need to be changed from 0 (I have only one, so the index is 0 in my case). More details are available in the 'pactl' and 'pacmd' manual pages.

Sunday, May 25, 2014

Solution for: Mouse cursor disappears when starting i3 with gnome-settings-daemon (in Arch Linux)

In my arch installation, whenever I start the i3 (or awesome) window manager as a gnome-session (which starts gnome-settings-daemon), the mouse cursor disappears. It is there, since I can click on things, but not visible. It is possible that the same problem exists when other window managers are started (other than gnome shell), but I have not tested with other window managers.

The solution turns out to be to run the following command:

 gsettings set org.gnome.settings-daemon.plugins.cursor active false  

That makes the mouse cursor visible again.


Sunday, May 18, 2014

Font settings I used in my Arch Linux install (on USB Pendrive)

I have the following content in my ~/.config/fontconfig/fonts.conf:

 <?xml version='1.0'?>  
 <!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>  
 <fontconfig>  
   <match target="font">  
     <edit mode="assign" name="autohint">  
       <bool>false</bool>  
     </edit>  
   </match>  
   <match target="font">  
     <edit mode="assign" name="rgba">  
       <const>rgb</const>  
     </edit>  
   </match>  
   <match target="font">  
     <edit mode="assign" name="hinting">  
       <bool>true</bool>  
     </edit>  
   </match>  
   <match target="font">  
     <edit mode="assign" name="hintstyle">  
       <const>hintfull</const>  
     </edit>  
   </match>  
   <match target="font">  
     <edit mode="assign" name="antialias">  
       <bool>true</bool>  
     </edit>  
   </match>  
 </fontconfig>  

Also, from AUR, I have installed the package 'ttf-win7-fonts-autodownload'.

Further, I have installed 'ttf-ubuntu-font-family'.

In Firefox I have installed the "Theme Font & Size Changer" add-on.

IIRC, that's all I did to get great (at least to my eyes) fonts in my Arch installation.

By the way, this Arch installation is on a USB pendrive, allowing me to carry my Linux around all the time. Apna Linux Pehen Ke Chalo :-)

Using gsettings to set font preferences in my shiny Ubuntu Gnome 14.04 Desktop

Instead of using gnome-tweak-tool, this time I have used the command line utility 'gsettings' to set my font preferences in Gnome (Ubuntu Gnome - 14.04). After invoking some 'gsettings set ...' commands, I have the following:

 ubuntu-gnome@ubuntu-gnome:~$ gsettings list-recursively org.gnome.settings-daemon.plugins.xsettings   
 org.gnome.settings-daemon.plugins.xsettings disabled-gtk-modules @as []  
 org.gnome.settings-daemon.plugins.xsettings priority 0  
 org.gnome.settings-daemon.plugins.xsettings hinting 'full'  
 org.gnome.settings-daemon.plugins.xsettings overrides {'Gtk/ShellShowsAppMenu': <0>}  
 org.gnome.settings-daemon.plugins.xsettings rgba-order 'rgb'  
 org.gnome.settings-daemon.plugins.xsettings antialiasing 'rgba'  
 org.gnome.settings-daemon.plugins.xsettings active true  
 org.gnome.settings-daemon.plugins.xsettings enabled-gtk-modules @as []  

(Note the keys 'hinting', 'rgba-order' and 'antialiasing')

To know which values are valid for any key, there is the 'range' command. For example, to know what are the possible values I can use for the 'antialiasing' key, I can use the following command:

 ubuntu-gnome@ubuntu-gnome:~$ gsettings range org.gnome.settings-daemon.plugins.xsettings antialiasing  
 enum  
 'none'  
 'grayscale'  
 'rgba'  

That means I can use one of those three enum values for the 'antialiasing' key.

Saturday, May 17, 2014

Prevent desktop icons to show up in Unity Desktop (Ubuntu 14.04)

Just type in the following command at a shell prompt:

 $ gsettings set org.gnome.desktop.background show-desktop-icons false  

Case Insensitive Autocompletion in Bash

Today I learnt how to get case insensitive autocompletion in Bash.

Just put the following line in ~/.inputrc:

 set completion-ignore-case On  

That's it. To learn more about what is really going on, the bash and readline manual pages should be read.


Sunday, May 4, 2014

Using Upstart in Ubuntu 12.04 to set screen brightness during boot in Asus Eee PC

First I wrote a small script in /usr/local/bin to set the brightness to the lowest possible value (the lowest value is plenty bright for my eyes):

 $ cat /usr/local/bin/set-screen-brightness.sh   
 #!/bin/bash  
 echo $1 > /sys/class/backlight/acpi_video0/brightness  

Then I made the script executable. Next I wrote the following upstart script:

 $ cat /etc/init/my-brightness.conf   
 description "Set laptop screen to lowest brightness level"  
 start on runlevel [2]  
 script  
   exec /usr/local/bin/set-screen-brightness.sh 0  
 end script  

(My default runlevel (as indicated by running the runlevel command) is 2)

At the next boot, my screen's brightness is automatically set to the provided 0 value.

If I wanted to start the 'my-brightness' upstart service anytime, I would simply use the following command:

 $ sudo service my-brightness start  

Hiding the Unity2d launcher when not in use (Ubuntu 12.04)

The command to hide the Unity2d launcher when not in use is:

 gsettings set com.canonical.Unity2d.Launcher hide-mode 1  

Wednesday, April 30, 2014

Connecting to wifi access point from the terminal

The following process has worked for me. I simply followed the procedure mentioned in arch linux wiki with a small tip from one of their forum post. So, a big thanks to the Arch community.

First of all, I am assuming all the wireless drivers are installed and loaded properly. I used the commands: iw, ip, wpa_supplicant for the process. NetworkManager was not used.

 $ iw dev  
   phy#0  
     Interface wlan0  
     ifindex 3  
     type managed  

This gives me the name of the wireless interface: wlan0

 $ ip link show  
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN   
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  
 3: wlan0: <BROADCAST,MULTICAST> mtu 1500 qdisc mq state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  

That means my wireless link wlan0 was not UP (otherwise the word UP would be there within <>)

 $ sudo ip link set wlan0 up  
 $ ip link show  
 1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN  
   link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00  
 2: eth0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc pfifo_fast state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  
 3: wlan0: <NO-CARRIER,BROADCAST,MULTICAST,UP> mtu 1500 qdisc mq state DOWN qlen 1000  
   link/ether xx:xx:xx:xx:xx:xx brd ff:ff:ff:ff:ff:ff  

Now, the wlan0 is UP. So, now it is time to find out what access points are available.

 $ sudo iw dev wlan0 scan | grep SSID  
     SSID: TP-LINK_POCKET_3020_C50F1E  
     SSID: Ramananda  

Ok. I want to connect to the first one. But before that I need to create a wpa_supplicant.conf file with the SSID and Password for the Access Point to which I want to connect.

 $ wpa_passphrase TP-LINK_POCKET_3020_C50F1E xxxxxxxx > wpa_supplicant.conf  

Now that the wpa_supplicant.conf file is generated, I can attempt to connect to the access point.

 $ sudo wpa_supplicant -iwlan0 -c wpa_supplicant.conf  
 ioctl[SIOCSIWENCODEEXT]: Invalid argument  
 ioctl[SIOCSIWENCODEEXT]: Invalid argument  
 Trying to associate with xx:xx:xx:xx:xx:xx (SSID='TP-LINK_POCKET_3020_C50F1E' freq=2462 MHz)  
 Associated with xx:xx:xx:xx:xx:xx  
 WPA: Key negotiation completed with xx:xx:xx:xx:xx:xx [PTK=CCMP GTK=CCMP]  
 CTRL-EVENT-CONNECTED - Connection to xx:xx:xx:xx:xx:xx completed (auth) [id=0 id_str=]  

I don't know about the ioctl lines, but now I am connected to the wireless access point. Now what I need to do is to use dhclient3 or dhcpcd to get an ip address from my access point (which is also configured as a dhcp server)

 $ sudo dhclient3 wlan0  

Done. Now I can successfully ping google :-)

Dear Inconsolata, I want to use you properly

I never got why inconsolata font is considered good for coding and things like that... until today.

I learnt that if I set autohint=true for the Inconsolata font in Linux (I am currently on Ubuntu 14.04), it actually looks great!

So, after reading some portions of the fonts.conf(5) manual page, I added the following stanza to my .config/fontconfig/fonts.conf file so that autohinting will be selectively turned on only for the Inconsolata font (others fonts tend to look horrible if autohinting is turned on as far as I am concerned):

 <match target="pattern">
     <test name="family">
         <string>Inconsolata</string>
     </test>
     <edit mode="assign" name="autohint">
         <bool>true</bool>
     </edit>
 </match>


Monday, February 10, 2014

Getting the correct pre-requisites for building gcc


Today I had to build a gcc cross compiler for my OS related experiments (I was building the bare bone OS as described in http://wiki.osdev.org/Bare_Bones). For some reason, gcc would not build. Turned out the versions of mpc, mpfr and gmp that I downloaded were likely not compatible, and were causing problems.

After some searching on the net I found that inside gcc source tree, there is a folder called contrib which contains a script called download_prerequisites. So, all I needed to do was to get into gcc source folder and execute:

$ ./contrib/download_prerequisites.

This downloaded the correct versions of the prerequisites and I was then able to successfully build the i586-elf target gcc cross compiler.


Thursday, January 2, 2014

An excellent source of some nice tutorials

Today, I was looking for some nice tutorial videos on intel assmbly language, and found this:
http://opensecuritytraining.info/IntroX86.html

Very informative.

I think I am going to frequently visit this site for their nice tutorials on some interesting topics which I find interesting.

Monday, December 30, 2013

Sample usage of transcoding using vlc, then genisoimage and wodim to write a dvd

Today I needed to write a dvd with some old family videos in it. The videos were obtained from my Sony Handycam. They were .MPG files, but the problem was they were too large to fit in a dvd.

So, to reduce their size without changing the quality, I decided to transcode them using vlc. I had no idea how to do it. So I fired up vlc from a terminal and after exploring some menu items, I transcoded one of the files to .mp4. The size got reduced by more than half. Great! Now I had to find a corresponding command line form of the same action for automating it for transcoding all of the 36 files I had.

So, I looked at the terminal dump of whatever vlc had done so far, and then googled around a little, and came up with this solution (for my case):

for i in `seq -w 01 36`; do 
  cvlc ~/Videos/HomeVideos/2011.10.05/M2U000$i.MPG
       --sout '#transcode{
                  vcodec=h264,vb=0,scale=0,
                  acodec=mpga,ab=128,
                  channels=2,samplerate=44100
               }:std{access=file,mux=mp4,dst='./$i.mp4'}'
       vlc://quit;
done


(BTW, what I actually ran was the above code all in a single loong line. I just formatted the above code to look nice and be more understandable. I am not sure whether the code would work if formatted like above. Too lazy to try now.)

The vlc://quit was to make vlc quit after transcoding each file. Otherwise I had to press Ctrl-C after each file was transcoded.

Next I made an iso image out of the transcoded files with the genisoimage as follows:

genisoimage -o homevideos_2011.10.05.iso \
            -p "Santanu" -V "HomeVideos_2011.10.05" -publisher "Santanu" \
            ./converted/


Then I wrote the resulting iso file to a blank dvd using wodim as follows:

wodim -v -eject speed=4 dev=/dev/dvdrw driveropts=burnfree homevideos.iso 



Saturday, September 21, 2013

RIP 'q' Key :-(

Recently, my colleague's thinkpad's 'q' key died. I am now thinking of digging up old xmodmap manual to use an unused key for 'q'. In the meantime, I am using the following method to input the 'q' character in gnome-terminal, firefox, etc.:

Control+Shift+u, then the hex Unicode value for the 'q' character (71)

... time to find the xmodmap manual... wait, I think I made a post about this a few years ago

Sunday, September 8, 2013

Aircel related info for my future reference

A few days ago, I had accidentally activated some Aircel service related to SMS (the service is called WBSMS1, the 1 part at the end is probably because it has validity of one day). I don't know what that service was, nor do I care. Since then every day, the service got auto renewed (that makes me angry), costing me Re.1/-

Today, I finally got fed up with it and try to call customer care number 121. Somehow it seems that I cannot talk to an aircel person using this number. For that I would have to call 198. So I called the person at the other end let me know that I am supposed to give the USSD command *122*01# to deactivate the service.

Tried it and finally the service is deactivated.

I just wanted to note the process so that I may refer back to it later.

Monday, March 11, 2013

Non-Linux Tip

To know any VAS (Value Added Services) you have activated on your BSNL mobile, the USSD code to use is *456*00#
For Airtel, it is *121*5#