Home
April 27, 2012

CLI Volume control

I couldn’t find the silly volume control in the system settings one day so i figured there had to be something I could use to control volume settings like mic boost without needing a gui or remembering names and numbers for the CLI. well there is and its so easy a caveman could do it (hah them ads….)…. so without further ado here’s a fun and great way to control your volume via a CLI.

type the following then use your arrows to move right/left an make the volume higher or lower by using up/down keys:

alsamixer -c 0

the 0 at the end is the number of your device. if a system only has one device you will use 0. if you have two devices you can use 0 or 1. it tells you the name of the device currently being edited so you dont give yourself a heart attack by changing the wrong volume. picture of the control is attached.

alsa volume editor

Share
April 25, 2012

Mount box.com as a local folder on ubuntu as webdav

Whats WebDav: Web Distributed Authoring and Versioning (WebDAV) is an extension of the Hypertext Transfer Protocol (HTTP) that facilitates collaboration between users in editing and managing documents and files stored on World Wide Web servers.
Whats Box.com [.net]: Box.com is cloud-storage service like Dropbox, SugarSync and google drive. After uploading your various documents, media files, and the like, you can easily access them online, share them with others, stream media to a mobile device, and so on. An awesome feature that comes with using box.com on an android device is that you get 50GB of free space. Sadly per file size limit is a very low of 100MB :( However you can enjoy box.com as a local folder on your computer whether you use windows or linux. I just mounted it as a local folder on my Ubuntu 12.04 desktop and 11.10 Server and heres the simple steps to follow :

install davfs:

sudo apt-get install davfs2

make a directory where you will be mounting the box folder. I am using a folder called box under the home directory of a user called homer

mkdir /home/homer/box

mount the folder. after using this command just insert username/password when prompted.

sudo mount -t davfs https://www.box.com/dav /home/homer/box

add your credentials to /etc/davfs2/secrets

sudo nano /etc/davfs2/secrets

insert the following, just replace your username/pass in the proper spot.:

https://www.box.com/dav username password”

now you also have access to dav://www.box.com/dav as a location in your file explorer.

Share
April 21, 2012

SSHFS mount remote file system locally over SSH

SSHFS is a filesystem client based on the SSH File Transfer Protocol. Since most SSH servers already support this protocol it is very easy to set up: i.e. on the server side there’s nothing to do. On the client side mounting the filesystem is as easy as logging into the server with ssh.

So we have two systems remote.kpsn.pie and local.kpsn.pie. we want to mount directory /home/homer/supercooldir from remote.kpsn.pie as /home/user/remote in local.kpsn.pie and for this discussion on remote system your user is called homer. we will be doing all these commands as user on local system and not root.

This requires SSH key based authentication to be working between the machines prior to this being setup. check out other tutorial on this setup.

so first off you install sshfs on local.kpsn.pie

sudo apt-get install sshfs

Now you need to make the folder in local.kpsn.org.pie where you will be mounting the remote folder so:

mkdir /home/user/remote

now we go about actually mounting the remote directory to the local one we made so:

sshfs -o idmap=user homer@remote.kpsn.pie:/home/homer/supercooldir /home/user/remote

What if you have a different port for ssh on remote? well simply use the -p flag, say the port is 12345:

sshfs -p 12345 -o idmap=user homer@remote.kpsn.pie:/home/homer/supercooldir /home/user/remote

to unmount you type:

fusermount -u /home/user/remote

to automagically mount this at startup edit /etc/rc.local

nano /etc/rc.local

and insert this line ABOVE the line saying exit 0

cd /home/user && su -c "/usr/bin/sshfs -o idmap=user [email protected]:/home/homer/supercooldir /home/user/remote" user

that last “user” is the local machine user. this allows the command to be run as the local machine user so the drive gets mounted properly.

this all is written for ubuntu but should work elsewhere. lemme know of any questions or concerns.

Share
April 4, 2012

Zoho Docs for Android finally on Google Play

Title:
Zoho Docs
Market rating: 3.1 / 5
Total downloads:
1,000 - 5,000
Size: 1.1M

Title:
Documents To Go 3.0 ...
Market rating: 4.1 / 5
Total downloads:
10,000,000 - 50,000,000
Size: Varies with device

Title:
Google Drive
Market rating: 4.1 / 5
Total downloads:
5,000,000 - 10,000,000
Size: 4.6M

My thoughts: Zoho docs is a viewer only, you cannot edit docs in it at this point just view already existing ones or uploaded new ones. which is sad but I suppose that’s why you have products like documents to go. zoho docs is decent, some people prefer it over google docs. personally I think there’s no reason for me to move to zoho when feature set is similar as far the viewers go and I need a new account for it whereas google docs has the same account shared on it AND i can edit and create docs as needed. others might disagree :) just because Its an option there’s also a link to documents to go up there which is a “full featured” document editor and viewer that can access your google docs also.

Zoho Description
Zoho Docs for Android offers mobile access to your documents available on the web at http://docs.zoho.com.
Zoho Docs is an online document management application for individuals and businesses. This mobile version extends access to your documents to Android mobiles. If you don’t already have a Zoho account, you can easily create one within the application.
HIGHLIGHTS

  • Access your documents created in online versions of Zoho Writer, Sheet, Show & Docs
  • View documents, spreadsheets, presentations, PDFs and other types of documents
  • View shared documents
  • Upload images from your mobile device directly to Zoho Docs
  • Search to quickly find your documents
  • Share your private documents to other Zoho users
  • List view with Swipe tabs
  • Remembers your account info so you can avoid frequent logins

Google Docs Description

  • Create, edit, upload and share your documents with the Google Docs app.
  • Designed for Android to save you time finding your docs
  • Edits to your documents appear to collaborators in seconds
  • Make quick changes to spreadsheets
  • View your documents, PDFs, presentations and more
  • Mark files as available offline for view access even when you’re not connected
  • Upload and convert files to the Google Docs format
  • Take a photo of printed text and convert it to a Google document
  • Share docs with your device’s contacts
  • Optimized experience to take advantage of larger screens for tablet users, Honeycomb (Android 3.0+)
  • Improved Google documents reading experience for tablet users
Share
April 3, 2012

SSH key generation 101

I always forget the -b option which allows changing the size of the key…. so Im putting this down here for future reference.

ssh-keygen -t rsa -b 2048

You can use dsa instead of the rsa after the -t to generate a DSA key. The number after the -b specifies the key bits. DSA is limited to 1024, whereas RSA isn’t. standard is 1024 if you don’t include the -b argument.

Share
March 12, 2012

Image Conversion & PDF shrinkage

Problem : I need to take a bunch of mixed images of jpg and png origin and convert them to a PDF file.
Solution : convert all to one file type, then convert them all to a single PDF and THEN shrink the PDF to a normal size….
tools needed : imagemagick, ghostscript, bash/zsh and a bunch of images

procedure :

I have all these images sitting in a directory :
img011.png img013.jpg img015.png img017.png img019.png img021.png img023.png img025.png img3.jpg img5.png img7.png img010.png img012.png img014.png img016.jpg img018.png img020.png img022.png img024.png img09.png img1.png img2.png img4.png img6.png img8.png

Lets convert them all to jpg first :

mogrify -format jpg *.png

now we have all jpg images (you can do it the opposite way also, just replace jpg with png in above and vice versa). So lets convert them all to a PDF file :

convert *.jpg img1.pdf

but its HUGE! AMIGAWD! etc… so we need to slim it down a little, get it some slimfasts etc…. so here we go! you need ghostscript for this next step ( sudo apt-get install ghostscript | yum install ghostscript )

gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/screen -dNOPAUSE -dQUIET -dBATCH -sOutputFile=OUTPUT.pdf INPUT.pdf

AMIGAWD*2 look at the size difference!

% ll img*.pdf   
-rw-rw-r-- 1 kingpin kingpin 155679662 2012-03-12 14:04 INPUT.pdf
-rw-rw-r-- 1 kingpin kingpin   1689376 2012-03-12 14:08 OUTPUT.pdf

My name is KingPin and this is my favorite way to make PDF’s on this internet!

Share
March 6, 2012

PHP Image Magick Drop Shadow

Want to add a simple drop shadow on any image? well here’s how to do it on the fly via PHP and Image Magick.

< ?php
 
    $img = new Imagick('images/image.jpg');
    $img->setImageFormat('png');
    $shadowed = $img->clone();
    $drop_shadow = $img->clone();
    $drop_shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );
    $drop_shadow->shadowImage( 80, 3, 5, 5 );
    $drop_shadow->compositeImage( $img, Imagick::COMPOSITE_OVER, 0, 0 );
    header( "Content-Type: image/jpeg" );
    echo $drop_shadow; 
?>

Here’s how to do same via PHP and Image Magick but writing the file out to a second image leaving your original alone.

< ?php
 
$filename_shdw = 'images/image_shadow.jpg';
 
if (!file_exists($filename_shdw)) {
    $img = new Imagick('images/image.jpg');
    $img->setImageFormat('png');
    $shadowed = $img->clone();
    $drop_shadow = $img->clone();
    $drop_shadow->setImageBackgroundColor( new ImagickPixel( 'black' ) );
    $drop_shadow->shadowImage( 80, 3, 5, 5 );
    $drop_shadow->compositeImage( $img, Imagick::COMPOSITE_OVER, 0, 0 );
    $drop_shadow->writeImage( 'images/image_shadow.jpg' );
}
    echo '<img src="images/image_shadow.jpg" />'; 
?>

these snippets are very simple, you can expand them, include them in your own code, randomize the drop shadow etc. I will expand this in another post.

Share
March 3, 2012

Create Thumbnails from a bunch of images

Linux Code snippet. Ever wated to batch create thumbnails? “musclecarr” posted this bash script to create thumbnails of all images of a specific type. It uses imagemagick and specifically the convert command. minor modifications done to it and comments added for easy understanding, here it is :

#!/bin/bash
# take argument or use current dir
DIR=${1:-`pwd`}
# create dir thumbs if doesnt exist
[ -d "$DIR/thumbs" ] || mkdir "$DIR/thumbs"
# error out if cant enter dir for some reason (permissions?)
cd "$DIR" || { echo >&2 "error: couldn't enter directory: $DIR"; exit 1;}
# For every file with extension XXX (jpg in this case)
for i in ./*.jpg; do
# Resize image to 100x100
convert "$i" -resize 100x100 "$DIR/thumbs/$i"
# profit? nah.
done
Share
March 3, 2012

recursively delete all empty subdirectories

sometimes you want to find a bunch of empty sub-directories and delete them well heres a simple piece of shell code that will accomplish that for you.

find /home/user/somedir -depth -type d -empty -exec rmdir -v {} \;

Caution
Caution!
This CAN and WILL destroy all your data and eat your small { dog | cat | turtle | parrot } if you aren’t careful! ALWAYS check the path twice and then check it again before using.

Share
March 2, 2012

Directory FileCount

I have close to 3000 images in a folder and needed to know exactly how many for a stupid bet I made. I dont feel like counting them! there must be something in the linux world to make this easier…. well there is. simple extension of the ls command.

my directory is called images but I’m sure contains no images whatsoever. *cough* so lets get the basics :

ls -1 images | wc -l

what if you wanted to not count sub directories or symlinks?

find images -maxdepth 1 -type f | wc -l

want to add symlinks?

find images -maxdepth 1 -type f -follow | wc -l

so yeah the basics should be done :)

Share
Page 1 of 212