Pages

Thursday, January 31, 2013

Formatting XML in php


For xml formatted with attributes...
data.xml:
<building_data>
<building address="some address" lat="28.902914" lng="-71.007235" />
<building address="some address" lat="48.892342" lng="-75.0423423" />
<building address="some address" lat="58.929753" lng="-79.1236987" />
</building_data>
php code:
$reader = new XMLReader();

if (!$reader->open("data.xml")) {
    die("Failed to open 'data.xml'");
}

while($reader->read()) {
  if ($reader->nodeType == XMLReader::ELEMENT && $reader->name == 'building') {
    $address = $reader->getAttribute('address');
    $lattitude = $reader->getAttribute('lat');
    $longitude = $reader->getAttribute('lng');
}

$reader->close();

php curl url


<?php function get_data($url) {
  $ch = curl_init();
  $timeout = 5;
  curl_setopt($ch, CURLOPT_URL, $url);
  curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  $data = curl_exec($ch);
  curl_close($ch);
  return $data;
}

$returned_content = get_data('http://flat.to');
echo $returned_content;

?>

Enable error reporting in php

ini_set('display_errors',1);error_reporting(E_ALL);

Tuesday, January 29, 2013

Access elasticsearch from Amazon EC2

Whatever host you use to connect to your ec2 machine, just add the name of the host and the port as 9200. http://ec2-xyz-ab-gh-io.compute-1.amazonaws.com:9200/

Remove all files from a directory linux


$ rm /home/usr/dirname/*
or
$ cd /home/usr/dirname/
$rm *

+jayakrishnan nair says that always use the first option rather than the second one


Read more: http://www.linuxstall.com/delete-all-files-from-directory/#ixzz2JMYbz4Fr

Wednesday, January 23, 2013

git ignore certain files


Sounds like you added app/runtime/application.log to git before applying the .gitignore rules.gitignore doesn't affect git's awareness of existing files, only newly created ones.
git rm --cached app/runtime/* should remove the logs from git's index.
Also add -r if you want to recursively remove a folder.

Tuesday, January 22, 2013

Monday, January 21, 2013

Search query elasticsearch


curl 'http://localhost:9200/blog/post/_search?q=something&pretty=true'

Posting data to elasticsearch

Source: http://www.elasticsearchtutorial.com/elasticsearch-in-5-minutes.html

When the elasticsearch is working you would need to index data to the instance and you will do the same by the following steps.

We're now going to index some data to our ElasticSearch instance. We'll use the example of a blog engine, which has some posts and comments.
curl -XPUT 'http://localhost:9200/blog/user/dilbert' -d '{ "name" : "Dilbert Brown" }'

curl -XPUT 'http://localhost:9200/blog/post/1' -d '
{
    "user": "dilbert",
    "postDate": "2011-12-15",
    "body": "Search is hard. Search should be easy." ,
    "title": "On search"
}'


curl -XPUT 'http://localhost:9200/blog/post/2' -d '
{
    "user": "dilbert",
    "postDate": "2011-12-12",
    "body": "Distribution is hard. Distribution should be easy." ,
    "title": "On distributed search"
}'


curl -XPUT 'http://localhost:9200/blog/post/3' -d '
{
    "user": "dilbert",
    "postDate": "2011-12-10",
    "body": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit, sed diam nonummy nibh euismod tincidunt ut laoreet dolore magna aliquam erat volutpat" ,
    "title": "Lorem ipsum"
}'
To each of these requests, you should have received a response that verifies that the operation was successful, for example:
{"ok":true,"_index":"blog","_type":"post","_id":"1","_version":1}

Check whether elasticsearch is running fine


You can access it at http://localhost:9200 on your web browser, which returns this:
{
  "ok" : true,
  "status" : 200,
  "name" : "Ultra-Marine",
  "version" : {
    "number" : "0.19.0",
    "snapshot_build" : false
  },
  "tagline" : "You Know, for Search"
}

./bin/elasticsearch: 122: exec: : Permission denied



On my local machine

bin/elasticsearch -f

Then go to the following URL http://localhost:9200/blog/post/_search?q=har

But the same is not working on the server!

Error
user@server:/home/ubuntu/elasticsearch-0.19.9# ./bin/elasticsearch -f

This is coming because Java is not installed

Solution
Install Java

./bin/elasticsearch: 122: exec: : Permission denied
The fist step was to install Java on the linux machine. Let's see if that solved the problem. 
Okay! Awesome elasticsearch is working now using the command bin/elasticsearch -f

Tuesday, January 15, 2013

EC2 machine login ubuntu operating system

EC2 Machine if the operating system is Ubuntu then the user should be ubuntu.
Also change the permissions of the keyfile to chmod 400.

Courtesy: JK

Friday, January 4, 2013

CSS Rounded Corners



.roundedtags {
width:400px;
height:25px;
background-color:#CCEBD6;
border: 1px solid #FF8855;
padding: 5px;
    -moz-border-radius: 12px;
    -webkit-border-radius: 12px;
    border-radius: 12px;
}



http://viralpatel.net/blogs/rounded-corner-css-without-images/

Thursday, January 3, 2013

r before a python String

One more important detail we’ve introduced here is that r character in front of the regular expression string. This tells Python that the string is a “raw string” – its contents should not interpret backslashes. In normal Python strings, backslashes are used for escaping special characters – such as in the string '\n', which is a one-character string containing a newline. When you add the r to make it a raw string, Python does not apply its backslash escaping – so, r'\n' is a two-character string containing a literal backslash and a lowercase “n”. There’s a natural collision between Python’s usage of backslashes and the backslashes that are found in regular expressions, so it’s strongly suggested that you use raw strings any time you’re defining a regular expression in Python. From now on, all of the URLpatterns in this book will be raw strings.

Wednesday, January 2, 2013

Django Slashes

If you’re the type of person who likes all URLs to end with slashes (which is the preference of Django’s developers), all you’ll need to do is add a trailing slash to each URLpattern and leave APPEND_SLASH set to True. If you prefer your URLs not to have trailing slashes, or if you want to decide it on a per-URL basis, set APPEND_SLASH to False and put trailing slashes in your URLpatterns as you see fit.