git config --global core.autocrlf false
git config --global core.eol lf
Friday, April 23, 2021
Unix line endings in windows under git
Monday, June 8, 2020
git svn
"Cherry pick" all changes required to make same as another branch:
git merge --squash -X theirs <other_branch>
Makes no commit, but stages all changes
Monday, February 3, 2020
Git project branch and directory info
To get the Git top level, or root, of the repo:
git rev-parse --show-toplevel
Get the current current branch name:
git rev-parse --abbrev-ref HEAD
Get the current working directory relative to project root:
echo "${PWD##$(git rev-parse --show-toplevel)}"
Get the current working directory relative to project root and the branch name in one line:
echo "${PWD##$(git rev-parse --show-toplevel)} [$(git rev-parse --abbrev-ref HEAD)]"
Wednesday, August 23, 2017
Getting pulseaudio volume for default sink, once and for all
This was done with pulseaudio 8.0
So, here it is:
echo $(( ($(pacmd list-sinks | sed -n -e "/$(pacmd stat | grep "Default sink name" | cut -d ' ' -f4)/,\$p" | grep -m1 volume | cut -d '/' -f2,4 | tr -d '% ' | tr '/' '+')) / 2 ))
Wow.. that's a mouthful. Let's break it down...
Wednesday, May 17, 2017
Drive images with progress indication
# make a drive image
sudo bash -c "pv -EE /dev/sdX >my_disk.img"
# make a compressed drive image
sudo bash -c "pv -EE /dev/sdX | gzip >my_disk.img.gz"
Monday, June 13, 2016
Resizing a VirtualBox disk image
This should go without saying, but make sure you have a good backup of everything before you do any of this.. If in doubt, just backup the whole VirtualBox folder. You have been warned.
Sunday, May 1, 2016
Configuring Gnome-Shell from the command line
Here's some useful tricks to automate the configuration of the gnome shell
Ubuntu-Gnome 16.04 on Thinkpad x230
This is mostly for myself, but perhaps someone else might get some ideas from it..
Tuesday, April 26, 2016
Edit gnome settings with your favorite editor
Using the vipe command, we can read from stdin, edit the contents in the default editor and send it down the pipe.
Saturday, March 26, 2016
find files from a certain date range in linux
When you need to find a file from a specific range of dates, like a reciept that you know you saved but can't remember where.. You can use the find command along with some parameters to find files newer than a specific date, older or between two dates.
Bash one-liner to fix "Failed to fetch" error for chrome in ubuntu
See this page for details on how an why, but here's the error:
W: Failed to fetch http://dl.google.com/linux/chrome/deb/dists/stable/Release:
Unable to find expected entry 'main/binary-i386/Packages'
in Release file (Wrong sources.list entry or malformed file)
And this will fix it in one shot:
sudo sed -i 's?deb http://dl.google.com/linux/chrome/deb/ stable main?deb [arch=amd64] http://dl.google.com/linux/chrome/deb/ stable main?g' /etc/apt/sources.list.d/google-chrome.list
Sunday, March 13, 2016
bash functions to view markdown documents
If you're writing markdown documents from vim or emacs, here's a couple handy ways to view them as rendered HTML.
Saturday, March 12, 2016
Kill an ssh connection from the server side
So you don't like Bob today or maybe you want to test a failed connection.. Whatever your reason you need to kill the ssh connections for his user on your server.
Friday, March 11, 2016
Reverse SSH Forward with special user
Tuesday, January 26, 2016
Make better bash scripts for yourself (and others)
When you write a bash script, there's a few things you can do to make your life (and anyone else who uses it) a lot better. Here's a few of the things that I (try) to do when I write scripts to make it easier to use and less error prone.
Sunday, January 17, 2016
Ditch capslock for escape in xwindows
xmodmap -e 'clear Lock' -e 'keycode 0x42 = Escape'
Taken from this post on the vim wiki
Tuesday, March 17, 2015
Print the current tag OR commit in git
# prints tag name or short revision
git name-rev --tags --name-only --no-undefined --always $(git rev-parse HEAD)
Monday, March 16, 2015
Multiple test programs, one makefile
Friday, November 14, 2014
git lsd – For when you don't want to use gitk --all
git log --graph --boundary '--format=%C(yellow)%h%Creset%C(bold cyan)%d%Creset %s %C(dim normal)(%ar)%Creset' --allThis will output something like this (depending on your terminal color settings):
* 4b22a90 (HEAD, master) erases chip before programming (2 days ago) * ee107af Merge branch 'sysclk' (2 days ago) |\ | * e9df6f6 removes clk config to use defaults (2 days ago) | * 66a1ea3 fixes clkout pin timing (2 days ago) | * bcdda54 enables PLL @ 16MHz (internal 2MHz x 8) (2 days ago) | * cd22bab enables the 32KHz rc for system clock (2 days ago) | * cee8efd enables the internal 32MHz rc for sysclk (2 days ago) | * aa10b4d enables 2MHz internal rc osc for sysclk (2 days ago) | * 80cbade re-defines F_CPU (2 days ago) |/ * 0644c9d Merge branch 'diagnostics' (3 days ago) |\ | * b9e155d adds SYSCLK/10000 on pin A0 (3 days ago) | * 57807ab adds blinky led (3 days ago) |/ * 5cfc996 basic skeleton (3 days ago)Of course you can mess with the format and colors, but this is how I like it. Once you have it set the way you like it, alias it for later use!
git config --global alias.lsd "log --graph --boundary '--format=%C(yellow)%h%Creset%C(bold cyan)%d%Creset %s %C(dim normal)(%ar)%Creset' --all"Now you can just type git lsd and have a quick overview of your commits.
Wednesday, October 15, 2014
Xmega DFU Programming in Linux
I'm using elementary OS 0.2 and have an MT-DB-X4 development board from MattairTech with an ATxmega32A4U — so you may need to adjust the following commands to suit your particular setup.
Install dfu-programmer
First we need to install some prerequisites:
$> sudo aptitude install libusb-1.0-0 libusb-1.0-0-dev
Then, download and extract the source:
$> wget -qO- "http://sourceforge.net/projects/dfu-programmer/files/dfu-programmer/0.7.0/dfu-programmer-0.7.0.tar.gz/download" | tar xvzNow configure, make, make install:
#!/bin/bash cd dfu-programmer-0.7.0 ./configure --prefix=$HOME/.local # This will install to your home make # Compile make install # Install
Now we can test it out. Plug in your device and run the following (change the device to match your chip):
$> sudo ~/.local/bin/dfu-programmer atxmega32a4u get Bootloader Version: 0x04 (4)
Finally, we need to add ~/.local/bin to our PATH so we can just type dfu-programmer:
#!/bin/bash
# check to see if it's already in PATH
echo $PATH | grep -v "$HOME/\.local/bin" > /dev/null &&
cat << EOF >>~/.profile
# set PATH so it includes user's private .local/bin if it exists
if [ -d "\$HOME/.local/bin" ] ; then
PATH="\$HOME/.local/bin:\$PATH"
fi
EOF
Remember, you need to logout and back in before the changes to your groups and .profile take effect.
Setup udev rules and permissions
When you first plug the device in, udev will only allow access to the root user by default. To change this we need to let udev know that we want to give access to the device to users in a certain group — plugdev in this case.
To start, check to see if you're already in the plugdev group:
$> groupsIf not, you'll need to add yourself:
$> sudo usermod -a -G plugdev $USER
Next, we need to add a rules file to tell udev which group to add the device to. To get the device info, run lsusp to get the vendor and product IDs:
$> lsusb | grep AtmelThis should output something like the following:
Bus 005 Device 003: ID 03eb:2fe4 Atmel Corp.Note the first and second parts of the ID
Now that we have the IDs, we can make the udev rule file and restart udev:
#!/bin/bash
sudo bash -c 'cat << EOF >/lib/udev/rules.d/12-atmel.rules
# atxmega32a4u with DFU Bootloader
SUBSYSTEM=="usb", ACTION=="add", ATTRS{idVendor}=="03eb", ATTRS{idProduct}=="2fe4", GROUP="plugdev"
EOF
service udev restart'
Now just unplug and replug your device and you should be able to access it without root:
$> dfu-programmer atxmega32a4u get Bootloader Version: 0x04 (4)