ShiftIt build

Posted: October 1st, 2011 | Author: | Filed under: OS X | No Comments »

This is a build based on fikovnik’s version.

By pressing hotkeys you can resize any window to one of the 10 position/size combinations. Of course this is mac only.


Stop OSX creating .DS_Store on network mounts

Posted: September 20th, 2011 | Author: | Filed under: OS X, System | No Comments »

Type this in terminal:

defaults write com.apple.desktopservices DSDontWriteNetworkStores true

Managing apache folder

Posted: September 8th, 2011 | Author: | Filed under: Development, Linux | No Comments »

The goal here is to allow apache process as well as multiple developers to have read and write permission to all apache files.

What I’m currently doing is:
- Add a new group “dev”

addgroup dev

- Add www-data (or whatever your apache runner user is) to the group “dev”

adduser www-data dev

- Add all developers to the group “dev”

adduser vincent dev
adduser anotherdev dev

- Change apache user “www-data” and all developers’ default group to “dev”

vim /etc/passwd
# each line is a user:
# username:x:userid:groupid:userinfo:script
# now change groupid from the default user group to the groupid of "dev"

- Change umask to 002 (all developers on ssh, all developers on sftp, and www-data)

vim /etc/profile
# change umask to 002
vim /etc/ssh/sshd_config
# change Subsystem to:
Subsystem sftp /usr/lib/openssh/sftp-server -u 0002
vim /etc/apache2/envvars
# add
umask 002

- Change all apache folders to www-data:dev, 775 and files to www-data:dev, 664

chown www-data:dev /home/www-data -R
chmod 775 /home/www-data
find /home/www-data/* -type d -exec chmod 775 {} \;
find /home/www-data/* -type f -exec chmod 664 {} \;

OSX: Remap Home/End keys

Posted: September 6th, 2011 | Author: | Filed under: OS X, System | No Comments »
# ~/Library/KeyBindings/DefaultKeyBinding.dict
{
/* Remap Home / End to be correct :-) */
"\UF729"  = "moveToBeginningOfLine:";                   /* Home         */
"\UF72B"  = "moveToEndOfLine:";                         /* End          */
"$\UF729" = "moveToBeginningOfLineAndModifySelection:"; /* Shift + Home */
"$\UF72B" = "moveToEndOfLineAndModifySelection:";       /* Shift + End  */
}

This will make “Home”/”End” act like they are in Windows.


Learn Vim Progressively

Posted: August 30th, 2011 | Author: | Filed under: Development, Linux | No Comments »

Source


Keep SSH session alive without sudo

Posted: July 24th, 2011 | Author: | Filed under: Linux | No Comments »
vim ~/.ssh/config

# this example keep the session alive for 60sec x 480 = 8hours
ServerAliveInterval 60 #seconds
ServerAliveCountMax 480 #times of keep-alive signals to send

SSH without password, and key only login

Posted: July 21st, 2011 | Author: | Filed under: Linux | No Comments »
# create rsa key, skip if already done
local> ssh-keygen -t rsa

# create .ssh/ in home
local> ssh USER@REMOTEHOST mkdir ~/.ssh

# cat local public key, pipe over to ssh, take the piped local key append into remote ~/.ssh/authorized_keys
local> cat ~/.ssh/id_rsa.pub | ssh USER@REMOTEHOST 'cat >> ~/.ssh/authorized_keys'

# now on remote
remote> sudo vim /etc/ssh/sshd_config
# add the following
PermitRootLogin no # disable ssh as root
PubkeyAuthentication yes # use key authentication
PasswordAuthentication no # disable password authentication

Production Server with Rails and Phusion Passenger

Posted: June 21st, 2011 | Author: | Filed under: Linux, Ruby, System | No Comments »

First you need to install RVM, ruby, rubygem, rails, with LAMP already installed too.

rvmsudo passenger-install-apache2-module

# to find out where apache config file is
apachectl -V | grep SERVER_CONFIG_FILE

# load modules in Apache config (this may vary)
LoadModule passenger_module /home/vincent/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/ext/apache2/mod_passenger.so
PassengerRoot /home/vincent/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7
PassengerRuby /home/vincent/.rvm/wrappers/ruby-1.9.2-p180/ruby

# now this is an exmple of apache virtualhost
<VirtualHost *:80>
        DocumentRoot /home/www-data/depot/public
        ServerName appname.myserver.com
        <Directory /home/www-data/depot/public>
                AllowOverride all
                Options -MultiViews
        </Directory>

        # Speeds up spawn time tremendously -- if your app is compatible.
        # RMagick seems to be incompatible with smart spawning
        RailsSpawnMethod smart

        # Keep the application instances alive longer. Default is 300 (seconds)
        PassengerPoolIdleTime 1000

        # Keep the spawners alive, which speeds up spawning a new Application
        # listener after a period of inactivity at the expense of memory.
        RailsAppSpawnerIdleTime 0

        # Additionally keep a copy of the Rails framework in memory. If you're
        # using multiple apps on the same version of Rails, this will speed up
        # the creation of new RailsAppSpawners. This isn't necessary if you're
        # only running one or 2 applications, or if your applications use
        # different versions of Rails.
        RailsFrameworkSpawnerIdleTime 0

        # Just in case you're leaking memory, restart a listener
        # after processing 5000 requests
        PassengerMaxRequests 5000

        # only check for restart.txt et al up to once every 5 seconds,
        # instead of once per processed request
        PassengerStatThrottleRate 5
</VirtualHost>

Create the database needed for the new app, update config/database.yml content to allow app to connect to database on the production server.

Once the new rails app is uploaded to the server:

# install/update bundle
cd appfolder/
bundle install

# now setup database table and data
cd appfolder/
rake db:setup RAILS_ENV=production

Next you use a2ensite and /etc/init.d/apache restart to reload the new site.


Bashrc Profile bits

Posted: June 21st, 2011 | Author: | Filed under: System | No Comments »
# Common alias
alias ll='ls -laF'
alias la='ls -A'
alias l='ls -CF'
alias dir='ls -Lla|grep ^d'

# check the window size after each command and, if necessary,
# update the values of LINES and COLUMNS.
shopt -s checkwinsize

# don't put duplicate lines in the history. See bash(1) for more options
# ... or force ignoredups and ignorespace
HISTCONTROL=ignoredups:ignorespace

# append to the history file, don't overwrite it
shopt -s histappend

# Colorful terminal
export CLICOLOR=1
export LSCOLORS=ExFxCxDxBxegedabagacad

# Set colorful PS1 only on colorful terminals.
# dircolors --print-database uses its own built-in database
# instead of using /etc/DIR_COLORS.  Try to use the external file
# first to take advantage of user additions.  Use internal bash
# globbing instead of external grep binary.
safe_term=${TERM//[^[:alnum:]]/?}   # sanitize TERM
match_lhs=""
[[ -f ~/.dir_colors   ]] && match_lhs="${match_lhs}$(<~/.dir_colors)"
[[ -f /etc/DIR_COLORS ]] && match_lhs="${match_lhs}$(</etc/DIR_COLORS)"
[[ -z ${match_lhs}    ]] \
        && type -P dircolors >/dev/null \
        && match_lhs=$(dircolors --print-database)
[[ $'\n'${match_lhs} == *$'\n'"TERM "${safe_term}* ]] && use_color=true

if ${use_color} ; then
        # Enable colors for ls, etc.  Prefer ~/.dir_colors #64489
        if type -P dircolors >/dev/null ; then
                if [[ -f ~/.dir_colors ]] ; then
                        eval $(dircolors -b ~/.dir_colors)
                elif [[ -f /etc/DIR_COLORS ]] ; then
                        eval $(dircolors -b /etc/DIR_COLORS)
                fi
        fi

        if [[ ${EUID} == 0 ]] ; then
                PS1='${debian_chroot:+($debian_chroot)}\[\033[01;31m\]\h\[\033[01;34m\] \W \$\[\033[00m\] '
        else
                PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\] '
        fi

else
        if [[ ${EUID} == 0 ]] ; then
                # show root@ when we don't have colors
                PS1='\u@\h \W \$ '
        else
                PS1='\u@\h \w \$ '
        fi
fi

# Remove variable name pollution
unset use_color safe_term match_lhs

Remove a line from multiple files

Posted: April 8th, 2011 | Author: | Filed under: Development, System | No Comments »
find . -type f -exec sed -i '/LINETHATCONTAINTHIS/d' {} \;

Few bash scripts

Posted: February 1st, 2011 | Author: | Filed under: Development, Linux, System | No Comments »

Perl rename (copied out from ubuntu dist)

#!/usr/bin/perl -w
use strict;

use Getopt::Long;
Getopt::Long::Configure('bundling');

my ($verbose, $no_act, $force, $op);

die "Usage: rename [-v] [-n] [-f] perlexpr [filenames]\n"
    unless GetOptions(
        'v|verbose' => \$verbose,
        'n|no-act'  => \$no_act,
        'f|force'   => \$force,
    ) and $op = shift;

$verbose++ if $no_act;

if (!@ARGV) {
    print "reading filenames from STDIN\n" if $verbose;
    @ARGV = <STDIN>;
    chop(@ARGV);
}

for (@ARGV) {
    my $was = $_;
    eval $op;
    die $@ if $@;
    next if $was eq $_; # ignore quietly
    if (-e $_ and !$force)
    {
        warn  "$was not renamed: $_ already exists\n";
    }
    elsif ($no_act or rename $was, $_)
    {
        print "$was renamed as $_\n" if $verbose;
    }
    else
    {
        warn  "Can't rename $was $_: $!\n";
    }
}

Capitalize all filenames in current folder (depend on perl rename)

rename 'y/A-Z/a-z/' *
rename 's/\b((?!(a|of|that|to)\b)[a-z]+)/\u$1/g' *

Turn everything to lowercase (depend on perl rename)

rename 'y/A-Z/a-z/' *

Turn everything to uppercase (depend on perl rename)

rename 'y/a-z/A-Z/' *

SVN Synchorize (auto add and delete all files recursively, also propset Id Revision keywords)

find . -name "._*" | xargs rm -Rf
svn st | grep "^?" | awk '{ print $2}' | while read f; do svn add "$f"; svn propset svn:keywords "Id Revision" "$f"; done;
svn st | grep "^!" | awk '{ print $2}' | while read f; do svn delete "$f"; done;

SVN deploy (create a “deploy” folder with all the modified and added files from a specified revision to HEAD, retaining folder structure)
Example: deploy 815 (will copy everything to ./deploy folder from revision 815 onwards)

svn diff -r $1:HEAD --summarize | grep "^A\|^M" | awk '{ print $2}' | while read f; do mkdir -p `dirname deploy/"$f"`; cp "$f" deploy/"$f"; done

Alias for dir, list just the directories and symbolic links in a directory.

alias dir='ls -Lla|grep ^d'

Svn log by revision and username
example: svn 1000:head vincent

#!/bin/bash
svn log -r $1 | sed -n "/"$2"/,/-----$/ p"

Mount VirturalBox Winhost/LinuxGuest with correct permission

Posted: January 30th, 2011 | Author: | Filed under: Development, System | No Comments »

This may or may not work. Need testing.

VBOXSHAREDFOLDERNAME PATHOFTHEMOUNTEDFOLDER vboxsf rw,uid=1000,gid=1000,auto,exec 0 0


Oblivion Scheme

Posted: December 23rd, 2010 | Author: | Filed under: Linux | 1 Comment »
<style>
* {
    margin: 0;
    padding: 0;
}

div {
    float: left;
    width: 100px;
    height: 75px;
    margin: 10px;
    text-align: center;
}

#wrapper {
    float: none;
    width: 360px;
    margin: 0 auto;
}

#butter1 { background-color:  #fce94f }
#butter2 { background-color:  #edd400 }
#butter3 { background-color:  #c4a000 }

#chameleon1 { background-color:  #8ae234 }
#chameleon2 { background-color:  #73d216 }
#chameleon3 { background-color:  #4e9a06 }

#orange1 { background-color:  #fcaf3e }
#orange2 { background-color:  #f57900 }
#orange3 { background-color:  #ce5c00 }

#skyblue1 { background-color:  #729fcf }
#skyblue2 { background-color:  #3465a4 }
#skyblue3 { background-color:  #204a87 }

#plum1 { background-color:  #ad7fa8 }
#plum2 { background-color:  #75507b }
#plum3 { background-color:  #5c3566 }

#chocolate1 { background-color:  #e9b96e }
#chocolate2 { background-color:  #c17d11 }
#chocolate3 { background-color:  #8f5902 }

#scarletred1 { background-color:  #ef2929 }
#scarletred2 { background-color:  #cc0000 }
#scarletred3 { background-color:  #a40000 }

#aluminium1 { background-color:  #eeeeec }
#aluminium2 { background-color:  #d3d7cf }
#aluminium3 { background-color:  #babdb6 }
#aluminium4 { background-color:  #888a85 }
#aluminium5 { background-color:  #555753 }
#aluminium6 { background-color:  #2e3436 }
</style>

<div id="butter1"></div>
<div id="butter2"></div>
<div id="butter3"></div>
<div id="chameleon1"></div>
<div id="chameleon2"></div>
<div id="chameleon3"></div>
<div id="orange1"></div>
<div id="orange2"></div>
<div id="orange3"></div>
<div id="skyblue1"></div>
<div id="skyblue2"></div>
<div id="skyblue3"></div>
<div id="plum1"></div>
<div id="plum2"></div>
<div id="plum3"></div>
<div id="chocolate1"></div>
<div id="chocolate2"></div>
<div id="chocolate3"></div>
<div id="scarletred1"></div>
<div id="scarletred2"></div>
<div id="scarletred3"></div>
<div id="aluminium1"></div>
<div id="aluminium2"></div>
<div id="aluminium3"></div>
<div id="aluminium4"></div>
<div id="aluminium5"></div>
<div id="aluminium6"></div>

Bash command wallpaper

Posted: September 19th, 2010 | Author: | Filed under: Linux | 2 Comments »

Note: Found on reddit.com


Install Win7 without the 100mb system reserved parition

Posted: September 11th, 2010 | Author: | Filed under: System | No Comments »

Before the Windows setup program starts to copy files (the last chance is at the step where it asks you “Where do you want to install Windows?”), click Shift+F10 to open command line.

# Launch diskpart
diskpart
# List all current disks
list disk
# Select the correct disk (assuming first disk 0 is the main hard disk)
select disk 0
# Wipe it clean
clean
# Create partition (omit size parameter to use all space)
create partition primary size=10000000
# Choose the new created partition
select partition 1
# Activate and format it
active
format fs=ntfs quick
# Done
exit

From mydigitallife.info


Subversion-tools

Posted: August 21st, 2010 | Author: | Filed under: Linux | No Comments »
sudo apt-get install subversion-tools
# svn-backup-dumps: incremental dumpfile-based backup script
# svn-clean: Remove unversioned files from a working copy
# svn-fast-backup: rsync-based backup script for FSFS repositories
# svn-hot-backup: backup script, primarily for BDB repositories
# svn_apply_autoprops: Apply property settings from .subversion/config file to an existing repository
# svn2cl: Generate GNU-style changelog from repository history
# svnmerge: Maintain merge history between two related branches
# svnwrap: Set umask to 002 before calling svn or svnserve
# several example hook scripts: commit-access-control, commit-email, log-police, mailer, svnperms, verify-po

Sass and Haml

Posted: August 17th, 2010 | Author: | Filed under: Linux | No Comments »
sudo apt-get install ruby rubygems1.8
sudo su
gem install haml-edge
vim /etc/environment
# add to PATH
/var/lib/gems/1.8/bin
# add sass watch to scss
sass --watch style.scss:style.css

Make your own mini ubuntu server

Posted: August 16th, 2010 | Author: | Filed under: Linux | No Comments »
# https://help.ubuntu.com/community/Installation/MinimalCD
sudo apt-get install build-essential vim
sudo mount /dev/cdrom /media/cdrom
sudo ./media/cdrom/VBoxLinuxAdditions-amd64.run
sudo dd if=/dev/zero of=/mnt/swap bs=1M count=2000
sudo mkswap /mnt/swap
sudo swapon /mnt/swap
sudo vim /etc/fstab
# /mnt/swap none swap sw 0 0
sudo vim /etc/sysctl.conf
# vm.swappiness=10
sudo apt-get install localepurge
sudo localepurge

Getting Ubuntu works with proxy

Posted: July 15th, 2010 | Author: | Filed under: Linux | No Comments »

This is a problem in Lucid Lynx and potentially also in other versions. If you need a proxy for your network to work, here is the things you need to do.

Source: http://www.uluga.ubuntuforums.org/showthread.php?t=1468738

1) System -> Preferences -> Network proxy

Manual proxy configuration, Use the same proxy for all protocols
HTTP proxy: http://your.proxy.address/ Port: 8081

Click “Apply System-Wide”

2) Synaptic Package Manager

Preferences -> Network tab
Manual config
HTTP proxy: your.proxy.address Port: 8081
FTP proxy: your.proxy.address Port: 8081

3) gksu gedit ~/.bashrc & # add, the following lines at the end:

export https_proxy=https://your.proxy.address:8081
export http_proxy=http://your.proxy.address:8081
export ftp_proxy=ftp://your.proxy.address:8081

4) gksu gedit /etc/wgetrc & # Uncomment or add the lines

https_proxy = https://your.proxy.address:8081/
http_proxy = http://your.proxy.address:8081/
ftp_proxy  = ftp://your.proxy.address:8081/
use_proxy = on

5) gksu gedit /etc/apt/apt.conf & # Add or modify the lines

Acquire::https::proxy "https://your.proxy.address:8081/";
Acquire::http::proxy "http://your.proxy.address:8081/";
Acquire::ftp::proxy "ftp://your.proxy.address:8081/";

Regular Expression Tester

Posted: July 13th, 2010 | Author: | Filed under: Linux | Tags: | No Comments »

http://www.gethifi.com/tools/regex