sudo apt-get install youtube-dl libavcodec-extra-53 youtube-dl --extract-audio --audio-format mp3 -l http://www.youtube.com/watch?v=qzYAqscEUC8
2013-10-18
How to Youtube to mp3 on Ubuntu
2012-12-07
Swedish post tracking cron job
/usr/local/bin/post-check
crontab -e
#!/bin/bash
# Script arguments
# argument 1 - package number, i.e. 012345670001234567
# argument 2 - mail address for package status updates
nr=$1
to=$2
# Swedish post perma-link
link="http://server.logistik.posten.se/servlet/PacTrack"
link="$link?lang=GB&xslURL=/xsl/pactrack/standard.xsl&kolliid=$1"
# Script saves status updates into temp dir
cd /tmp/
# Send the mail
# argument 1 - subject
# argument 2 - message
function send_mail() {
# arg1 subject
echo "$2" | mail -s "$1" \
-a "MIME-Version: 1.0" \
-a "Content-Type: text/html" \
"$to"
}
# Download package latest status
wget "$link" -q -O post-status.new
if [ $? -ne 0 ]; then
error="Could not download package status."
echo "$error Mail sent."
send_mail "Package $nr status error" "$error"
exit
fi
# Make sure both current and previous status file exists
touch post-status.new
touch post-status.old
# Check if there is a difference in two last status sizes
new_size=$(stat -c%s post-status.new)
old_size=$(stat -c%s post-status.old)
if [ $new_size -ne $old_size ]; then
echo "Package status updated. Mail sent."
send_mail "Package $nr status updated" "`cat post-status.new`"
fi
# Save the status
cp post-status.new post-status.old
crontab -e
*/15 * * * * /usr/local/bin/post-check 012345670001234567 your@mail.com
2012-08-10
Lua output redirection
While ago I was working on Lua based implementation of the scripting library. One of the requirements was a total control of output and error messages, to allow it's automatic handling. One of the issues I've faced is that some output was going to stdout even if there is redefined print Lua function.
I thought about two quick solutions:
- redirect standard streams;
- redefine printf and it's adjacent functions.
Since standard streams, both stdout and stderr, in my case were already redefined (for remote debugging purposes), I didn't had much to choose from.
Looking into Lua 5.1 sources, I've found that stdout was simply hard-coded in some places. During up-streaming this patch to Lua 5.2 surprisingly most of the hard-coded stream names went away, and it looks like it would be possible to use redefined print without losing anything. I haven't tested this though. Following just works for Lua 5.1.x and above.
I thought about two quick solutions:
- redirect standard streams;
- redefine printf and it's adjacent functions.
Since standard streams, both stdout and stderr, in my case were already redefined (for remote debugging purposes), I didn't had much to choose from.
Looking into Lua 5.1 sources, I've found that stdout was simply hard-coded in some places. During up-streaming this patch to Lua 5.2 surprisingly most of the hard-coded stream names went away, and it looks like it would be possible to use redefined print without losing anything. I haven't tested this though. Following just works for Lua 5.1.x and above.
2012-08-08
Manually adding missing apt public keys
When apt-get update starts complaining about missing public keys, it's always pain in the ass when you're behind proxy and gpg --recv-keys doesn't work. Following is the manual way of adding missing apt public keys:
1. Obtain public key via browser:
3. Import the key file in System->Administration->Software Sources
1. Obtain public key via browser:
http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x[KEY]2. Save the key.
3. Import the key file in System->Administration->Software Sources
2012-06-12
How-to add a permanent network interface alias on Ubuntu 10.04 and higher
1. Add network interface alias by adding following into /etc/network/interfaces:
2. Create a new file and place it in /etc/network/if-up.d/:
3. Restart network via Network Manager or command line:
# Alias interface auto eth0:0 iface eth0:0 inet static address 192.168.1.1 netmask 255.255.255.0
2. Create a new file and place it in /etc/network/if-up.d/:
#!/bin/bash
if [ "$IFACE" = "eth0" ]; then
/sbin/ifup --force eth0:0
fi
3. Restart network via Network Manager or command line:
sudo /etc/init.d/networking restart
2011-12-16
Nine-patch Bitmaps on Android
Excerpt from new Android Training by Google:
Supporting different screen sizes usually means that your image resources must also be capable of adapting to different sizes. For example, a button background must fit whichever button shape it is applied to.
If you use simple images on components that can change size, you will quickly notice that the results are somewhat less than impressive, since the runtime will stretch or shrink your images uniformly. The solution is using nine-patch bitmaps, which are specially formatted PNG files that indicate which areas can and cannot be stretched.
Therefore, when designing bitmaps that will be used on components with variable size, always use nine-patches.
Supporting different screen sizes usually means that your image resources must also be capable of adapting to different sizes. For example, a button background must fit whichever button shape it is applied to.
If you use simple images on components that can change size, you will quickly notice that the results are somewhat less than impressive, since the runtime will stretch or shrink your images uniformly. The solution is using nine-patch bitmaps, which are specially formatted PNG files that indicate which areas can and cannot be stretched.
Therefore, when designing bitmaps that will be used on components with variable size, always use nine-patches.
2011-11-08
Multiple gcc versions on Ubuntu machine
# let the beast in su # install the older gcc versions apt-get install gcc-4.4 apt-get install g++-4.4 # configure update-alternatives --remove-all gcc update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.4 44 --slave /usr/bin/g++ g++ /usr/bin/g++-4.4 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.4 update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.6 46 --slave /usr/bin/g++ g++ /usr/bin/g++-4.6 --slave /usr/bin/gcov gcov /usr/bin/gcov-4.6 # switch gcc update-alternatives --config gcc
2011-09-26
git user configuration override
In case if it's required to have a different user configuration from the one stored in .gitconfig, there is two possible ways to achieve this:
Local (per git)
This method will override default or git's user configuration. Add following to .bashrc:
Local (per git)
$ cd git-repo $ git config user.name "Name Surname" $ git config user.email "name.surname@domain.com"Global
This method will override default or git's user configuration. Add following to .bashrc:
function gitswitch () {
case "$1" in
"custom")
export GIT_AUTHOR_EMAIL="name.surname@domain.com"
export GIT_AUTHOR_NAME="Name Surname"
export GIT_COMMITTER_EMAIL="name.surname@domain.com"
export GIT_COMMITTER_NAME="Name Surname"
echo "Using custom configuration."
;;
"default")
unset GIT_AUTHOR_EMAIL
unset GIT_AUTHOR_NAME
unset GIT_COMMITTER_EMAIL
unset GIT_COMMITTER_NAME
echo "Using default configuration from .gitconfig."
;;
*)
echo "Bad argument - please specify 'custom' or 'default'."
;;
esac
}
And then:$ gitswitch custom Using custom configuration. $ gitswitch default Using default configuration from .gitconfig. $ gitswitch ? Bad argument - please specify 'custom' or 'default'.
2011-08-29
To Go or not to Go?
Apparently Go language makes more and more community attention. Today made a 15 min try and was surprised how simple and fast you can get into it.
Surprisingly, there is bindings for GTK which allows to write GUI apps for both Linux and Windows, and one of the demos looks as simple as:
Surprisingly, there is bindings for GTK which allows to write GUI apps for both Linux and Windows, and one of the demos looks as simple as:
package main
import (
"os"
"github.com/mattn/go-gtk/gtk"
"fmt"
)
func main() {
gtk.Init(&os.Args)
window := gtk.Window(gtk.GTK_WINDOW_TOPLEVEL)
window.SetTitle("GTK Table")
window.Connect("destroy", gtk.MainQuit)
swin := gtk.ScrolledWindow(nil, nil)
swin.SetPolicy(gtk.GTK_POLICY_AUTOMATIC, gtk.GTK_POLICY_AUTOMATIC)
table := gtk.Table(5, 5, false)
for y := uint(0); y < 5; y++ {
for x := uint(0); x < 5; x++ {
table.Attach(gtk.ButtonWithLabel(fmt.Sprintf("%02d:%02d", x, y)),
x, x+1, y, y+1, gtk.GTK_FILL, gtk.GTK_FILL, 5, 5)
}
}
swin.AddWithViewPort(table)
window.Add(swin)
window.SetDefaultSize(200, 200)
window.ShowAll()
gtk.Main()
}
2011-07-29
2010-03-09
OpenPGP key generation for GnuTLS
Create key pair. Write down the key number.
gpg --gen-keyEdit the key with the command below.
gpg --edit-key 1F8D4A4CIn gpg prompt enter passwd and specify empty password, type quit.
gpg --armor --export 1F8D4A4C> public.key gpg --armor --export-secret-keys 1F8D4A4C> secret.keyDelete keys from keyrings if required.
gpg --delete-secret-keys 1F8D4A4C gpg --delete-keys 1F8D4A4C
2010-02-24
2009-12-04
Subversion repository part migration
svnadmin dump /srv/svn/old-repo | svndumpfilter include --drop-empty-revs --renumber-revs /directory-name > directory.svndump svnadmin load /srv/svn/new-repo < directory.svndumpPlease note, that if directory structure needs to be changed (for example, from /old-repo/projects/dir to /new-repo/dir) manual edit of dump file will not help. Instead, sed must be combined with svndumpfilter. Additional info regarding this topic can be found here.
2009-12-03
Virtualbox 3.1.x Linux guest dead keyboard fix
After new release of Virtualbox was installed and my virtual machine with OpenSUSE on-board had started, I've ended up with a dead keyboard. It worked fine on Windows XP as host, but OpenSUSE VM was acting like there is no keyboard at all. Couple of minutes of brain activity and finger work I've found that /etc/X11/xorg.conf was replaced during Virtualbox Guest Additions update. Comparing xorg.conf between two latest VB releases, I was able to get the keyboard working. Here is a fix:
1. Restore old xorg.conf :
3. Add Option "CorePointer" to InputDevice section of Mouse[1]
4. Add Option "SendCoreEvents" to InputDevice section of Mouse[2]
5. Rename Device option from InputDevice section of Mouse[2] from /dev/vboxadd to /dev/vboxguest
1. Restore old xorg.conf :
cp /etc/X11/xorg.conf.bak /etc/X11/xorg.conf2. Add Option "CoreKeyboard" to InputDevice section of Keyboard[0]
3. Add Option "CorePointer" to InputDevice section of Mouse[1]
4. Add Option "SendCoreEvents" to InputDevice section of Mouse[2]
5. Rename Device option from InputDevice section of Mouse[2] from /dev/vboxadd to /dev/vboxguest
2009-10-28
2009-09-17
How to change language in GIMP on Windows
After installing GIMP on my laptop I've found it's language is set according to my regional settings. However, I have failed trying to change it to english because there is no visible configuration option for that. Now that's weird!
After googling for few minutes I've found that this is not a GIMP problem but rather GTK+ for Windows and to force it to use english translation by default you need to add lang environment variable with the value of c.
After googling for few minutes I've found that this is not a GIMP problem but rather GTK+ for Windows and to force it to use english translation by default you need to add lang environment variable with the value of c.
2009-09-14
Removing MinGW dll dependencies
libgcc_s_dw2-1.dll
Passing -static-libgcc will remove this dependency for all languages other than C.
Note: C++ exceptions depends on this option.
mingwm10.dll
Remove -mthreads option from your makefile.
Note: Multithreading and C++ exceptions depends on this option.
Passing -static-libgcc will remove this dependency for all languages other than C.
Note: C++ exceptions depends on this option.
mingwm10.dll
Remove -mthreads option from your makefile.
Note: Multithreading and C++ exceptions depends on this option.
2009-09-09
How to set up library paths for configure
env CPPFLAGS="-I/opt/local/include" LDFLAGS="-L/opt/local/lib" ./configure
2009-08-26
How to remove absolute path in svn+ssh
As you may or may not know there is a path difference between svn and svn+ssh links in case if subversion server is configured with default root directory:
/etc/sysconfig/svnserve
/etc/sysconfig/svnserve
SVNSERVE_OPTIONS="-d -R -r /path-to-repos"This way repository can be checked out using following commands (consider ssh is set up and working):
svn co svn://server.com/repository directoryor
svn co svn+ssh://server.com/path-to-repos/repository directory
Subscribe to:
Posts (Atom)