Pages

Your Ad Here

This Blog is not to read or go through

because, I have never been such a mess


Search the blog instead

Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts

Tuesday, July 19, 2011

How to set up your private GIT Server

Source: http://tumblr.intranation.com/post/766290565/how-set-up-your-own-private-git-server-linux


How to set up your own private Git server on Linux

Update 2: as pointed out by Tim Huegdon, several comments on a Hacker News thread pointing here, and the excellent Pro Git book, Gitolite seems to be a better solution for multi-user hosted Git than Gitosis. I particularly like the branch–level permissions aspect, and what that means for business teams. I’ve left the original article intact.
Update: the ever–vigilant Mike West has pointed out that my instructions for permissions and git checkout were slightly askew. These errors have been rectified.
One of the things I’m attempting to achieve this year is simplifying my life somewhat. Given how much of my life revolves around technology, a large part of this will be consolidating the various services I consume (and often pay for). The mention of payment is important, as up until now I’ve been paying the awesome GitHub for their basic plan.
I don’t have many private repositories with them, and all of them are strictly private code (this blog; Amanda’s blog templates and styles; and some other bits) which don’t require collaborators. For this reason, paying money to GitHub (awesome though they may be) seemed wasteful.
So I decided to move all my private repositories to my own server. This is how I did it.

Set up the server

These instructions were performed on a Debian 5 “Lenny” box, so assume them to be the same on Ubuntu. Substitute the package installation commands as required if you’re on an alternative distribution.
First, if you haven’t done so already, add your public key to the server:
ssh myuser@server.com mkdir .ssh
scp ~/.ssh/id_rsa.pub myuser@server.com:.ssh/authorized_keys
Now we can SSH into our server and install Git:
ssh myserver.com
sudo apt-get update
sudo apt-get install git-core
…and that’s it.

Adding a user

If you intend to share these repositories with any collaborators, at this point you’ll either:
We’ll be following the latter option. So, add a Git user:
sudo adduser git
Now you’ll need to add your public key to the Git user’s authorized_keys:
sudo mkdir /home/git/.ssh
sudo cp ~/.ssh/authorized_keys /home/git/.ssh/
sudo chown -R git:git /home/git/.ssh
sudo chmod 700 !$
sudo chmod 600 /home/git/.ssh/*
Now you’ll be able to authenticate as the Git user via SSH. Test it out:
ssh git@myserver.com

Add your repositories

If you were to not share the repositories, and just wanted to access them for yourself (like I did, since I have no collaborators), you’d do the following as yourself. Otherwise, do it as the Git user we added above.
If using the Git user, log in as them:
login git
Now we can create our repositories:
mkdir myrepo.git
cd !$
git --bare init
The last steps creates an empty repository. We’re assuming you already have a local repository that you just want to push to a remote server.
Repeat that last step for each remote Git repository you want.
Log out of the server as the remaining operations will be completed on your local machine.

Configure your development machine

First, we add the remotes to your local machine. If you’ve already defined a remote named origin(for example, if you followed GitHub’s instructions), you’ll want to delete the remote first:
git remote rm origin
Now we can add our new remote:
git remote add origin git@server.com:myrepo.git
git push origin master
And that’s it. You’ll probably also want to make sure you add a default merge and remote:
git config branch.master.remote origin && git config branch.master.merge refs/heads/master
And that’s all. Now you can push/pull from origin as much as you like, and it’ll be stored remotely on your own myserver.com remote repository.

Bonus points: Make SSH more secure

This has been extensively covered by the excellent Slicehost tutorial, but just to recap:
Edit the SSH config:
sudo vi /etc/ssh/sshd_config
And change the following values:
Port 2207
...
PermitRootLogin no
...
AllowUsers myuser git
...
PasswordAuthentication no
Where 2207 is a port of your choosing. Make sure to add this so your Git remote:
git remote add origin ssh://git@myserver.com:2207/~/myrepo.git


--------------------


Wednesday, July 14, 2010

PHP Jabber Web Chat

Searched a LOT And LOT and finally found one.


PHP/Ajax based Jabber Web Chat Client.


http://blog.jwchat.org/jwchat/

Wednesday, June 23, 2010

Kannel restart script | Attempting to Kill a process in linux until it gets killed

Restarting kannel wasn't simpler, as the bearerbox was not exiting on single stop command for Kannel. So needed to do some tricks on killing the bearerbox first. See the code

#!/bin/bash
while [ true ]
do
 echo "quering bearerbox"
 sleep 1
 count=$(ps -C "bearerbox" | wc -l)
 echo $count
 if [ $count -eq 2 ]
 then
  echo "attempting to kill bearerbox"
  killall bearerbox
 else
  sleep 1
  echo "======= bearerbox killed ========"
  break
 fi
done
sleep 1
bearerbox /etc/kannel/kannel.conf
smsfox /etc/kannel/kannel.conf

Tuesday, April 20, 2010

bash shell quick tips

some quick tips on bash shell programming

a) Variable set/access
varname='some text'
echo $varname
b) store command output to a variable
varname=`somecommand`
echo $varname

or,
an alternate way to do it
varname=$(some command)
echo $varname
eg. - to store current timestamp in a variable
current_timestamp=`date +%s`
echo $current_timestamp
c)s
eg
d)
eg
e)
eg
f)
eg
g)
eg

Friday, April 16, 2010

Automatic Base URL in PHP

# Generate the BASE_URL

$request = $_SERVER["REQUEST_URI"];
$script_path = $_SERVER["SCRIPT_NAME"];
$base_url_len = strlen($script_path) - strlen("index.php");
$arg = explode("/", substr($request, $base_url_len));
$base_url = "http://". $_SERVER["HTTP_HOST"] . substr($script_path, 0, $base_url_len);
define("BASE_URL", $base_url);

author -- acpmasquerade

Thursday, March 18, 2010

PHP array_splice vs. array_slice

Slice
array array_slice ( array $array , int $offset [,int $length [, bool $preserve_keys = false ]] )

Extract a slice of the array

Example :

$input= array("a", "b", "c", "d", "e");

$output = array_slice($input, 2); // returns "c", "d", and "e"
$output = array_slice($input, -2, 1); // returns "d"
$output = array_slice($input, 0, 3); // returns "a", "b", and "c"

// note the differences in the array keys
print_r(array_slice($input, 2, -1));
print_r(array_slice($input, 2, -1, true));





Splice
array array_splice ( array &$input , int $offset [, int $length = 0 [, mixed $replacement ]] )
Remove a portion of the array and replace it with something else

Example :

= array("red", "green", "blue", "yellow");
array_splice($input, 2);
// $input is now array("red", "green")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, -1);
// $input is now array("red", "yellow")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 1, count($input), "orange");
// $input is now array("red", "orange")

$input = array("red", "green", "blue", "yellow");
array_splice($input, -1, 1, array("black", "maroon"));
// $input is now array("red", "green",
// "blue", "black", "maroon")

$input = array("red", "green", "blue", "yellow");
array_splice($input, 3, 0, "purple");
// $input is now array("red", "green",
// "blue", "purple", "yellow");



Thanks - PHP.net

Wednesday, March 10, 2010

Tuesday, March 2, 2010

Programming Contest Questions

My Bookmarks for Programming Contest Questions

ACSL.org
http://acsl.org/acsl/00-01/
http://acsl.org/acsl

HP Code Wars Sample Problems
http://www.hpcodewars.org/index.php?page=samples

IPSC Questions Archives
http://ipsc.ksp.sk/old.php

List of all Programming Contests as defined in Open Directory
http://www.dmoz.org/Computers/Programming/Contests/

The International Obfuscated C Code Contest
http://www.ioccc.org/

ACM Programming Contest
http://homepages.ecs.vuw.ac.nz/~david/acm/

Waterloo Programming Contests
http://plg1.cs.uwaterloo.ca/~acm00/

Tuesday, January 19, 2010

Logo Design Processes for 30 different logs

http://creativenerds.co.uk/articles/30-professional-logo-design-processes-revealed/

Wednesday, December 16, 2009

Crazy Ideas for jquery

Jparallax
http://webdev.stephband.info/parallax.html

Monday, December 14, 2009

Git installing tutorials

The Best one is to do from source.
http://www.how-to-linux.com/2009/01/install-git-161-on-centos-52/

January 16th, 2009

Install the dependencies

yum install gettext-devel expat-devel curl-devel zlib-devel openssl-devel

Get the git source code

wget http://kernel.org/pub/software/scm/git/git-1.6.1.tar.gz

untar the git source code

tar xvfz git-1.6.1.tar.gz

Install

cd git-1.6.1.tar.gz

make prefix=/usr/local all

make prefix=/usr/local install


Wednesday, October 21, 2009

0utput results to a file in SQL

[SQL Query] into outfile "/file/path/here";

Note:
File path should be writable, and should not exist.

Wednesday, August 19, 2009

codeigniter tweak for find_in_set

It was really really frustrating when i could not find any good function in the Codeigniter Active Record Class for FIND_IN_SET type queries.

So, i just buit this.


$set = implode(',',$where);
$this->db->where('1 <=', "FIND_IN_SET(`".$field."`,".$this->db->escape($set).")",false);

Where $where is an array of values

And Yest , it works with a miracle now.

Sunday, August 16, 2009

not in the database

select src from (
select "node/1" as src
union select "node/2" as src
union select "node/3" as src
) temp where src not in (select src from drupal_url_alias)

Tuesday, June 9, 2009

Email validation in php

eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email)

Monday, February 16, 2009

Flash for linux

Two tools I found available to use here for Linux.

Flasm
Haxe

Have not explored properly, will post more if found any more.

Friday, November 7, 2008

Pass Sessions between subdomains in php

If needed to be able to pass session data between subdomains, add the following to the php.ini file.
session.cookie_domain = .mydomain.com

If unable to modify the the php.ini file, add the following before the session.start() function on any page which creates the session cookie.

ini_set("session.cookie_domain", ".mydomain.com")

Sunday, June 29, 2008

Position:fixed solved in IE

top:0px;
left:0px;
position:fixed;
background-color:#f0f0f0;
_position:absolute;
_top:expression(eval(document.body.scrollTop));

Friday, May 9, 2008

Unicode Problem in PHP and database used with it

Unicode Data with PHP 5 and MySQL 4.1




By Andrew Penry


Posted on 11.12.04




Unicode background



In the ever expanding world of e-commerce and information technology, one thing above all is coming to the forefront of internet design - globalization. For many large companies, web documents are translated into many different languages. However, the computer technologies we use for storing data weren't originally designed to deal with information in multiple languages. A web page could show only one set of characters, be it Latin, Cyrillic, Greek, Japanese, or any other character set. Luckily, there is now a standard that is implemented in most browsers called Unicode. This standard encodes characters differently than older technologies, allowing almost all the characters in all human printed languages to be displayed in one page.



Let's clarify the difference between some commonly used terms. A character is a textual unit, such as a letter, number, symbol, punctuation mark, etc. A character set is a set of characters you would like to use. For instance, English uses a Latin character set, while Russian uses a Cyrillic character set. Unicode is a character set that includes characters needed for almost all current written human languages.



When we request text data from the web the data must be encoded. As you know, all data is stored as numbers in computers, and this is what the encoding is. Think of the old decoder rings you would get in cereal boxes. "1" would stand for "A", "2" for "B", etc. The character encoding is the same thing, just on a much larger scale. In computers it matches up integers to characters. The Unicode standard provides several different character encodings, which may be appropriate for different technologies. The one that is leading the way in web development is called UTF-8. UTF-8 contains a numerical representation for over 100,000 characters (all the characters in the Unicode character set).



A glyph is a pictorial representation of a character. For instance the typeset "g" and the handwritten "g" are both glyphs. They look different, but they both mean "letter g." UTF-8 encodes characters, not glyphs. There is only one code for the "letter g." A font is a collection of glyphs. It takes the characters and maps them to glyphs. You must have a font capable of producing the correct glyphs to correctly view Unicode text. Most fonts only have glyphs for subsets of the entire Unicode character set, for instance Latin and Greek. If you have Cyrillic characters in a document and you attempt to render them with such a font, the Cyrillic characters may be rendered as open rectangle, question marks, or not at all. This does not mean that the data is not there, it just means that the font you have selected does not include the glyphs needed to display the data. Very few fonts have glyphs for all the characters in Unicode, primarily because creating more than 100,000 passes the point of diminishing returns for commercial fonts. Code2000 is a $5 shareware font that is the most comprehensive with over 61,000 glyphs. Other fonts can be found at Alan Wood's Unicode site.

How Unicode fits in your Dynamic Web Site



PHP 5 supports UTF-8 natively (without special compilation options) as does MySQL 4.1. However some care needs to be taken to ensure your data is stored and displayed correctly. This article is about storing and retrieving Unicode data in a MySQL 4.1 database using PHP 5. It is not about support for using Unicode characters in variable names and other PHP code, or in the names of tables and columns in MySQL. As Unicode support is still young, I would recommend avoiding such things at this time.

Preparing MySQL for Unicode



Although MySQL has support for UTF-8, it doesn't use it as its default character encoding. If you have control over your server, you can configure it at compilation or through its configuration files to use UTF-8 as default. But since most people don't have complete control, we'll focus on things you can do at the table level.



Let's create a table to hold our data. What is most important here is the "CHARACTER SET utf8" portion. This tells MySQL that all the text in this table will be encoded in UTF-8.

CREATE TABLE document (

id INTEGER UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,

unicodeText VARCHAR(45) NOT NULL

)

CHARACTER SET utf8 COLLATE utf8_general_ci;

Note that MySQL uses a non-standard name "utf8" to mean UTF-8. The COLLATE command is used to tell how to sort the data when using the SORT BY command. Also note that you should always use VARCHAR instead of CHAR with UTF-8. (UTF-8 uses variable sized numbers for different characters. For instance, Latin letters use 1 byte codes, while Japanesee characters are 3 bytes. Using CHAR(10) would force the database to reserve 30 bytes, because it doesn't know ahead of time which length with be used, so it reserves the maximum.)



Telling MySQL how to store the data is just half of the equation. You must also tell MySQL that the data you are passing into it is UTF-8 otherwise it will assume it is in its default encoding. (If you've been doing a lot of searching on Google, and haven't been able to get things to work, this is probably the information that you haven't found.) The command for this is:

SET NAMES 'utf8';

Using PHP and XHTML to encode



Here's our code snippet. You'll want to modify this so that it's valid XHTML before you use it in production:

 1 <?php 

2 $DB = new mysqli('localhost', 'user', 'root', 'dbname');

3 $DB->query("SET NAMES 'utf8'");

4 if (!empty($_POST['ta'])) {

5 $DB->query("UPDATE document SET unicodeText='{$_POST['ta']}' WHERE ID=1");

6 }

7 $result = $DB->query("SELECT unicodeText FROM document WHERE ID=1");

8 $return = $result->fetch_object();

9 $result->close();

10 ?>

11 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"

12 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

13 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">

14 <head>

15 <title>Test</title>

16 </head>

17 <body>

18 <p>Posted: <?php echo $_POST['ta'];?></p>

19 <form enctype="multipart/form-data" method="post" action="test2.php">

20 <fieldset>

21 <textarea name="ta"><?php echo $return->unicodeText;?></textarea>

22 <input type="submit" />

23 </fieldset>

24 </form>

25 </body>

26 </html>

Because we are using MySQL 4.1 with PHP 5 it makes sense to use the MySQLi extension. I like using the OO version of the extension. Line 2 is the connection to the database. Line 3 tells the database to expect UTF-8 data. Lines 4-6 update a row in the database with the Unicode data we send through the form. (Make sure to have some sample data in row 1 of the database when you test this code) Lines 7-8 pull the data back out of the database. Lines 11-12 are important. XHTML defaults to using UTF-8 encoding, unless you specifically tell it otherwise. Using the correct Doctype declaration will alert your browser to use UTF-8 encoding. You will see a lot of things if you search on Google about how you need to put tags about UTF-8 in all sorts of places, like the form, or the form controls, or in META tags. If you are serving valid XHTML this is not necessary. The rest of the code is the form. Lines 18 and 21 will let you compare the raw POST data with what the database returns.



By taking a little care with setting up the database, and using valid XHTML, one can properly store and serve UTF-8 code. Here's a link to a page that will allow you to copy some Unicode that you can paste into your form for testing.
Your Ad Here