Remove a Remote on GIT

To remove a Remote on GIT you just need to use the got remote rm WHATTOREMOVE

 

origin  git@github.com:user/repo.git (fetch)
# origin  git@github.com:user/repo.git (push)
# destination  git@github.com:forker/repo.git (fetch)
# destination  git@github.com:forker/repo.git (push)
git remote rm destination
# Remove remote

git remote -v
# Verify removal

# origin  git@github.com:user/repo.git (fetch)
# origin  git@github.com:user/repo.git (push)
 

Add Sublime as default editor on Linux

Sublime Text is an awesome text editor. If you’ve never heard of it, you should check it out right now.

I’ve made this tutorial because there’s no installer for the Linux versions of Sublime Text. While that’s not a real problem, I feel there is a cleaner way to go around this. Also, this post will show you how to integrate Sublime Text to Unity (which, I’m glad to report, has now matured into a fully functional user interface).

So let’s get on with this. Here is my how to install Sublime Text on Ubuntu tutorial.

 

Step 1

Download the tarfile that suits you best and extract it. Here’s the command to extract tar.bz2 files:

 

1.tar xf Sublime\ Text\ 2.0.1\ x64.tar.bz2

You’ll notice that I got the 64-bit version. The reason is that it’s lightning fast. So, go for that if you can!

Step 2

You’ll get a “Sublime Text 2″ folder after extraction. This folder contains all the files that Sublime Text will need. So we have to move that folder somewhere more appropriate. Like the “/opt/” folder :

 

1.sudo mv Sublime\ Text\ 2 /opt/

Step 3

At some point you’d want to be able to call Sublime Text from the Terminal by just typing “sublime”. To do that, we’ll just create a symbolic link in “/usr/bin” like thus:

 

1.sudo ln -s /opt/Sublime\ Text\ 2/sublime_text /usr/bin/sublime

Step 4

Now that our files are at the right place, we need to create a launcher in Unity. To do this, we’re going to create a .desktop file in “/usr/share/applications”:

 

1.sudo sublime /usr/share/applications/sublime.desktop

And paste the following content:

 

01.[Desktop Entry]
02.Version=1.0
03.Name=Sublime Text 2
04.# Only KDE 4 seems to use GenericName, so we reuse the KDE strings.
05.# From Ubuntu's language-pack-kde-XX-base packages, version 9.04-20090413.
06.GenericName=Text Editor
07. 
08.Exec=sublime
09.Terminal=false
10.Icon=/opt/Sublime Text 2/Icon/48x48/sublime_text.png
11.Type=Application
12.Categories=TextEditor;IDE;Development
13.X-Ayatana-Desktop-Shortcuts=NewWindow
14. 
15.[NewWindow Shortcut Group]
16.Name=New Window
17.Exec=sublime -n
18.TargetEnvironment=Unity

As you can see, these lines are quite straightforward. Go ahead and experiment a bit with them.

Step 5

Now you would probably want to open all text files with Sublime Text 2. The easiest way to do that is to open up the file associations list:

 

1.sudo sublime /usr/share/applications/defaults.list

And replace all occurrences of gedit.desktop with sublime.desktop.

 

Taken from:

How to install Sublime Text 2 on Ubuntu 12.04 (Unity)

Install and configure Django on Linux Server with Apache and mod_wsgi

If you want to install Django in your Linux machine you need the following:

  • Python 2.5 or higher.
  • Apache 2 or higher.
  • Download mod_wsgi.

In this case I will explain how to do it in a Debian based server, and I will supose you already have python and Apache installed.

1) Download Django from https://www.djangoproject.com/download/  

wget https://www.djangoproject.com/download/1.4.3/tarball/

2) Uncompress the Django source.

 $ tar xzvf Django-1.4.3.tar.gz 

3) Go to Folder

 cd Django-1.4.3

4) Install it using python:

 python manage.py install

2) In this point you should be able to create django project on any folder by typing:

python-admin.py startproject myproject

Linux: Add a folder to the PATH

I had to compile a separated version of python to run some software without remove the current version that is dependent of other applications inside the server.

When I tried to install some other dependent libraries of this version of python, It was not found because binary folder was not in the path.

To add the binary folder temporary I did in this way:

Before add it, the PATH looked like this:

$ echo $PATH

/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/puppet/sbin:/usr/local/puppet/bin:/root/bin

To add the folder to my PATH you just need to update the value of path in this way:

$ PATH=$PATH:/usr/local/python2.7/bin
 
Now if you print again the PATH values you will se something like this:

$ echo $PATH 

/usr/local/jdk/bin:/usr/kerberos/sbin:/usr/kerberos/bin:/usr/lib/courier-imap/sbin:/usr/lib/courier-imap/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/bin:/usr/X11R6/bin:/usr/local/puppet/sbin:/usr/local/puppet/bin:/root/bin:/usr/local/python2.7/bin

 

 

MySQL: Create database, user and assign user

 

Let’s supose you want to create an user called “myuser” with the password “mypassword” and the database called “mydb”.

Create Database:

$mysql> CREATE DATABASE mydb;
Query OK, 1 row affected (0.00 sec)

Create User:

$mysql> CREATE USER ‘myuser‘@’localhost’ IDENTIFIED BY ‘mypassword‘;
Query OK, 0 rows affected (0.02 sec)

Assign user to database:

$mysql> GRANT ALL PRIVILEGES ON mydb.* TO ‘myuser‘@’localhost’;
Query OK, 0 rows affected (0.01 sec)

How to view and clear logs in Linux server

Apache and other services generate logs, that can increase the size rapidly, and could take gigabytes of the hard drive.

View Log with tail

Let’s supose you want to view the log located at /usr/local/apache/logs/mylog.log
$tail /usr/local/apache/logs/mylog.log
It will show the last lines of the log, you can also tell the command to show more lines.

Clear Log

echo “” > /usr/local/apache/logs/mylog.log
It will replace the content of the file for an empty string.

Rename files in Bash with Regular expresions

Sometimes It’s necessary to rename files following some patterns. Do this task manual is a long task, if you thousand of files. For this reason, I use rename command:

Debug and preview:

$ rename’REGULAR EXPRESSION’ files -n

Execute:

$ rename’REGULAR EXPRESSION’ files

Some of the most common expressions I use are:

Convert filename to lowercase:

$rename ‘y/A-Z/a-z/’ *

Add Prefix to filename:

 

$rename ‘s//text-/’ *.mp3

Remove Suffix:

$rename ‘s/ – text//’ *.mp3

Dynamic Rename

rename ‘s/(.*?)-(.*).mp3/$2-$1.mp3/’ *.mp3

More Information in manual of rename:

$man rename

 

 

NAME
       rename – renames multiple files
SYNOPSIS
       rename [ -v ] [ -n ] [ -f ] perlexpr [ files ]
DESCRIPTION
       “rename” renames the filenames supplied according to the rule specified as the first argument.  The
       perlexpr argument is a Perl expression which is expected to modify the $_ string in Perl for at least
       some of the filenames specified.  If a given filename is not modified by the expression, it will not be
       renamed.  If no filenames are given on the command line, filenames will be read via standard input.
       For example, to rename all files matching “*.bak” to strip the extension, you might say
               rename ‘s/\.bak$//’ *.bak
       To translate uppercase names to lower, you’d use
               rename ‘y/A-Z/a-z/’ *
OPTIONS
       -v, –verbose
               Verbose: print names of files successfully renamed.
       -n, –no-act
               No Action: show what files would have been renamed.
       -f, –force
               Force: overwrite existing files.
ENVIRONMENT
       No environment variables are used.

How to increase the performance of a Linux Server

In a server the resources usage is critical and expensive. For this reason is very important to potimize the server to use just the necessary resources.

The use os this tips depends on each server needs, for this reason is important to evaluate if you really can do it. For most of the server, the following recommendation would help to increasse the performance of a server.

 

Tip #1: Disable system services

The top way to increase your VPS performance is to disable any system services that are not necessary. Services that are never used will still use up valuable RAM and CPU time, and also possibly allow your server to be attacked remotely. If you don’t need these services, why have them? Manage the startup scripts that start these services at boot time, and disable them.

Tip #2: Configure MySQL properly.

One of the more common ways to increase the available RAM (or to allocate more RAM to MySQL) is to configure the MySQL cache sizes. If your MySQL server instance is using too much memory, decrease the cache sizes. Likewise, if MySQL gets bogged down with large requests, increase the MySQL cache.

Tip #3: Configure Apache properly.

With Apache 2.0, many system administrators and clients alike have become confused as to the proper configuration of the Apache worker threads. Check how much memory Apache is using, and adjust the StartServers and MinSpareServers directives as needed to free up more memory.

Tip #4: Clean up your modules!

Without exception, there will always be modules or features that are enabled in memory hungry server software packages (such as Apache) that simply are not needed. Take a look at the configuration files for Apache, and decide if you need FrontPage support, or some of the other extra modules that ship with the VPS software packages. Disabling unnecessary modules or plugins will decrease the system memory that server software such as Apache requires, which will give you more resources for the software that needs it!

Tip #5: Disable control panels.

Let’s face it, everyone loves the more popular control panels, such as Cpanel, Plesk, Webmin, and phpMyAdmin. Heck, I’ve even written tutorials on how to use some of these control panel software packages. However, disabling these software packages frees up quite a bit of resources- sometimes as much as 120 MB of RAM! Sometimes the best solution is to disable these control panels until you actually need them- then they can be turned on via a PHP script (albeit somewhat insecure), or via a command entered at a shell prompt.