Mario Orlandi's Snippets

28/01/2012

List and kill processes on Mac

Filed under: Uncategorized — Tags: — morlandi @ 11:42
$ ls -eaf

$ killall procname

killall options:

-u user     Limit potentially matching processes to those belonging to the specified user.
-s          Show only what would be done, but do not send any signal

22/01/2012

Git branch examples

Filed under: Uncategorized — Tags: — morlandi @ 18:42

first create the branch locally and then push it to the remote repo

$git checkout -b new_branch_name
$git push origin new_branch_name

Finally, add the following to ".git/config":

[branch "new_branch_name"]
    remote = origin
    merge = refs/heads/new_branch_name

list branches

$git branch -a ... shows all local and remote branches
$git branch -r ... shows only remote branches

or use the following to displays plenty of information about the remote in general and how it relates to your own repository:

$git remote show origin

other example with a submodule

    cd src/forum
    git status
    # Not currently on any branch.
    git checkout master
    # Previous HEAD position was 0816d91... Updated locales
    # Switched to branch 'master'
    git pull
    git checkout -b assiweb
    git push origin assiweb

20/01/2012

Allow db access with password authentication in LAN

Filed under: Uncategorized — Tags: — morlandi @ 19:51

in file “pg_hba.conf”:

# TYPE  DATABASE    USER        CIDR-ADDRESS          METHOD

# "local" is for Unix domain socket connections only
local   all         all                               trust
# IPv4 local connections:
host    all         all         127.0.0.1/32          trust
host    paintdb     jcolors     192.168.98.0/24       password
host    all         all         192.168.98.0/24       password
# IPv6 local connections:
host    all         all         ::1/128               trust

18/01/2012

Update query by joining multiple tables

Filed under: Uncategorized — Tags: — morlandi @ 10:29
update assiweb_company set province_id=S.id
from silverbullet_geo_state S
where assiweb_company.state = S.code

09/01/2012

Relocate Git repository

Filed under: Uncategorized — Tags: — morlandi @ 19:37
# git remote rm origin
# git remote add origin ssh://host/newgitrepo

then update .git/config as follows:

[branch "master"]
	remote = origin
        merge = refs/heads/master

31/12/2011

Readynasduo Backup to USB external drive

Filed under: Uncategorized — Tags: — morlandi @ 12:47
Always use front USB port which is USB 2.0 while back ports are USB 1.1 compatible:

nas3:~# lspci -v
0000:00:17.0 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 62)
0000:00:17.1 USB Controller: VIA Technologies, Inc. VT82xxxxx UHCI USB 1.1 Controller (rev 62)
0000:00:17.2 USB Controller: VIA Technologies, Inc. USB 2.0 (rev 65) (prog-if 20 [EHCI])

nas3:# fdisk -l
Disk /dev/hdc: 2000.3 GB, 2000388448256 bytes
...
Disk /dev/hde: 2000.3 GB, 2000388448256 bytes
...
Disk /dev/hde doesn't contain a valid partition table
...
Disk /dev/sda: 2000.3 GB, 2000398934016 bytes
255 heads, 63 sectors/track, 243201 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Disk identifier: 0x734462e6
   Device Boot      Start         End      Blocks   Id  System
/dev/sda1               1      243202  1953512032+   7  HPFS/NTFS

nas3:# du --max-depth=1 -h /c
70G	/c/family
16k	/c/lost+found
210G	/c/media
126G	/c/.timemachine
3.6G	/c/silverbullet
57G	/c/brainstorm-extr
48G	/c/backup
708M	/c/.bittorrent
25G	/c/brainstorm
11M	/c/home
536G	/c

nas3:# mount /dev/sda1 /mnt/usbdrive/ 

Per es., backup del folder "brainstorm":
nas3:# rsync --progress --delete -avh /c/brainstorm/ /mnt/usbdrive/2011-12-31/c/brainstorm

oppure:

nas3:# rsync --progress --delete -avh --exclude-from '/c/exclude.txt' /c/ /mnt/usbdrive/2011-12-31/c

dove per es.

nas3:# cat exclude.txt
media
.timemachine
.bittorrent

Poiche' abbiamo attivato "fast USB write", alla fine:
nas3:# umount /mnt/usbdrive

note

nas3:~# export TERM=xterm
nas3:~# top

29/12/2011

How do I create an .iso image

Filed under: Uncategorized — Tags: , — morlandi @ 10:19

I want to create an .iso image and have it compatible with Mac and Windows. Will Disk Utility let me do this?

Create a folder with the contents you want on your ISO.

Open Disk Utility and use the New Image from Folder menu item to create an image. Ensure it is uncompressed and use the CD/DVD master option.

In my experience this creates HFS+ masters which are no good in Windows.

Open the Terminal

Assuming your new image is called ~/Desktop/Master.cdr (the file is on your desktop and called Master.cdr) type:

Code:

cd ~/Desktop
hdiutil makehybrid -iso -joliet -o Master.iso Master.cdr

This will create an ISO/Joliet .iso file.

16/12/2011

set Django Form Textatea size

Filed under: Uncategorized — Tags: , — morlandi @ 11:59
class CourseAttachmentInline(admin.TabularInline):
    model = CourseAttachment
    extra = 1

    def formfield_for_dbfield(self, db_field, **kwargs):
        field = super(CourseAttachmentInline, self).formfield_for_dbfield(db_field, **kwargs)
        if db_field.name in ('subtitle',):
            #field.widget.attrs['rows'] = 3
            #field.widget.attrs['cols'] = 20
            field.widget.attrs = {'rows': 3, 'cols': 50}
        return field

or


class CourseAttachmentInline(admin.TabularInline):
    model = CourseAttachment
    extra = 1

    def formfield_for_dbfield(self, db_field, **kwargs):
        if db_field.name in ('subtitle',):
            return forms.CharField(widget=forms.Textarea(
                attrs={'cols': 50, 'rows': 3},
            ))
        return super(CourseAttachmentInline, self).formfield_for_dbfield(db_field, **kwargs)

14/12/2011

Mac OS X – Show / Hide Hidden Files in Finder

Filed under: Uncategorized — Tags: — morlandi @ 09:15
show:
$defaults write com.apple.finder AppleShowAllFiles TRUE
$killall Finder

hide:
$defaults write com.apple.finder AppleShowAllFiles FALSE
$killall Finder

Sinlge file

show:
$chflags nohidden ~/Library/

hide:
$chflags hidden ~/Library/

10/12/2011

What’s the equivalent of Linux’s updatedb command for the Mac?

Filed under: Uncategorized — Tags: — morlandi @ 09:36
sudo /usr/libexec/locate.updatedb
Older Posts »

Theme: Silver is the New Black. Blog at WordPress.com.

Follow

Get every new post delivered to your Inbox.