Showing posts with label My Tools. Show all posts
Showing posts with label My Tools. Show all posts

Wednesday, May 12, 2021

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I have a hard time with heavy mice, like MX Master itself. Also, the ergonomics is a killer here.

But I was having a hard time figuring out how to pair it to my Linux machine, Windows 10 was fine. Literally spent hours trying to Google a solution down. Nothing was showing up. The official pages only provide links to Windows Driver and MacOS drivers. The user manual is more of a translation tutorial rather than something useful. Really really hard to read with such small fonts as well.

But fortunately, switching the search term turned up with a russian blog post that had instructions for it. And an undocumented (or hard to find in the documentation) feature is all I needed. So I am going to post that here in order to keep a record and hope someone else does not have the same hard time.


Things to know:

  1. The device switcher button on the mouse has a "long press" functionality. It puts the specific responder on so the device tries to connect with that.
  2. You need to install 'hcitool" from AUR
Steps:
  1. First need to find out the MAC Address of the Bluetooth device. To do that, in your terminal type

    hcitool scan
  2. With your mouse turned on, long press the device switcher button. You will see that the device number blinker slows down and blink with less frequency. This is, according to the manual, when the mouse is trying to connect to a device
  3. At this point, the hcitool command should turn up with a MAC Address
  4. Now in terminal, type
    bluetoothctl
  5. Now type
    trust <MAC Address>
  6. And type
    connect <MAC Address>
  7. At this point, your mouse should be working already






Keeping a copy of that page here for future reference:

From sunny China came a mouse for the laptop - Rapoo MT550. Excellent ergonomics, power supply from 2xAA batteries promises to be long-lasting, and the most killer feature is work simultaneously with three computers via bluetooth with a simple switch.



Under Windows 10, no problems arose - I turned it on, clicked the "bluetooth scan" on the mouse, Windows found it and that's it.

Under Linux Mint 17.3 Cinnamon - the mouse is visible, but when trying to connect, it is impossible to enter pin code "0000" for this mouse in the pop-up notification. Accordingly, the BT manager has a mouse, but it is indicated that the pairing did not occur. Probably no problem under KDE or other shells.

The solution is that you need to manually pair:

1. Install the packages:

apt-get install bluez-tools
apt-get install bluez-hcidump

The first one swears that it is "untrusted".

2. Execute, on the mouse, press the "bluetooth" button for recognition:

hcitool scan
Scanning ...
6C: 5D: 63: 77: 1D: 1E  RAPOO BT3.

3. In a new terminal window:
sudo hcidump -at
HCI sniffer - Bluetooth packet analyzer ver 2.5

device: hci0 snap_len: 1500 filter: 0xffffffffffffffff

4. We are interested in hci0, execute:
sudo bluez-simple-agent hci0 6C: 5D: 63: 77: 1D: 1E
RequestPinCode (/ org / bluez / 11002 / hci0 / dev_6C_5D_63_77_1D_1E)
Enter PIN Code: 0000
Release
New device (/ org / bluez / 11002 / hci0 / dev_6C_5D_63_77_1D_1E)

It will ask for a pincode, for MT550 - "0000"

5. Making the bluetooth mouse "trusted"
sudo bluez-test-device trusted 6C: 5D: 63: 77: 1D: 1E yes

6. We cling to the mouse:
sudo bluez-test-input connect 6C: 5D: 63: 77: 1D: 1E

You can try to move the mouse - it should be recognized. After rebooting, it was recognized automatically, and in the Bluetooth manager of Mint itself, the mouse is now indicated as paired. 

7. For MT750 / 750S, the connection instructions are the same.

UPDATE for those who have Mint 19 / Ubuntu 18.04:

Although the mouse is detected in the bluetooth manager, it still does not want to connect at point-blank range. Simple-agent and the commands associated with it no longer work
in  bluez-tools .
To connect, enter:
hcitool scan - and hold down the channel selection button (on Rapoo 750S), we see the mouse:
Scanning ...
6C: 5D: 63: 76: AA: 17  RAPOO BT3.0 MS
Next, run the utility:
sudo bluetoothctl 
Shows a bunch of devices in the area, incl. and mouse (for some reason I have different macs and BT versions):
[NEW] Device ED: 8E: 0E: 10: AA: 28 RAPOO BT4.0 MS
[NEW] Device 6C: 5D: 63: 76: AA: 17 RAPOO BT3.0 MS
Then in the console [bluetoothctl]:
help - list of commands
We need to entrust the required MAC and connect:
[RAPOO BT4.0 MS] # trust 6C: 5D: 63: 76: AA: 17
[CHG] Device 6C: 5D: 63: 76: AA: 17 Trusted: yes
Changing 6C: 5D: 63: 76: AA: 17 trust succeeded
[bluetooth] # connect 6C: 5D: 63: 76: AA: 17
Attempting to connect to 6C: 5D: 63: 76: AA: 17
[CHG] Device 6C: 5D: 63: 76: AA: 17 Connected: yes
Connection successful
I can't vouch for the trust / connect sequence - first I tried connect, then trust - the result is negative. After trust - again connect - everything came to life. 
At the time of connect,  you must also keep the channel selection on the 750S.

Thursday, January 02, 2020

Unreal Tournament 2004 bugs in Linux

There are 2 specific problems that I almost always run into when I attempt to run Unreal Tournament 2004 on Linux.


  1. No soound
  2. Libstdc++

I am keeping a note of these 2 here.

For no sound, just use "padsp ./ut2004"

And for Libstdc++, try installing the library through your distro's package manager. Example: "sudo pacman -S libstdc++5" 

Monday, December 18, 2017

Change Matplotlib backend to avoid QT5 issues.

This is an issue that has been bugging me for about 5 hours. Until I reached the solution of changing the backend of Matplotlib for good.

import matplotlib
gui_env = ['TKAgg','GTKAgg','Qt4Agg','WXAgg']
for gui in gui_env:
    try:
        print "testing", gui
        matplotlib.use(gui,warn=False, force=True)
        from matplotlib import pyplot as plt
        break
    except:
        continue
print "Using:",matplotlib.get_backend()


Credits: https://stackoverflow.com/a/43015816/1928610

Sunday, November 27, 2016

Display switcher for terminal buffs

I am not a Linux developer or anything, I just love writing scripts that facilitate in making me lazy. So here's one that lets me switch my displays (dual). I usually work on only one and when I need to quickly switch, I use this. It depends on xrandr though. And it has my display names hardcoded (lots of assumptions, I know), but it might just come in handy.
Switch to left or right
./reset_display.sh left
./reset_display.sh right
Set both on with duplicate view
./reset_display.sh
Set both on their individual view
./reset_display.sh both

You can simlink it /usr/local/bin too.
Github gist

Sunday, November 06, 2016

Getting file list from torrent magnet URLs using Aria2

So, I hit upon this realy awesome SO reply on how to fetch the torrent file list using magnet URLs. I use Aria2 for torrents and it's be design that you cannot get any meta data from Magnet URLs because they do not hold any information off the link. They fetch the meta data when you use them. So, what you have to do is, generate a torrent file from them and then use THAT torrent file for listing. So it's a 2 step process.

First you create the torrent file using:
aria2c --bt-metadata-only=true --bt-save-metadata=true -q "magnet url here"
It will generate a torrent file right there with a name that is a hash just use that to get the file list.

Credits: http://unix.stackexchange.com/a/134286/52595

Saturday, October 08, 2016

Replacing Apache in your VPS with Nginx

If you have not been following the web development scene recently, you need to know that Apache is being seriously challenged by Nginx in the ideal server candidate position. Nginx is a great server daemon that also uses much less resources. Recently I attempted to make a move to Nginx from Apache. But there were some issues that needed to be addressed.

Well, setting up Nginx is really straightforward, just run
# apt-get install nginx
But you might face problems with starting the nginx service. Well, the most likely reason probably is that by default Nginx is configured to run on Port 80. In computers one port cannot be used by multiple programs at the same time. But Apache too is configured to listen on port 80. Now, if you want to move to Nginx and serve all your sites via Nginx, you can unassign Apache from port and give Nginx the instruction to listen to port 80. To do that you will need to tweak an apache configuration file. This may be different for different distros and scenarios but the most common place to look for the Apache configuration files is
/etc/apache2
or
/etc/httpd
Now usually the configuration can be found in
/etc/apache2/apache2.conf
or
/etc/httpd/httpd.conf
Just open your appropriate configuration file and try to find the the line:
Listen 80
If you can't find the line it's very much possible that the port instruction is in different file. Just read through the configuration and try to find if any "Include" directive. It could be like
Include "ports.conf"
Which means the port Listen directive is there. Open the file (you should be able to find that in the same directory).
Now change "Listen 80" to "Listen 1234". This will make Apache listen to port 1234.
Now you should restart Apache with
#servicectl restart apache2
And start nginx with
#servicectl restart nginx

Saturday, August 06, 2016

Solving GPU nvidia Optimus issues on Linux

I have gone through painstakingly complex processes to solve this issue time after time and today I just decided to record my approach for this time. I understand that one approach almost never works twice for this issue in particular. So I am just going to add links and references that help me solve this problem.


First of all, my approach is based on Bumblebee and nothing beats this when it comes to Arch or Arch based.
https://wiki.archlinux.org/index.php/bumblebee
Then to solve any optimus related issue, https://github.com/Bumblebee-Project/Bumblebee/wiki/Troubleshooting
And finally for primus run
https://wiki.archlinux.org/index.php/bumblebee#Primusrun

Wednesday, July 06, 2016

Fixing assets broken by Google reCaptcha

Well this does not fix the page fully but it make it workable. Follow the steps.
Open fiverr.com, and click "inspect element". Go to "Console".
Then click on an asset (js/css) that has 403.
Now right click on it and click "open in new tab"
Enter the reCaptcha, you'll see the asset file now
Now repeat this for the assets that got 403
Now you got your page partially fixed, you might find some more JS missing, just go to console and fix that using the same way.

Tuesday, July 14, 2015

Connecting via Remote host using postgresql

When the instance of postgres is inside vm and you are on the host machine with some stack such as Node, the scenario becomes as if connecting from a remote host. To make it possible, we have to make postgres listen to remote (all) hosts and also specify the IP of that host.
1. To add the ip to the allowed host list, edit /etc/postgresql/9.1/main/pg_hba.conf and add the lines
host all all 192.168.0.1/24 md5
where 192.168.0.1 is the IP of the host you want to connect from.
2. And to enable listening from remote hosts, edit the file /etc/postgresql/9.1/main/postgresql.conf and add the following line
listen_addresses = '*'
Credits http://www.thegeekstuff.com/2014/02/enable-remote-postgresql-connection/

Setting up Node with NVM

I always keep facing problems with Node. It just keeps pushing me around with it's numerous errors. So, lately I found out about NVM and tried it. Still had an issue with it. But finally got it up and running. Here are some important things to keep note of when attempting to install node using NVM.
1. The default installation directory of the NVM installer (provided in the repo readme) is ~/.nvm. I find this a bit problematic so I actually just clone the repo into /opt/nvm since I kind of stick to sudoing things when they need to be global for node and ~/.nvm isn't owned by root, I kind of like to keep it that way.
2. Now setting up the envvars is done using profile.d/nvm.sh. This could also be done using ~/.zshrc or ~/.zprofile but I like it this way. In whatever case the envvar setup script is like this
export NVM_DIR=/usr/local/nvm
source /opt/nvm/nvm.sh

export NPM_CONFIG_PREFIX=/usr/local/node
export PATH="/usr/local/node/bin:$PATH"
3. So it's basically done (setting up NVM, not node) but since to install anything via nvm I'll need sudo so I must (at least) source the /etc/profile.d/nvm.sh into root. So I just do
$ sudo su
# source /etc/profile.d/nvm.sh
4. Now for the installation of a node version
# nvm install 0.12
# nvm ls
The last one should be done from root because it creates a particular directory that $ can't create.
5. Now we can simply execute
$ nvm use 0.12

Credits:
http://stackoverflow.com/questions/11542846/nvm-node-js-recommended-install-for-all-users
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-with-nvm-node-version-manager-on-a-vps
Found a nice article here: http://www.liquidweb.com/kb/how-to-install-node-js-via-nvm-node-version-manager-on-ubuntu-14-04-lts/

Adding profile.d envvars to zsh

This is an extremely simple task to accomplish. Since, bash uses the following code segment to source all the files under /etc/profile.d you just have to add this into your ~/.zprofile or /etc/zprofile (the former sounds like a much more flexible choice).
# The default umask is now handled by pam_umask.
# See pam_umask(8) and /etc/login.defs.

if [ -d /etc/profile.d ]; then
  for i in /etc/profile.d/*.sh; do
    if [ -r $i ]; then
      . $i
    fi
  done
  unset i
fi


Monday, July 13, 2015

When you can't log into Postgresql from Web Interface (Adminer etc.)

I ran into this problem earlier this week and left it until today, when I needed it work at all cost. Turns out it was a simple issue with the configuration file. Here's the process.

First of all, open the file /etc/postgresql/9.1/main/pg_hba.conf
Find the line : "local" is for Unix domain socket connections only
Below that line there is a line like this: local all all md5
Just change the last value to: peer
So the line now looks like: local all all peer
Now save the file (you need to be root)
Then restart the Postgresql process using the command: sudo service postgresql restart
Done.

Sunday, May 03, 2015

Vagrant কি আর কিভাবে এটা ব্যবহার করব?

Vagrant আসলে একটা virtualization tool (wrapper আসলে)। এটা যা করবে, তোমার PC-র RAM খরচ করে একটা virtual computer বানাবে। সেটার সাথে তোমার real PC-র একটা LAN (NAT আসলে) বানাবে। আর সেই PC-র Port 80 (HTTP Listener) টা কে তোমার real PC-র কোন একটা port এ forward করে দেবে। যেখানে তুমি তোমার app টা কে access করতে পারবা। OK, that part aside, তুমি এখন এই same port কে কোন public IP তেও দিয়ে দিতে পারো।

কথা হচ্ছে, কিভাবে এত সব হবে। প্রথম কথা, Vagrant তোমার জন্য, সবই নিজে করবে, তুমি শুধু কিছু script লিখে বলে দিবা কি কি software তোমার server এ রাখবা। যেমন সাধারণত আমি LAMP stack টা ছাড়া কিছু রাখিনা, আর Django রাখি (Python)। তো আমি একটা provisioning script লিখে রেখে দেই। এটা একটা directory তে রেখে "vagrant up" command লিখলেই কিছুক্ষণের মধ্যে আমার server ready। তো এতসব যে হচ্ছে, বাতাস থেকে হচ্ছে নাকি? না। আসলে তুমি তোমার core OS টার একটা image (ubuntu 14.04, 12.04, etc) প্রথমবার vagrant কে দিয়ে download করাবা। সে এটা একবারই নামায় রেখে দিবে আর পরে আরও server বানালে সে এটা দিয়ে OS install করে তোমার provision script থেকে software গুলি install করবে।

তো এখন কি তুমি provisioning script এর language শিখতে বসবা? না। ভাল একটা vagrant file নামায় একটা directory তে রেখে "vagrant up" করে দিবা। প্রথমবার সে image নামাবে। তো এসব vagrant file পাবা কোথায়? Google দিয়ে পাবা। আমি কয়েকটা use করি। মোটামুটি ২/৩ টার মধ্যেই হয়ে যায় সব। Github এ অনেকে তাদের configure করা VM এর vagrantfile share করে দেয়। ভাল করে লিখেও দেয় এটাতে PHP কোনটা, phpMyAdmin আছে কিনা। কোন port এ কি service চলে। পরে শুনে দেখে একটা তে settle হবা এই আর কি।

Happy exploring.

Saturday, March 28, 2015

Stop the laptop from going "stand by" when lid is closed in Xubuntu

I hate the fact that I have to figure this out for every new distro I use. But here it goes for Xubuntu. Tested and working in 14.04 LTS.
1. Open the file /etc/systemd/logind.conf
2. Find the line "HandleLidSwitch="
3. Set it like "HandleLidSwitch=ignore" and if it has a "#" (hash" in front of it, remove it.
Save and reboot and you are good. :)
Credits: http://askubuntu.com/a/362692/145915

Monday, March 23, 2015

Laravel validation trouble shootings.

While working on a project I stumbled upon this huge pile of problem of validating a form. Even though the fancy coding styles did make some things easy, it made some other things hard, especially when not having a complete documentation. So, here's a note for future.
\ 1. Custom validation messages: Custom messages, if not in a language file must be written for each field and each of the rules of that field. So you cannot escape with a single message written for email field if you want it to be shown on every rule. You have to write that same message for each rule, individually
2. Field name renaming: When printing validation messages Laravel, if not instructed otherwise, will use a slightly polished version of the 'name' attributes of you fields. So, for example name='user_name' will be made into user name. So if you instead want it to look like "Username", you have to use the method called
setAttributeNames
Like this:
$attributeNames = array(
   'name' => 'Name',
   'cat' => 'Category',     
);
$validator = Validator::make ( Input::all (), $rules );
$validator->setAttributeNames($attributeNames);
// Credits for: http://stackoverflow.com/a/25189223/1928610
3. Check uniqueness in a table having a different name than field name: Now what if you want to ensure that the user always enters an email that is not yet present in the 'users' table when signing up. Laravel has a great validation rule for it called 'unique:table_name'. So you use it like
'email' => 'unique:users'
But if you are like me, you may at first run into the problem where your field 'name' attribute does not match with the uniqueness field in your database. Like in my case, email field's name attribute contained 'email_address' but in my 'users' table, the column name was 'email'. So to fix this, Laravel validaton just takes another attribute with the validator.
'email_address' => 'unique:users,email'
Neat right?
Scouring through the documentation will help you more as it is doing for me. I'll keep posting further troubles I shoot in Laravel. InshaAllah.

Saturday, February 07, 2015

Mount non Linux drives automatically when they are not in /etc/fstab

So, I usually face this problem when I'm not using GUI based File Managers. They allow you to auto mount drives when you click on them but when you are using CLI based file managers or no file managers at all, the only way is to mount them through writing commands. I'm a lazy fad and I want this done automatically. So here's a script for that. [ https://gist.github.com/Tafhim/5d0839caca813ae82c97 ].
#!/usr/bin/zsh
if [[ "$1" == "" ]] then
  echo "Please specify a device name";
  exit;
fi;
deviceFile=$1
 
## Auto mount only ntfs, fat32, vfat
for i in $(ls $deviceFile* | grep '[0-9]$'); do
  blkid -s UUID -o value $i | read z;
  blkid -s TYPE -o value $i | read f;
  echo "$z is $f";
  if [[ "$z" !=  "" && ("$f" == "ntfs" || "$f" == "vfat" || "$f" == "fat32" ) ]] then
    /usr/bin/udisksctl mount -t $f -b $i # https://help.ubuntu.com/community/AutomaticallyMountPartitions
  fi;
done

Thursday, February 05, 2015

Documenting my first Arch build

I bought a new Laptop a few months ago and now I have the old one being thrown around and ready for some wild tests. So I decided instead of using prebuilt Arch Linux distros I'll make a proper one myself and see how things turn up. :)

1. First things first, I built the vanilla setup simply by following the "Beginners's guide in Arch Wiki" and the only 2 things I found of good notice is the "Partitioning part" and the "Get yourself wifi" part. Both of these have different scenarios but in my case things were a bit simplified since
a. I always use MBR
b. I always use WiFI
So to fix the partitioning issue I didn't do much. Used parted to get my disks ready, wrote the file systems using mkfs.ext4 and mkswap and set the bootflag on root.
To fix up with the WiFi, I first unblocked using
rfkill unblock all
Then used
wifi-menu
To connect to my system
This pretty much brought up my whole system using the guide I mentioned earlier which you can find here

2. Now for the post installation part. The very first thing that came in my way is that my fan was blasting away like crazy. I fixed this using 'laptop-mood-tools' and 'powertop'. So first I created a new user (I can't be root when installing packages from the AUR) then I installed
yaourt
Then I installed 'laptop-mode-tools' using 'yaourt'. After that I installed 'powertop' using 'pacman' and ran it
powertop
Then I used to TAB key to go to the Turntables column and made all the 'Bad' entries 'Good'. Then pressed 'Esc' to save the settings and rebooted.
UPDATE: Apparently this did not bring the crazy fan speeds down. After some browsing around, I hit a thread in the ArchBang forums where it became pretty apparent that recent Kernel changes in 3.18 have triggered the issue and still has not been resolved. So, I had to downgrade to 3.17.6 which I did by following a well written guide here. What I basically did was
a. Went to the Arch official package database
b. Located the Linux package
c. On the upper right Package Section of the page, click on View Changes. There I located an earlier version, in this case upgpkg: linux 3.17.6-1
d. Located the revision number from the line that is like "file:///srv/svn-packages@177020". That’s the revision number after the @, it might be anything. e. Then to compile 3.17.6, did the following in the terminal. CAUTION: This process might take several hours, took me around 4 hours to compile the kernel
cd ~/Downloads
mkdir linux-kernel && cd linux-kernel
svn checkout --depth=empty svn://svn.archlinux.org/packages
cd packages
svn update -r  linux
cd linux/trunk/
makepkg -g >> PKGBUILD
makepkg -s
sudo pacman -U *.pkg.tar.xz
This will install the new kernel. You might face some dependency issues where it might ask for 3.18. I removed those packages. Rebooted the PC and it was fixed.
3. Now for the GUI. I personally do not find full blown desktop environments much useful so I stick to Window Managers. I installed Xmonad. Then I configured Xorg for my user account using
Xorg -configure
Copied the barebones default xmonad configuration template from their configuration archives into ~/.xmonad/xmonad.hs
--
-- xmonad example config file for xmonad-0.9
--
-- A template showing all available configuration hooks,
-- and how to override the defaults in your own xmonad.hs conf file.
--
-- Normally, you'd only override those defaults you care about.
--
-- NOTE: Those updating from earlier xmonad versions, who use
-- EwmhDesktops, safeSpawn, WindowGo, or the simple-status-bar
-- setup functions (dzen, xmobar) probably need to change
-- xmonad.hs, please see the notes below, or the following
-- link for more details:
--
-- http://www.haskell.org/haskellwiki/Xmonad/Notable_changes_since_0.8
--
 
import XMonad
import Data.Monoid
import System.Exit
 
import qualified XMonad.StackSet as W
import qualified Data.Map        as M
 
-- The preferred terminal program, which is used in a binding below and by
-- certain contrib modules.
--
myTerminal      = "xterm"
 
-- Whether focus follows the mouse pointer.
myFocusFollowsMouse :: Bool
myFocusFollowsMouse = True
 
-- Width of the window border in pixels.
--
myBorderWidth   = 1
 
-- modMask lets you specify which modkey you want to use. The default
-- is mod1Mask ("left alt").  You may also consider using mod3Mask
-- ("right alt"), which does not conflict with emacs keybindings. The
-- "windows key" is usually mod4Mask.
--
myModMask       = mod1Mask
 
-- NOTE: from 0.9.1 on numlock mask is set automatically. The numlockMask
-- setting should be removed from configs.
--
-- You can safely remove this even on earlier xmonad versions unless you
-- need to set it to something other than the default mod2Mask, (e.g. OSX).
--
-- The mask for the numlock key. Numlock status is "masked" from the
-- current modifier status, so the keybindings will work with numlock on or
-- off. You may need to change this on some systems.
--
-- You can find the numlock modifier by running "xmodmap" and looking for a
-- modifier with Num_Lock bound to it:
--
-- > $ xmodmap | grep Num
-- > mod2        Num_Lock (0x4d)
--
-- Set numlockMask = 0 if you don't have a numlock key, or want to treat
-- numlock status separately.
--
-- myNumlockMask   = mod2Mask -- deprecated in xmonad-0.9.1
------------------------------------------------------------
 
 
-- The default number of workspaces (virtual screens) and their names.
-- By default we use numeric strings, but any string may be used as a
-- workspace name. The number of workspaces is determined by the length
-- of this list.
--
-- A tagging example:
--
-- > workspaces = ["web", "irc", "code" ] ++ map show [4..9]
--
myWorkspaces    = ["1","2","3","4","5","6","7","8","9"]
 
-- Border colors for unfocused and focused windows, respectively.
--
myNormalBorderColor  = "#dddddd"
myFocusedBorderColor = "#ff0000"
 
------------------------------------------------------------------------
-- Key bindings. Add, modify or remove key bindings here.
--
myKeys conf@(XConfig {XMonad.modMask = modm}) = M.fromList $
 
    -- launch a terminal
    [ ((modm .|. shiftMask, xK_Return), spawn $ XMonad.terminal conf)
 
    -- launch dmenu
    , ((modm,               xK_p     ), spawn "exe=`dmenu_path | dmenu` && eval \"exec $exe\"")
 
    -- launch gmrun
    , ((modm .|. shiftMask, xK_p     ), spawn "gmrun")
 
    -- close focused window
    , ((modm .|. shiftMask, xK_c     ), kill)
 
     -- Rotate through the available layout algorithms
    , ((modm,               xK_space ), sendMessage NextLayout)
 
    --  Reset the layouts on the current workspace to default
    , ((modm .|. shiftMask, xK_space ), setLayout $ XMonad.layoutHook conf)
 
    -- Resize viewed windows to the correct size
    , ((modm,               xK_n     ), refresh)
 
    -- Move focus to the next window
    , ((modm,               xK_Tab   ), windows W.focusDown)
 
    -- Move focus to the next window
    , ((modm,               xK_j     ), windows W.focusDown)
 
    -- Move focus to the previous window
    , ((modm,               xK_k     ), windows W.focusUp  )
 
    -- Move focus to the master window
    , ((modm,               xK_m     ), windows W.focusMaster  )
 
    -- Swap the focused window and the master window
    , ((modm,               xK_Return), windows W.swapMaster)
 
    -- Swap the focused window with the next window
    , ((modm .|. shiftMask, xK_j     ), windows W.swapDown  )
 
    -- Swap the focused window with the previous window
    , ((modm .|. shiftMask, xK_k     ), windows W.swapUp    )
 
    -- Shrink the master area
    , ((modm,               xK_h     ), sendMessage Shrink)
 
    -- Expand the master area
    , ((modm,               xK_l     ), sendMessage Expand)
 
    -- Push window back into tiling
    , ((modm,               xK_t     ), withFocused $ windows . W.sink)
 
    -- Increment the number of windows in the master area
    , ((modm              , xK_comma ), sendMessage (IncMasterN 1))
 
    -- Deincrement the number of windows in the master area
    , ((modm              , xK_period), sendMessage (IncMasterN (-1)))
 
    -- Toggle the status bar gap
    -- Use this binding with avoidStruts from Hooks.ManageDocks.
    -- See also the statusBar function from Hooks.DynamicLog.
    --
    -- , ((modm              , xK_b     ), sendMessage ToggleStruts)
 
    -- Quit xmonad
    , ((modm .|. shiftMask, xK_q     ), io (exitWith ExitSuccess))
 
    -- Restart xmonad
    , ((modm              , xK_q     ), spawn "xmonad --recompile; xmonad --restart")
    ]
    ++
 
    --
    -- mod-[1..9], Switch to workspace N
    --
    -- mod-[1..9], Switch to workspace N
    -- mod-shift-[1..9], Move client to workspace N
    --
    [((m .|. modm, k), windows $ f i)
        | (i, k) <- zip (XMonad.workspaces conf) [xK_1 .. xK_9]
        , (f, m) <- [(W.greedyView, 0), (W.shift, shiftMask)]]
    ++
 
    --
    -- mod-{w,e,r}, Switch to physical/Xinerama screens 1, 2, or 3
    -- mod-shift-{w,e,r}, Move client to screen 1, 2, or 3
    --
    [((m .|. modm, key), screenWorkspace sc >>= flip whenJust (windows . f))
        | (key, sc) <- zip [xK_w, xK_e, xK_r] [0..]
        , (f, m) <- [(W.view, 0), (W.shift, shiftMask)]]
 
 
------------------------------------------------------------------------
-- Mouse bindings: default actions bound to mouse events
--
myMouseBindings (XConfig {XMonad.modMask = modm}) = M.fromList $
 
    -- mod-button1, Set the window to floating mode and move by dragging
    [ ((modm, button1), (\w -> focus w >> mouseMoveWindow w
                                       >> windows W.shiftMaster))
 
    -- mod-button2, Raise the window to the top of the stack
    , ((modm, button2), (\w -> focus w >> windows W.shiftMaster))
 
    -- mod-button3, Set the window to floating mode and resize by dragging
    , ((modm, button3), (\w -> focus w >> mouseResizeWindow w
                                       >> windows W.shiftMaster))
 
    -- you may also bind events to the mouse scroll wheel (button4 and button5)
    ]
 
------------------------------------------------------------------------
-- Layouts:
 
-- You can specify and transform your layouts by modifying these values.
-- If you change layout bindings be sure to use 'mod-shift-space' after
-- restarting (with 'mod-q') to reset your layout state to the new
-- defaults, as xmonad preserves your old layout settings by default.
--
-- * NOTE: XMonad.Hooks.EwmhDesktops users must remove the obsolete
-- ewmhDesktopsLayout modifier from layoutHook. It no longer exists.
-- Instead use the 'ewmh' function from that module to modify your
-- defaultConfig as a whole. (See also logHook, handleEventHook, and
-- startupHook ewmh notes.)
--
-- The available layouts.  Note that each layout is separated by |||,
-- which denotes layout choice.
--
myLayout = tiled ||| Mirror tiled ||| Full
  where
    -- default tiling algorithm partitions the screen into two panes
    tiled   = Tall nmaster delta ratio
 
    -- The default number of windows in the master pane
    nmaster = 1
 
    -- Default proportion of screen occupied by master pane
    ratio   = 1/2
 
    -- Percent of screen to increment by when resizing panes
    delta   = 3/100
 
------------------------------------------------------------------------
-- Window rules:
 
-- Execute arbitrary actions and WindowSet manipulations when managing
-- a new window. You can use this to, for example, always float a
-- particular program, or have a client always appear on a particular
-- workspace.
--
-- To find the property name associated with a program, use
-- > xprop | grep WM_CLASS
-- and click on the client you're interested in.
--
-- To match on the WM_NAME, you can use 'title' in the same way that
-- 'className' and 'resource' are used below.
--
myManageHook = composeAll
    [ className =? "MPlayer"        --> doFloat
    , className =? "Gimp"           --> doFloat
    , resource  =? "desktop_window" --> doIgnore
    , resource  =? "kdesktop"       --> doIgnore ]
 
------------------------------------------------------------------------
-- Event handling
 
-- Defines a custom handler function for X Events. The function should
-- return (All True) if the default handler is to be run afterwards. To
-- combine event hooks use mappend or mconcat from Data.Monoid.
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add EWMH event handling to your custom event hooks by
-- combining them with ewmhDesktopsEventHook.
--
myEventHook = mempty
 
------------------------------------------------------------------------
-- Status bars and logging
 
-- Perform an arbitrary action on each internal state change or X event.
-- See the 'XMonad.Hooks.DynamicLog' extension for examples.
--
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add EWMH logHook actions to your custom log hook by
-- combining it with ewmhDesktopsLogHook.
--
myLogHook = return ()
 
------------------------------------------------------------------------
-- Startup hook
 
-- Perform an arbitrary action each time xmonad starts or is restarted
-- with mod-q.  Used by, e.g., XMonad.Layout.PerWorkspace to initialize
-- per-workspace layout choices.
--
-- By default, do nothing.
--
-- * NOTE: EwmhDesktops users should use the 'ewmh' function from
-- XMonad.Hooks.EwmhDesktops to modify their defaultConfig as a whole.
-- It will add initialization of EWMH support to your custom startup
-- hook by combining it with ewmhDesktopsStartup.
--
myStartupHook = return ()
 
------------------------------------------------------------------------
-- Now run xmonad with all the defaults we set up.
 
-- Run xmonad with the settings you specify. No need to modify this.
--
main = xmonad defaults
 
-- A structure containing your configuration settings, overriding
-- fields in the default config. Any you don't override, will
-- use the defaults defined in xmonad/XMonad/Config.hs
--
-- No need to modify this.
--
defaults = defaultConfig {
      -- simple stuff
        terminal           = myTerminal,
        focusFollowsMouse  = myFocusFollowsMouse,
        borderWidth        = myBorderWidth,
        modMask            = myModMask,
        -- numlockMask deprecated in 0.9.1
        -- numlockMask        = myNumlockMask,
        workspaces         = myWorkspaces,
        normalBorderColor  = myNormalBorderColor,
        focusedBorderColor = myFocusedBorderColor,
 
      -- key bindings
        keys               = myKeys,
        mouseBindings      = myMouseBindings,
 
      -- hooks, layouts
        layoutHook         = myLayout,
        manageHook         = myManageHook,
        handleEventHook    = myEventHook,
        logHook            = myLogHook,
        startupHook        = myStartupHook
    }
Then I opened up ~/.xinitrc and added
exec xmonad
Installed a file manager called 'ranger' and then added it to the configuration to launch with mod + f key. Installed a terminal emulator called 'xfce4-terminal'. I might switch from it later but what the hell.
I will update this article as more changes are added to the system.

Fix fans running at full in Arch Linux vanilla (Kernel 3.18 and up)

So, the other day I was tinkering with a fresh Arch installation and the very first issue that I ran into was my fan was rotating at full blast even though there was now processor load at all. While looking for a solution I was surprised to find that there were no actual solutions on the internet to these. I followed the path of "Fan speed control" in Arch Linux wiki and but no luck. Then I installed 'powertop'
pacman -S powertop
Then I ran
powertop
Used Tab to navigate to the "Turntables" area. Then changed the states of all "Bad" to "Good" as many as possible. Saved using "Esc" and then reboot. It worked :)

UPDATE: Apparently this did not bring the crazy fan speeds down. After some browsing around, I hit a thread in the ArchBang forums where it became pretty apparent that recent Kernel changes in 3.18 have triggered the issue and still has not been resolved. So, I had to downgrade to 3.17.6 which I did by following a well written guide here. What I basically did was
a. Went to the Arch official package database
b. Located the Linux package
c. On the upper right Package Section of the page, click on View Changes. There I located an earlier version, in this case upgpkg: linux 3.17.6-1
d. Located the revision number from the line that is like "file:///srv/svn-packages@177020". That’s the revision number after the @, it might be anything. e. Then to compile 3.17.6, did the following in the terminal. CAUTION: This process might take several hours, took me around 4 hours to compile the kernel
cd ~/Downloads
mkdir linux-kernel && cd linux-kernel
svn checkout --depth=empty svn://svn.archlinux.org/packages
cd packages
svn update -r  linux
cd linux/trunk/
makepkg -g >> PKGBUILD
makepkg -s
sudo pacman -U *.pkg.tar.xz
This will install the new kernel. You might face some dependency issues where it might ask for 3.18. I removed those packages. Rebooted the PC and it was fixed.
Credits: https://ask.fedoraproject.org/en/question/31514/how-to-change-cpu-temperature-thresholds-and-control-fan-speed/
https://nims11.wordpress.com/2013/02/17/downgrading-packages-in-arch-linux-the-worst-case-scenario/

Sunday, January 18, 2015

Getting brightness keys to work on Xubuntu

Well, it's not even an original content or anything. Just noting it down since blogs always come and go. So I kept a reference.
I own a machine whose brightness keys don't work out of the box in Linux. So, I used to employ xbacklight in order to change brightness. Obviously it wasn't a good solution. It just allowed me to change to a state but not keep that state or even use the brightness controller keys. Here's a great solution that solves all of it. The initial problem: I can't change the brightness of my laptop screen with Ubuntu 13.04.
Apparent solution: xbacklight -set 41 (for a moderate brightness)
Problem: Didn't work. Xbacklight did not have any function, no matter what argument was given.
Solution: Search the line within /etc/default/grub and change it to
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash acpi_osi=Linux acpi_backlight=vendor"
After a sudo update-grub, xbacklight works as intended, and the screen brightness keys on my Laptop also work normal. Very nice. If your screen brightness changes again after reboot, you can enter the xbacklight line to the startup applications. After login, your eyes will thank you.

Credits: http://www.ryocentral.info/2013/07/getting-xbacklight-and-brightness-keys.html

Thursday, December 18, 2014

Postgresql different syntaxes

As I am currently working on a project involving PostgreSql, I came to learn some very important commands that I use. here's a list of those commands.

Connect Rapoo MT750S with Linux (Tested on Manjaro)

 I bought this obvious copy of MX Master 2S in hopes of having the device switching functionality along with a lightweight body because I ha...