Updates from January, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • diegor 6:06 pm on July 29, 2011 Permalink | Reply
    Tags:   

    HOWTO: rename all files in lowercase 

    Pretty simple.

    1. If you don’t have a *NIX operating system, please skip this post.
    2. Create a script with this content:
      #!/bin/sh
      for f in *; do
      g=`expr "xxx$f" : 'xxx\(.*\)' | tr '[A-Z]' '[a-z]'`
      mv -n "$f" "$g"
      done

      and call it “rename.sh”

    3. Give it execution permissions, typing:
      chmod u+x rename.sh
    4. Execute the script from the directory where you have your files to rename
    If you have two files, “Foo” and “foo“, you’ll be notified and no files will be overwritten. So, don’t worry about that, you won’t lose any information. To be sure, try it with a few files in “/tmp” directory.
    Question? Suggestion? Comment! :)

     

     
    • Luca De Vitis 6:26 pm on July 29, 2011 Permalink | Reply

      ls -1 | while read file ; do mv -nv “${file}” “$(echo “${file}” | tr ‘[A-Z]‘ ‘[a-z]‘)” ; done

      • diegor 6:53 pm on July 30, 2011 Permalink | Reply

        Hi Luca, thanks for the trick.
        I tried but it doen’t work.. I have this:

        “namefile not overwritten”

        It works only if I drop “-n” option from mv command (too risky!!)

  • diegor 1:00 pm on March 11, 2011 Permalink | Reply
    Tags:   

    HOWTO: make vim show ending line spaces as characters 

    When you edit a file with vim, it’s useful understand where the line ends especially if there are spaces at the end of the line. Instead checking all lines, you can highlight white spaces. How?

    1. Open Vim from Terminal
    2. type
      :set list
    3. You see an output like the one below
    4. If you want see each space as character, type this command
      :set listchars=eol:$,tab:>-,trail:~,extends:>,precedes:<
    5. The output should look like below

    Very simple and useful tip! :)

    If you have any doubt, advice or something else, comment this post! :)

    Source: Stackoverflow

     
    • proudlygeek 1:43 pm on March 11, 2011 Permalink | Reply

      Vim is my favourite text editor, i use it pretty anywhere :-)

      I’ll share a useful trick for commenting multiple lines of code:

      1) SHIFT-V to select multiple lines;
      2) Type “:s/^/#”

      Where “^” indicates the beginning of a line and “#” the comment symbol of your choice.

      To decomment a block of code:

      1) Shift-V
      2) Type “:s/^#//”

  • diegor 7:58 pm on March 4, 2011 Permalink | Reply
    Tags:   

    HOWTO: run cron job in seconds 

    If you know what cron is, you also know that the minimum time to execute a job is a minute. There is a small tip to execute a cron job every X seconds. For example if you need to run a cron job every 30 seconds (it’s a common case), you can do it adding these lines to crontab:

    * * * * * root sh /path/to/myscript.sh
    * * * * * root sleep 30 && sh /path/to/myscript.sh

    Both lines execute the job every minute, but the second one waits 30 seconds using “sleep” command from bash.

    If you have any question, comment this post. :)

     
    • Andrea 4:01 pm on July 24, 2011 Permalink | Reply

      Very nice guide! It’s very tricky. Anyway do you know some implementation of a scheduler such cron that deals with seconds instead of minutes?

    • diegor 11:17 pm on July 24, 2011 Permalink | Reply

      Mmm, sorry I don’t know any scheduler except cron..

  • diegor 3:26 pm on February 15, 2011 Permalink | Reply
    Tags:   

    HOWTO: moving Time Machine data to new hard disk 

    If you are using Time Machine feature from OSX maybe you need to move data from you hard disk to a new one avoiding to lose it. There is no official way to do this, but with some trick you can do it easily. Follow these steps:

    1. make sure both drives (could be also a remote hard disk) are connected;
    2. launch “Disk Utility”
    3. in the left column, click on one drive name (NOTE: main drive icon!)
    4. at the right side click on “restore” tab (the last one)
    5. from the left, click and drag the icon of the older hard drive to “source” field
    6. repeat step 5 with the new drive dragging it into “destination” field
    7. best choice is to set “Erase Destination”
    8. click “Restore”
    9. realax for some hours (for 120 GB I waited 5 hours).

    When the process will finish, new drive has the same name of the old one. Rename old drive or give a new name to new drive. Once you changed the name open Time Machine settings and choose new drive.

    That’s it :)

    If you have any trouble, let me know commenting this post.

     
  • diegor 6:01 pm on January 29, 2011 Permalink | Reply
    Tags:   

    HOWTO: restore Mail.app content indexing 

    Mail is a great mail client provided with OSX. It works very well, fully integrated and fast. Sometimes it goes crazy and doesn’t indexing the mails’ content with the impossibility to perform research based on it.

    After some research over the web, the problem stays in “spotlight“. Yes, unlike subject, from and to fields, the content is indexed by spotlight.

    To solve this issue, open a Terminal and type these commands:

    #> sudo mdutil -i off "/Volume/where/is/Mail"
    #> sudo mdutil -i on "/Volume/where/is/Mail"
    #> sudo mdutil -E "/Volume/where/is/Mail"

    In according to mdutil’s man page, latest command set the indexing content as “Erased” and will be rebuilt.

    Any trouble? Shoot a comment :)

     
  • diegor 11:57 pm on January 27, 2011 Permalink | Reply
    Tags:   

    HOWTO: emulate a slow connection on OSX 

    In Italy, where I live (for now), it’s not difficult to “emulate” a slow connection. Anyway if you want test your new webapp or you want see the behavior of website with a slow connection, then “speedlimit” is for you. It’s a small application (preference pane exactly) that you can find here.

    The steps are very simple:

    1. download it (from here)
    2. install it
    3. run it
    4. choose the ports and the sites where you want go slowly
    5. finally choose the slowness of you “emulated” connection
    6. once you have set up everything, press the button “Slow Down”

    So, don’t run!! :)

     
  • diegor 7:53 pm on January 17, 2011 Permalink | Reply
    Tags:   

    HOWTO: fix offending key in SSH 

    When you perform an ssh connection to a remote machine, the 1st time you will be prompted to say ‘yes’ to authenticate the remote host.
    This feature is controlled by “StrictHostKeyChecking” parameter and it is set to yes by default. From security point of view, this option should be enable because protect you and your system against trojan horse attacks.
    Sometimes you need disabling it temporarily. To disable it you can do via console or via config file.

    Via console:

    #> ssh -o 'StrictHostKeyChecking no' username@remotemachine

    Via config file, adding below line to /etc/ssh_config (OSX) or /etc/ssh/ssh_config (linux):

    StrictHostKeyChecking no

    Once you turned it on, you can solve “offending key” deleting it from “~/.ssh/know_hosts” through this terminal command:

    # sed -i '19d' ~/.ssh/known_hosts

    where 19 is the line containing offending key.

    If you have suggestions, troubles or you feel alone, comment this post! :)

     
c
compose new post
j
next post/next comment
k
previous post/previous comment
r
reply
e
edit
o
show/hide comments
t
go to top
l
go to login
h
show/hide help
shift + esc
cancel

Switch to our mobile site

Powered by Google Talk Widget