Saturday, March 30, 2013

DOS batch: renaming multiple files with a counter

In rena.bat:
echo off
cls
set i=0
setlocal ENABLEDELAYEDEXPANSION
for /r %%x in (%1) do (
 ren "%%x" "foo-"!i!".jpg" 
 set /a i=i+1
)
The above code renames all .jpg files to be prefixed with foo and with an incrementing counter. To use the code,
rena *.jpg

Thursday, March 28, 2013

A bit of git

Install git everywhere

sudo apt-get install git

Local Directory

git init
git add .
git commit -a -m "message foo"

Prepare the server

git init

Submit to server

git remote add origin url.git
git push origin master

Further Worthwhile Reading

Sunday, March 24, 2013

C Comments: FIXME, TODO, XXX

Gedit has these comments hightlighted in yellow (credit):
/* TODO: How about auto-correcting small spelling errors? */
/* FIXME: This won't work if the file is missing. */
/* XXX: This method badly needs refactoring: should switch by core type. */

Saturday, March 23, 2013

Checking Endianness with C

The piece of code is written on April 23, 2010.
#include <stdio.h>
int checkEndian(){
 int p = 0xffff0000;
 if(*(char*)&p==0xff) //char* pointer of p's first byte
   printf("Big Endian");
 else
   printf("Little Endian"); //my pc is little endian
 return 0;
}
int main(){
   checkEndian();
}

Appendix

If the value of integer variable (32 bits) is 0xffff0000 and your system is in big endian, it will be stored as binary in memory like:
low addr:  1111 1111
       |   1111 1111
       ↓   0000 0000
high addr: 0000 0000

Friday, March 22, 2013

Users and Groups

Linux is a native multi-accessible system.

Enable and disable root

sudo password root
sudo passwd -l root
To open a shell with root, just
su

Add a new group bar

sudo groupadd bar

Add a new user foo to a group bar

sudo useradd -G bar foo

Add an existing user foo to a group bar

sudo usermod -a -G bar foo

Print current settings

id bar
groups foo

Tuesday, March 19, 2013

Makefile: CFLAGS

By writing the following in the Makefile,
CFLAGS = "-FOO -BAR"
It is equivalent to write the below in the original C files.
#define FOO
#define BAR
So if you have these somewhere in your code,
#ifdef FOO
foo();
#endif

foo() will be executed.

GCC CFLAGS

Flags like -Wall -Wextra are used to pass an option to the compiler. The former means to generate all warnings, the latter extra warnings. Follow link.

gs: Merging Multiple PDFs

Preparation

sudo apt-get install gs pdftk

The Command

gs -dBATCH -dNOPAUSE -q -sDEVICE=pdfwrite -sOutputFile=done.pdf ./*.pdf

A Sketch of GhostScript.

gs
    starts the Ghostscript program.
-dBATCH
    once Ghostscript processes the PDF files, it should exit.
    If you don't include this option, Ghostscript will just keep running.
-dNOPAUSE
    forces Ghostscript to process each page without pausing for user interaction.
-q 
    stops Ghostscript from displaying messages while it works
-sDEVICE=pdfwrite 
    tells Ghostscript to use its built-in PDF writer to process the files.
-sOutputFile=finished.pdf
    tells Ghostscript to save the combined PDF file with the specified name.

Saturday, March 16, 2013

Choosing Your Web Color Scheme From Paintings

Here is an excerpt:
23616639.JPG 
Museum of Modern ArtStarry Night: Van Gogh accepted the night as a distorting condition, almost the way later modernists like Marcel Duchamp and Jean Arp would use chance to experiment and to break habits. Unable to see clearly, he painted what he saw, ultimately pitting his colors against one another as if they were antagonists in a visual drama. He egged on their clashes with exaggerated daubs of paint, bringing backgrounds forward and giving each inch of canvas its own sense of life. In Western art before him, only the semi-Western mosaics of Ravenna achieved such complete articulation.NYT
Here is an example exploiting this color scheme:
An Octagon Board
For more, please follow this article:
Van Gogh And The Colors Of The Night

Tuesday, March 12, 2013

Dollars in Shell

As pointed out here (stackoverflow : link):
  • Positional parameters $1 ,2,3… and their corresponding array representation, count and IFS expansion @, #, and *.
  • - current options set for the shell.
  •  pid of the current shell (not subshell)
  • _ most recent parameter (or the abs path of the command to start the current shell immediately after startup)
  • IFS the (input) field separator
  • ? most recent foreground pipeline exit status
  • ! PID of the most recent background command
  • 0 name of the shell or shell script

wget Everything in a Folder With Credentials

To fetch multiple files from a private FTP server where the credentials are required, one needs to specify --ask-password, if not, one gets this report:

Logging in as anonymous ...
Error in server response, closing control connection
Retrying.

Right command:

wget -rc --user=your-user-name --ask-password ftp://your.website.com

where -r means to recursively get, and -c means to continue to get a partially downloaded file.

Monday, March 11, 2013

Elegant Reading Extensions in Chrome

It captures pictures (and videos) on webpages and posts (pins) it to your pinterest board.


Readability is a renowned web practice on web reading, it re-organizes articles in printing standards, one can send the artified article back to book readers like Kindle.


Pocket is a pinterest on blog articles, aka read-it-later app, although it provides also for pictures and videos. 


Friday, March 8, 2013

Enabling root user on Ubuntu

We need to create a password for root

sudo password root
su root

To unable

sudo password -l root

Beautiful Zooming on Chrome: simpLoupe

This is a recommendation of a cute extension for zooming partially within your browser. It has an unique interface and easy to use and configure. Also it gives you a sence of real lens.

Follow this link to get it

Raw Picutures Editing under Ubuntu

Various Software Options:

  • digiKam

    sudo apt-get install digiKam
  • AfterShot Pro, made by Corel, 30-day-trial, click link, I recommend this one (☆☆☆)

    sudo dpkg -i AfterShotPro_amd64.deb
  • LightZone

    git clone git://github.com/AntonKast/LightZone.git
  • UFraw

    sudo apt-get install ufraw
  • RawTherapee

    sudo apt-get install rawtherapee
  • Raw Studio

    sudo apt-get install rawstudio