Skip to main content

Posts

Showing posts from 2014

Get header information by PHP curl

References:  http://stackoverflow.com/questions/11659460/get-header-information-from-php-curl-post-request http://stackoverflow.com/questions/9183178/php-curl-retrieving-response-headers-and-body-in-a-single-request If you want to get the headers, set the option  CURLOPT_HEADER   to 1, and the HTTP response you get back from   curl_exec()   will contain the headers. You can them parse them for the location. $ch = curl_init ( $url ); curl_setopt ( $ch , CURLOPT_HEADER , 1 ); // return HTTP headers with response curl_setopt ( $ch , CURLOPT_RETURNTRANSFER , 1 ); // return the response rather than output it $resp = curl_exec ( $ch ); list ( $headers , $response ) = explode ( "\r\n\r\n" , $resp , 2 ); // $headers now has a string of the HTTP headers // $response is the body of the HTTP response $headers = explode ( "\n" , $headers ); foreach ( $headers as $header ) { if ( stripos ( $header , 'Location:' ) !== false )

CSS specificity

     A good article      http://htmldog.com/guides/css/intermediate/specificity/ It may not seem like something that important, and in most cases you won’t come across any conflicts at all, but the larger and more complex your CSS files become, or the more CSS files you start to juggle with, the greater likelihood there is of conflicts arising. More Specific = Greater Precedence If the selectors are the same then the  last  one will always take precedence. For example, if you had: p { color : red } p { color : blue } The text in the box of  p  elements would be colored blue because that rule came last. However, you won’t usually have identical selectors with conflicting declarations on purpose (because there’s not much point). Conflicts quite legitimately come up, though, when you have  nested  selectors . div p { color : red } p { color : blue } In this example it might seem that a  p  within a  div  would be colored blue, seeing as a rule to color  p  

Why use Apache Jackrabbit

The reference link: http://stackoverflow.com/questions/13890595/apache-jackrabbit-vs-rolling-your-on-content-repository There are several benefits to using an existing JCR implementation, such as  Jackrabbit  or  ModeShape . First and foremost, you immediately get lot of functionality for free: Hierarchical data storage  - Lots of data is naturally hierarchical, and a JCR repository allows you to organize your data in the way that your applications will access it. Anything keyed by a URI, date/time, categories, or folder structures are natural fits for storing in a repository. Use a standard Java API  - The JCR API is standard Java API with a TCK, meaning your applications can rely upon standard behavior and not be tied to a particular JCR implementation. Flexible schema enforcement  - You can choose whether and where the node structure and property values are enforced by how you define and use node types. Data evolution  - Your data structure will likely evolve over time, and

Django 1.7 + Nginx 1.4.6 + uWSGI 2.0.7 deployment

There are many ways to deploy Django project. Nginx and uWSGI is one of them. Nginx deals with static files. uWSGI transfers no-static file request from Nginx to Django. Note that you can only use uWSGI + Django for deployment. I assume you already installed Django, Nginx and uWSGI. (1) Test uWSGI. Write a simple test.py first # test.py def application ( env , start_response ) : start_response ( ' 200 OK ' , [( ' Content - Type ',' text / html ' )]) return "Hello World" Then run command uwsgi -- http : 8001 -- wsgi - file test . py Then you can check if   http://127.0.0.1:8001 is working (2) Test Django run command python manage.py runserver 0.0.0.0:8002 Then you can check if it is working. (3) Write Django uwsgi file write Django_wsgi.py file which is at the same directory with manage.py in Django project #!/usr/bin/env python # coding: utf-8 import os import sys reload(sys) sys.setdefaultenco

pip install uwsgi error

Install uwsgi error by pip The error message is as follows Cleaning up ... Command / usr / bin / python - c "import setuptools, tokenize;__file__='/tmp/pip_build_root/mysql-python/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" You have to install python dev package sudo apt-get install python2.7-dev

JVM Performance Optimization

How to set JVM parameters The performance of the JVM depends on how well it is configured to match the functionality of the application. Although memory is automatically managed using garbage collection and memory reallocation processes, you have control over their frequency. In general, the more memory you have available for your application, the less memory management processes are required, which pause your application. If garbage collections are occurring more frequently than you would want, you can start the JVM with more maximum heap size. The longer it takes for a generation of the heap to fill up, the fewer garbage collections occur. To configure the maximum heap size, use the -Xmx option when you start the JVM. By default, the maximum heap size is set to either 1/4th of the physical memory available to the OS, or to 1 GB (whichever is the smallest). If the problem is with memory reallocation, you can set the initial heap size to be the same as the maximum. This means th

PHP json_decode example

<?php $jsonData = '{ "user":"John", "age":22, "country":"United States" }'; $phpArray = json_decode($jsonData); print_r($phpArray); foreach ($phpArray as $key => $value) {      echo "<p>$key | $value</p>"; } ?>