Saturday, June 7, 2014

Force google-chrome to start new session

This command will force Google Chrome to start a new session, and disables any proxy settings you currently have

google-chrome --user-data-dir=/tmp --no-proxy-server

Thursday, June 5, 2014

Data portals

http://data.gov

SOCKS proxy with firefox about:config and ssh

A simple socks proxy can be made as follows

First, open Firefox and type about:config in the address bar

change the following items

network.proxy.socks localhost
network.proxy.socks_port 4321

network.proxy.type 1
network.proxy.socks_remote_dns true

ssh to your favorite machine with the -D flag
i.e.

ssh -D 4321 root@myserver.com

This will setup a SOCKS proxy to myserver.com and also protect your DNS requests

Links:
http://bityard.blogspot.fr/2009/01/make-openssh-socks-proxy.html

Unmount busy filesystem and find process linux

sudo umount /mntumount: /mnt: device is busy.
        (In some cases useful info about processes that use
         the device is found by lsof(8) or fuser(1))

lsof /mntCOMMAND   PID     USER   FD   TYPE DEVICE SIZE/OFF NODE NAME
bash            19005       user  cwd DIR   8,17        4096         2           /mnt


sudo kill -9 19005

Set iptables rulesets

Redirecting traffic to different ports - in this caser, redirect standard http requests and https requests to a server which doesn't run as root (all ports < 1000 require root access)

sudo iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-port 8080
sudo iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-port 8443


To show the new rules, do

iptables -t nat --list

Setting up emacs24 and clojure starter kit

Ubuntu

sudo add-apt-repository ppa:cassou/emacs
sudo apt-get update
sudo apt-get install emacs-snapshot

Once the ppa and emacs are installed, start emacs by doing emacs-snapshot. Hit C-x C-f (Ctrl and x, then Ctrl and f) and type in the path ~/emacs.d/init.el . Add the following text to this file

(require 'package)
(add-to-list 'package-archives
             '("marmalade" . "http://marmalade-repo.org/packages/") t)
(package-initialize)

Now do M-x eval-buffer, then M-x package-refresh-contents, then M-x package-install. When prompted, type starter-kit. Now you are off! I also installed starter-kit-lisp

Most of the above information is just parroting the information found at the following links.

Installing EVIL mode for VIM keys

M-x package-install RET evil RET 

M-x package-install RET evil-leader RET

M-x package-install RET evil-numbers RET 


Now add the following line to ~/.emacs.d/init.el

(evil-mode 1) 
Other packages

auto-complete

auto-indent-mode


Links

https://github.com/technomancy/clojure-mode/blob/master/doc/gnu-linux-setup.md

https://github.com/technomancy/emacs-starter-kit

http://www.emacswiki.org/emacs/Evil

Using evolution with an exchange server

First, install the evolution, evolution-mapi, and evolution-exchange packages. On CentOS 6.3, this was accomplished by the command sudo yum install evolution evolution-mapi evolution-exchange.

When setting up the account, select Exchange MAPI for the Server Type on the Receiving Email tab. It may also be necessary to use the IP address of your Exchange server, instead of the name. The domain name should be the prefix you normally see on your Windows login i.e. WONDERCO/jdoe could be

Server: 192.168.1.101

Username: jdoe

Domain name:WONDERCO


IMPORTANT: Before you click View->Calendar, disable the "Prefer Plain Text" plugin by going to Edit->Plugins, then unchecking the "Prefer Plain Text" box. I didn't do this, and got trapped in the calendar, which would freeze evolution every time it was launched. If this happens, reset your settings by following the instructions at the link below.

http://www.samlesher.com/tag/delete-evolution-settings


Links

https://www.linux.com/learn/tutorials/370590:connect-evolution-to-an-exchange-server

http://mylinuxnotebook.blogspot.com/2008/09/evolution-ms-outlook-invitation.html

Get full kernel source for CentOS 6.X and compile against it

First, follow the instructions from the link below to get the full kernel source. To confirm that this was actually a complete kernel, I also performed a make in ~/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/ . This compiled the entire kernel, and proved to me that this was the full kernel source (unlike the packages kernel-devel and kernel-headers).

http://wiki.centos.org/HowTos/I_need_the_Kernel_Source

Once the "test build" was complete, I needed to build my kernel module against that kernel source. This was accomplished by doing ./configure --kernel-source-path=/home/myname/rpmbuild/BUILD/kernel-2.6.32-220.23.1.el6/ , followed by make && make install

Transferring files with netcat

On the destination server, set up a listen port by doing nc -l PORT > FILENAME, where PORT is the listen port to connect to, and  FILENAME is the filename you want to have on the destination server. This could be any number, but you probably want it to be >1000 due to Linux rules about ports.

Now on the source server, do

nc IP PORT < FILE, where IP is the ip of the destination server, PORT is the same as above, and FILE is name of the file to transfer.

An example, with IP = 192.168.10.5, PORT = 9001, FILE=backup.iso

Destination:

nc -l 9001 > backup.iso

Source:

nc 192.168.10.5 9001 < backup.iso
http://www.g-loaded.eu/2006/11/06/netcat-a-couple-of-useful-examples/

Changing finch keybindings

Switching to XMonad can create a keybinding conflict with Finch. To correct this, create a file named ~/.gntrc with the following text

[GntWM::binding]
c-n = window-next
c-p = window-prev
c-r = start-resize
c-t = start-move                
  

https://developer.pidgin.im/wiki/Using%20Finch

Add a buddy in finch (commandline pidgin)

Press Ctrl-o (also written c-o) to access the actions windows, where you can add buddies, plugins, and other things

Install Skype on ubuntu 12.10


After downloading the 64 bit Ubuntu 10.04 .deb package from skype.com, I tried to install with dpkg -i

sudo dpkg -i skype-ubuntu_4.0.0.8-1_amd64.deb

This returned with:


dpkg: dependency problems prevent configuration of skype:
 skype depends on lib32stdc++6 (>= 4.1.1-21); however:
  Package lib32stdc++6 is not installed.
 skype depends on lib32asound2 (>> 1.0.14); however:
  Package lib32asound2 is not installed.
 skype depends on ia32-libs; however:
  Package ia32-libs is not installed.
 skype depends on libc6-i386 (>= 2.7-1); however:
  Package libc6-i386 is not installed.
 skype depends on lib32gcc1 (>= 1:4.1.1-21+ia32.libs.1.19); however:
  Package lib32gcc1 is not installed.


To get skype working properly, the following steps must be taken


sudo dpkg -r ia32-libs

sudo apt-get update

sudo apt-get install -f



After this, running

sudo dpkg -i skype-ubuntu_4.0.0.8-1_amd64.deb


should install skype.

http://askubuntu.com/questions/212175/i-cant-install-skype

Setting power to suspend on XMonad laptop

You will need the acpi program for this change to work - do a

sudo apt-get install acpi


After this, simply change the line in /etc/acpi/lid.sh that says

. /usr/share/acpi-support/screenblank

to

echo -n mem > /sys/power/state

http://ubuntuforums.org/showthread.php?t=1366830

Adding a .cls file to latex

Add a line to ~/.bashrc that points to your .cls files

The . in front is critical to source the current directory

For example, my github (http://www.github.com/kastnerkyle/Papers/) has an IEEEtran file that has the IEEE standard template inside. To use it, simply add this line to ~/.bashrc

export TEXINPUTS=.:<path_to_IEEEtran_file>:$TEXINPUTS

now running texi2pdf should compile IEEE format .tex files

Fixing matlab under XMonad

After switching to XMonad, I still couldn't get MATLAB to work properly

The fix is to add the line

import XMonad.Hooks.SetWMName

at the top of xmonad.hs, and then

startupHook = setWMName "LG3D"

under the defaultConfig section of xmonad.hs

http://www.haskell.org/haskellwiki/Xmonad/Frequently_asked_questions

Make mac boootable USB in Ubuntu

Put in a USB device, then do

dmesg | tail

Depending on what /dev/sdX device is listed, do

mkfs.vfat /dev/sdX -I


Note, the above command WILL wipe the USB drive!

Now take the downloaded .ISO, and do

dd of=/dev/sdX if=<path_to_.iso> bs=1M

Reboot the Mac, while holding Alt. A boot prompt should come up and allow you to boot from the USB.

Set custom videomode for correct resizing of virtualbox guest OS

First, you will need to install the Guest Additions for the VM you wish to resize. For most Linux VMs, this requires installing the latest kernel and kernel headers. To get the kernel and  kernel headers in CentOS, run sudo yum -y install kernel kernel-devel


Once this is done, reboot the VM. This should use the latest kernel (which was just installed) allowing for successful building of the main Guest Additions module. To build the Guest Additions, go to Devices->Install Guest Additions in the Virtualbox menu. You should now be able to autorun the Guest Additions software (it should show up as a CD) in the VM. There may still be other issues, typically OpenGL fails to build, but generally the main Guest Additions module is all that is necessary for screen resizing.


vboxmanage setextradata "Z7" "CustomVideoMode1" "1280x650x32"

Where Z7 is the name of the VM, and 1280x650x32 is the custom resolution you desire. In Ubuntu, you can take a stab at what your monitor resolution is by running xrandr. You can get a list of VM names by doing

vboxmanage list vms


https://forums.virtualbox.org/viewtopic.php?f=6&p=105958

Change screen brightness from commandline

There is usually a program /usr/bin/intel_backlight that will allow you to set the backlight setting

/usr/bin/intel_backlight xx

where xx is some value between 0 and 100

For older systems, use

sudo setpci -s 00:02.0 f4.b=xx


where xx is 00-FF, and 00:02.0 is my VGA display device as shown by lspci

Alternatively, for newer devices which use the intel_backlight interface, use this command

echo xx | sudo tee /sys/class/backlight/intel_backlight/brightness


where xx is anything from 0 (this will blank out your screen...) to whatever is displayed by cat /sys/class/backlight/intel_backlight/max_brightness

Though it changes more than just brightness, the command


xgamma -gamma xx


where xx is anywhere from 0->1.5 will also change the screen. You can go higher than 1.5, but I haven't tried anything higher.

http://wilmor24.wordpress.com/2010/05/11/change-screen-brightness-from-terminal-ubuntu-10-04/

https://bbs.archlinux.org/viewtopic.php?id=137164

Cronjob to change screen brightness

Tired of your backlight resetting every time you boot your laptop or set it to hibernate? Create a new file containing the following content in /usr/local/bin, and name the file check_backlight

#!/bin/bash
WAIT_TIME=3

LOOP_COUNTER=$\$$((60/$WAIT_TIME))

for i in `seq 1 $\$$LOOP_COUNTER`; do

    DESIRED_BRIGHTNESS=22

    BRIGHTNESS_COMMAND='/usr/bin/intel_backlight '

    BRIGHTNESS_PERCENTAGE=`$\$$BRIGHTNESS_COMMAND | awk '{print $\$$(NF)}'`
    BRIGHTNESS=$\$${BRIGHTNESS_PERCENTAGE%'%'}
    if [ $\$$BRIGHTNESS -ne $\$$DESIRED_BRIGHTNESS ]; then
        BRIGHTNESS_COMMAND+=$\$$DESIRED_BRIGHTNESS

        eval $\$$BRIGHTNESS_COMMAND
    fi
    sleep $\$$WAIT_TIME

done



Now add the following line to /etc/crontab

* *     * * *   root    /bin/bash /usr/local/bin/check_backlight


This entry in crontab will run the script /usr/local/bin/check_backlight every minute. The check_backlight script loops for 60 seconds, checking the backlight every WAIT_TIME seconds.

Setup fake ethernet device with any MAC address

sudo modprobe dummy
sudo ip link set name eth0 dev dummy0

sudo ifconfig eth0 hw ether 00:24:49:03:1a:72

http://www.question-defense.com/2012/11/26/linux-create-fake-ethernet-interface

Launch matlab in 32bit mode

matlab -glnx86

Add ssh key for GitHub

ssh-keygen -t rsa -C <email here>

sudo apt-get install xclip


xlip -sel clip < ~/.ssh/id_rsa.pub

Now just add the key through the github interface
To make the repo push over ssh

git remote rm origin
git remote add origin git@github.com:your_username/your_project.git


To add the upstream repo and synch with it

git remote add upstream https://github.com/upstream_name/project.git
git fetch upstream
git checkout master
git pull --rebase upstream master

https://help.github.com/articles/generating-ssh-keys

Find key maps in XMonad

Running the program xev and then looking at the output can tell you the key mapping for a key to put in xmonad.hs
http://ubuntuforums.org/archive/index.php/t-1755109.html

http://www.haskell.org/haskellwiki/Xmonad/Key_codes

Add user to vboxusers group to enable VM USB support

sudo usermod -a -G vboxusers $USER

Create a pdf from many images

convert *.jpg images.pdf

http://dancingpenguinsoflight.com/2010/02/converting-multiple-images-to-one-pdf-on-linux/

Adding latex support to a blog (like this one!)

To add LaTeX support to a Blogger.com blog, simply add this script under your Layout->HTML/JavaScript settings

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js"> MathJax.Hub.Config({ extensions: ["tex2jax.js","TeX/AMSmath.js","TeX/AMSsymbols.js"], jax: ["input/TeX", "output/HTML-CSS"], tex2jax: { inlineMath: [ ['$\$$','$\$$'], ["\(","\)"] ], displayMath: [ ['$\$$$\$$','$\$$$\$$'], ["$\backslash [$","$\backslash ]$"] ], }, "HTML-CSS": { availableFonts: ["TeX"] } });< /script>


I have forgotten where I got this tip, but whoever originally posted this - thank you!

Resize many gif images using imagemagick

for i in *.gif; do convert $\$$i -resize 400x400 $\$$(basename $\$$i .gif).gif; done

wget files of a certain type in all subdirectories

wget -r -A .gif <website>

Show status of dd command

Run dd with something like

sudo dd if=/dev/zero of=/dev/sdx

Now in another terminal, do ps ax| grep dd

Look at the process id (first column) of the dd command

Use that process id as input for

sudo kill -SIGUSR1 <pid>

This will force dd to print a status update

http://serverfault.com/questions/4906/using-dd-for-disk-cloning

PXE boot args for disabling nouveau

Doing lsmod | grep nouveau showed nouveau drivers being loaded, even though I had the following PXE boot args

append initrd=myrd.gz root=/dev/ram0 rdblacklist=nouveau nouveau.modeset=0 init=/bin/init ramdisk_size=800000 ramdisk_blocksize=1024 rw
Noveau was still loading, but adding nouveau.blacklist=1 solved it, like so:

append initrd=myrd.gz root=/dev/ram0 nouveau.blacklist=1 rdblacklist=nouveau nouveau.modeset=0 init=/bin/init ramdisk_size=800000 ramdisk_blocksize=1024 rw

There is also a nouveau.disable=1 option, which I did not try
http://fedora.12.x6.nabble.com/Problems-removing-nouveau-in-fed-18-td4993336.html

Make a bootable USB

Copy the .iso file to /dev/sdx (NOT /dev/sdx1)

dd bs=4M if=/path/to/iso of=/dev/sdx

When finished, make sure to zero out the boot record and non-standard partition table:

dd count=1 bs=512 if=/dev/zero of=/dev/sdx

https://wiki.archlinux.org/index.php/USB_Installation_Media

Making a pdf from an IPython notebook

With the latest ipython one can run ipython nbconvert latex mynotebook.ipynb. The latest ipython can currently be installed from https://github.com/ipython/ipython, at the time of this writing this is the 1.0 development stream.


ipython nbconvert latex mynotebook.ipynb will result in a latex file. texi2pdf should then be able to convert this tex file into a viewable pdf - in my case I had to manually copy all the files and images out of the associated mynotebook_files directory to the same directory as the .tex file, both of which were generated by ipython nbconvert. If you encounter latex errors, see http://www.tug.org/texlive/acquire-netinstall.html for installation instructions for the latest latex. The default Ubuntu texlive package (as of 13.04 at least) is not recent enough to perform the conversion!

Copy files over ssh

dd if=input | ssh login@remotehost "dd of=output"

Wednesday, June 4, 2014

Inspect disk statistics with smartctl

smartctl -a -d megaraid,0 /dev/sdx

Compile Ubuntu packages from source

apt-get source <package> (NOTE: no sudo!)

sudo apt-get build-dep <package>


http://askubuntu.com/questions/28372/how-do-i-get-the-source-code-of-packages-installed-through-apt-get

Update firmware for older Dell servers

Download the CentOS LiveDVD from here: http://linux.dell.com/files/openmanage-contributions/om-firmware-live/

next, copy it to a usb drive with dd:

sudo dd if=<path to CentOS iso> of=/dev/<my usb drive> bs=4096

This image should have all the latest firmware built into it. I used this to update BMC firmware for the Dell R900.

There is a blog by Dell about this procedure as well, shown here:

http://en.community.dell.com/techcenter/b/techcenter/archive/2011/08/17/centos-based-livedvd-to-update-firmware-on-dell-servers.aspx

OpenWRT on DIR 601 Rev B1

Have to use the NA file, because the other file won't get recognized as firmware.

Once that is done, telnet into 192.168.1.1 to set up OpenWRT

uci del wireless.@wifi-device[0].disabled

uci del wireless.@wifi-iface[0].network

uci set wireless.@wifi-iface[0].mode=sta

uci commit wireless

wifi

iw wlan0 scan


then follow the steps here

http://wiki.openwrt.org/doc/recipes/routedclient#using.masquerade

Make sure to change the LAN settings to a subnet not shared by the "mothership" router! And also encryption type is PSK2 for WPA/WPA2 mixed mode - iw wlan0 scan did not show the same output as the steps on the page.

To change the default LAN IP of the D-Link network, simply edit /etc/config/network

http://downloads.openwrt.org/snapshots/trunk/ar71xx/openwrt-ar71xx-generic-dir-601-b1-squashfs-factory-NA.bin

http://wiki.openwrt.org/doc/howto/clientmode

http://gradengineering.blogspot.com/2013/09/basic-setup-of-openwrt-on-dir-601-b1.html

Get full structure of website

wget \
     --recursive \
     --no-clobber \
     --page-requisites \
     --html-extension \
     --convert-links \
     --restrict-file-names=windows \
     --domains reddit.com\
     --no-parent \
         www.reddit.com