<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:blogger='http://schemas.google.com/blogger/2008' xmlns:georss='http://www.georss.org/georss' xmlns:gd="http://schemas.google.com/g/2005" xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-8586650242273506656</id><updated>2024-11-06T04:51:12.395+02:00</updated><category term="web development"/><category term="JavaScript"/><category term="jQuery"/><category term="php"/><category term="C++"/><category term="Html&amp;CSS"/><category term="Other"/><category term="Photoshop"/><category term="Qt"/><category term="UI Design"/><category term="compression"/><category term="encryption"/><category term="jQueryUI"/><category term="open ssl"/><category term="security"/><category term="Оther"/><title type='text'>LexMihaylov - Blog</title><subtitle type='html'>Software Engineer based in Varna</subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>11</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-6902265887866052797</id><published>2016-06-30T14:41:00.001+03:00</published><updated>2016-06-30T14:58:50.687+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><title type='text'>Generating hash using native Crypto API (Example)</title><content type='html'>You can find more information about the crypto api here: &amp;nbsp;&lt;a href=&quot;https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto&quot;&gt;https://developer.mozilla.org/en-US/docs/Web/API/Window/crypto&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:[javascript]&quot;&gt;function arrayBufferToStringAsync( /*ArrayBuffer*/ buffer) {
    var reader = new FileReader();
    return readAsync(reader, &#39;Text&#39;, new Blob([buffer])).then(function() {
        return new Promise(function(resolve, reject) {
            resolve(reader.result);
        });
    });
};

function arrayBufferToHexAsync( /*ArrayBuffer*/ buffer) {
    return new Promise(function(success, error) {
        arrayBufferToStringAsync(buffer).then(function(string) {
            var hex = &#39;&#39;;
            for (var i = 0; i &amp;lt; string.length; i++) {
                var char = (&#39;000&#39; + string.charCodeAt(i).toString(16)).slice(-4);
                hex += char;
            }

            success(hex);
        }).catch(error);
    });
};

function readAsync( /* FileReader */ reader, as, data, encoding) {
    return new Promise(function(resolve, reject) {
        reader.onloadend = resolve;
        reader.onerror = reject;
        reader[&#39;readAs&#39; + as](data, encoding);
    });
};

var blob = new Blob([&#39;Hello World&#39;]);
var reader = new FileReader();

readAsync(reader, &#39;ArrayBuffer&#39;, blob).then(function() {
    var result = reader.result;
    return crypto.subtle.digest(&quot;SHA-1&quot;, result);
}).then(function(hash) {
    return arrayBufferToHexAsync(hash);
}).then(function(hexHash) {
    console.log(hexHash);
});
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/6902265887866052797/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2016/06/generating-hash-using-native-crypto-api.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/6902265887866052797'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/6902265887866052797'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2016/06/generating-hash-using-native-crypto-api.html' title='Generating hash using native Crypto API (Example)'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-5966973351212093706</id><published>2014-02-16T22:57:00.001+02:00</published><updated>2014-02-16T23:21:10.578+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="web development"/><title type='text'>Is NodeJS the best solution for your project</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw_vLJzTdb2aJzOUKOG0Vypf5mkKSMg6frtjemjQSitMf2OPln0yPro2E3vd7vkE6HCKiFUcQ61D9xf8DtJgltVNeMCuBDH3FZ4BgZHzhjPZYvacxLxcuqR-UhBj_WqSGzLoK3TLa8Dm8/s1600/html5-web-apps-with-nodejs.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw_vLJzTdb2aJzOUKOG0Vypf5mkKSMg6frtjemjQSitMf2OPln0yPro2E3vd7vkE6HCKiFUcQ61D9xf8DtJgltVNeMCuBDH3FZ4BgZHzhjPZYvacxLxcuqR-UhBj_WqSGzLoK3TLa8Dm8/s1600/html5-web-apps-with-nodejs.jpg&quot; height=&quot;239&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Ever since all the commotion around NodeJS started, I was wondering, if javascript is really good for backend development. So I started looking up various subjects regarding NodeJS, like how to configure a production server, benchmarks and others. After doing some reading I was able to form an opinion.&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;h3&gt;
1. JavaScript is event driven.&lt;/h3&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Although it would be really good to have an asynchronous and event driven application in the backend, the web is stateless. Most web servers use technologies like CGI and Fast CGI, which enable them to execute scripts. While you will be able to configure node to run as a cgi script, you will also be defeating the purpose of using JavaScript in the backend. So to be able to run a node application properly, you will have to setup a node http server that will serve all the requests.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
&lt;/h3&gt;
&lt;h3&gt;
2. Node is single threaded&lt;/h3&gt;
&lt;div&gt;
This part is really interesting. Node is single threaded but asynchronous, and the thing is that if your node application does not do a lot of CPU intensive operations, it can actually handle more requests than the Apache server. One downside is that you would almost every time have to use a balancer to distribute the load across several node servers.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
3. Building realtime apps&lt;/h3&gt;
&lt;div&gt;
Node is really good for developing applications that transfer realtime data to the users. Realtime applications are easily monitored by using some third party modules like nodetime, node-uptime, log.io and many others.&amp;nbsp;&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
4. Using only one language&lt;/h3&gt;
&lt;div&gt;
NodeJS uses the same engine as google chrome, the V8, and when you are building a web app you will only need to use one language - JavaScript.&lt;/div&gt;
&lt;div&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;h3&gt;
Conclusion&lt;/h3&gt;
&lt;div&gt;
Although you could build an event driver realtime app by using Ruby or Python, it would&#39;ve taken you a lot of time and effort to do so, instead it is way better to use NodeJS, which has event driven asynchronous structure and gives you most of the functionality that you need. But if you are building a large scale web application that needs to handle a lot of concurrent connections, maybe it&#39;s better to stick with a threaded system. Anyway it all depends on the technical requirements of the application that you are building. If you want a more detailed explanation of how NodeJS works, read this great article by Tomislav Capan: &lt;a href=&quot;http://www.toptal.com/nodejs/why-the-hell-would-i-use-node-js&quot; target=&quot;_blank&quot;&gt;Why The Hell Would I Use Node.js? A Case-by-Case Introduction&lt;/a&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/5966973351212093706/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2014/02/is-nodejs-best-solution-for-your-project.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/5966973351212093706'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/5966973351212093706'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2014/02/is-nodejs-best-solution-for-your-project.html' title='Is NodeJS the best solution for your project'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjw_vLJzTdb2aJzOUKOG0Vypf5mkKSMg6frtjemjQSitMf2OPln0yPro2E3vd7vkE6HCKiFUcQ61D9xf8DtJgltVNeMCuBDH3FZ4BgZHzhjPZYvacxLxcuqR-UhBj_WqSGzLoK3TLa8Dm8/s72-c/html5-web-apps-with-nodejs.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-160960063796991876</id><published>2014-02-13T18:32:00.008+02:00</published><updated>2016-11-02T13:01:11.042+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Html&amp;CSS"/><category scheme="http://www.blogger.com/atom/ns#" term="web development"/><title type='text'>CSS class generator using SASS</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;http://mrdanadams.com/images/sass.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;http://mrdanadams.com/images/sass.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Sass give us a lot of flexibility when we are building big web apps. One of my favorite function is to be able to create css classes by using a loop:&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:[sass]&quot;&gt;@mixin zoom($scale) {
    $scale: $scale / 100;
    -webkit-transform-origin: 50% 0;
    -moz-transform-origin: 50% 0;
    -ms-transform-origin: 50% 0;
    -o-transform-origin: 50% 0;
    transform-origin: 50% 0;
    
    -webkit-transform: scale($scale);
    -moz-transform: scale($scale);
    -ms-transform: scale($scale);
    -o-transform: scale($scale);
    transform: scale($scale);
}

$zoomFactor: 100;
@while $zoomFactor &amp;gt;= 20 {
    .zoom-#{$zoomFactor} {
        @include zoom($zoomFactor);
    }
    $zoomFactor: $zoomFactor - 10;
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
The resulting css should look something like this:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:[sass]&quot;&gt;.zoom-100 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(1);
  -moz-transform: scale(1);
  -ms-transform: scale(1);
  -o-transform: scale(1);
  transform: scale(1); }

.zoom-90 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.9);
  -moz-transform: scale(0.9);
  -ms-transform: scale(0.9);
  -o-transform: scale(0.9);
  transform: scale(0.9); }

.zoom-80 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.8);
  -moz-transform: scale(0.8);
  -ms-transform: scale(0.8);
  -o-transform: scale(0.8);
  transform: scale(0.8); }

.zoom-70 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.7);
  -moz-transform: scale(0.7);
  -ms-transform: scale(0.7);
  -o-transform: scale(0.7);
  transform: scale(0.7); }

.zoom-60 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.6);
  -moz-transform: scale(0.6);
  -ms-transform: scale(0.6);
  -o-transform: scale(0.6);
  transform: scale(0.6); }

.zoom-50 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.5);
  -moz-transform: scale(0.5);
  -ms-transform: scale(0.5);
  -o-transform: scale(0.5);
  transform: scale(0.5); }

.zoom-40 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.4);
  -moz-transform: scale(0.4);
  -ms-transform: scale(0.4);
  -o-transform: scale(0.4);
  transform: scale(0.4); }

.zoom-30 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.3);
  -moz-transform: scale(0.3);
  -ms-transform: scale(0.3);
  -o-transform: scale(0.3);
  transform: scale(0.3); }

.zoom-20 {
  -webkit-transform-origin: 50% 0;
  -moz-transform-origin: 50% 0;
  -ms-transform-origin: 50% 0;
  -o-transform-origin: 50% 0;
  transform-origin: 50% 0;
  -webkit-transform: scale(0.2);
  -moz-transform: scale(0.2);
  -ms-transform: scale(0.2);
  -o-transform: scale(0.2);
  transform: scale(0.2); }
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/160960063796991876/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2014/02/css-class-generator-using-sass.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/160960063796991876'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/160960063796991876'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2014/02/css-class-generator-using-sass.html' title='CSS class generator using SASS'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-5421865769938973531</id><published>2014-02-13T16:23:00.003+02:00</published><updated>2014-02-13T16:57:20.127+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="web development"/><title type='text'>Create a jquery extension for handling dom insert events</title><content type='html'>&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ6Gd7-WMNpn1gCqB5ukKn9jADacV_NRok54S1H2Min747l9lOld6-DEfTuWEn79mp8ZGzA6yyWBHo4rLKaE3OmlT9iJMrsSGQ16FVlNEMrIp-VBzDibnz-SrMc0L5CrvH-VhpHYqnarI/s1600/Screen+Shot+2014-02-13+at+4.38.23+PM.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ6Gd7-WMNpn1gCqB5ukKn9jADacV_NRok54S1H2Min747l9lOld6-DEfTuWEn79mp8ZGzA6yyWBHo4rLKaE3OmlT9iJMrsSGQ16FVlNEMrIp-VBzDibnz-SrMc0L5CrvH-VhpHYqnarI/s1600/Screen+Shot+2014-02-13+at+4.38.23+PM.png&quot; height=&quot;254&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Very often when I&#39;m building a web application, I need to dynamically create some objects and append them to the dom. Well thats ok, but if there are some additional calculations that you need to do after inserting your objects, then things are getting a bit messy. For example you need to position your objects according to a relative parent object&#39;s dimensions or initialize a plugin that requires your object to appended to the dom. &amp;nbsp;Well there is always a way of getting around issues like that, but I wanted to keep thing simple and to do that I needed some king of &quot;onDomInsert&quot; event.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;h2&gt;
&lt;b&gt;Solutions&lt;/b&gt;&lt;/h2&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;1. Mutation Observers&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
One way of getting around this was to detect dom changes using &quot;Mutation Observers&quot;. This approach is pretty great and there is a great post on how to use them at &lt;a href=&quot;http://updates.html5rocks.com/2012/02/Detect-DOM-changes-with-Mutation-Observers&quot;&gt;html5rocks.com&lt;/a&gt;, but the problem is that they aren&#39;t that widely supported (&lt;a href=&quot;http://caniuse.com/mutationobserver&quot;&gt;http://caniuse.com/mutationobserver&lt;/a&gt;).&amp;nbsp;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;2. Detecting dom insertions using css animation.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
In my opinion this is a pretty great hack, but still a hack, and because it uses css3 animations, you limit your application usage to only modern browsers. If you want you can read more about that approach here:&amp;nbsp;&lt;a href=&quot;http://davidwalsh.name/detect-node-insertion&quot;&gt;http://davidwalsh.name/detect-node-insertion&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;b&gt;3. Creating a dom insertion event using jquery.&lt;/b&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
After some thinking, I thought that it wouldn&#39;t be so bad to create a jquery extension, that will override some of the dom manipulation methods of jquery with a event trigger. So here it is.&lt;/div&gt;
&lt;h2&gt;
Dom Insert jQuery Extension&lt;/h2&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
The first thing i had to do was to modify some methods to trigger a &quot;beforeDomInsert&quot; and &quot;domInsert&quot; events. After some testing I was able to find that some methods are used in others and there was no point in overriding all of them. For the first part I saved the old methods in a temporary object:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush:[javascript]&quot;&gt;    var parent_methods = {
        // inset inside methods
        /*
         * append
         * appendTo
         * html
         */
        append: $.fn.append,
        /*
         * prepend
         * prependTo
         */
        prepend: $.fn.prepend,
        // insert outside methods
        /*
         * after
         * insertAfter
         */
        after: $.fn.after,
        /*
         * before
         * insertBefore
         */
        before: $.fn.before
    };&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Then I created two function - one for before dom insert event and one for dom insert event&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush:[javascript]&quot;&gt;     /**
     * Triggers an event if item is a jquery object
     * @param {type} item
     * @return {undefined}
     */
    var on_after_insert = function(item) {
        if (item.triggerHandler) {
            if(item.closest(&#39;body&#39;).length &amp;gt; 0) {
                item.triggerHandler(&#39;domInsert&#39;);
                item.find(&#39;*&#39;).each(function() {
                    $(this).triggerHandler(&#39;domInsert&#39;);
                });
            }
        }
    };
    
    /**
     * Triggers an event before the element has been inserted
     * @param {type} item
     * @returns {undefined}
     */
    var on_before_insert = function(item) {
        if(item.triggerHandler) {
            if(item.closest(&#39;body&#39;).length === 0) {
                item.triggerHandler(&#39;beforeDomInsert&#39;);
                item.find(&#39;*&#39;).each(function() {
                    $(this).triggerHandler(&#39;beforeDomInsert&#39;);
                });
            }
        }
    };
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
Note that here I&#39;m using the &#39;triggerHandler&#39;, because &#39;trigger&#39; will cause the event to bubble up and we don&#39;t want that, we just need the event handler to be executed on the specific element and sub elements. To make the event bubble down trough the element&#39;s structure, we use item.find(&#39;*&#39;) and trigger the event on all child elements.&lt;br /&gt;
&lt;br /&gt;
Now all we need to do is override the existing jquery methods with our own implementation.&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush:[javascript]&quot;&gt;    /**
     * modifys a dom insertion method
     * @param {type} method
     * @return {unresolved}
     */
    var dom_events_modifyer = function(method) {
        return function() {
            var args = Array.prototype.splice.call(arguments,0),
                result = undefined,
                i = 0;
        
            for(i = 0; i &amp;lt; args.length; i++) {
                on_before_insert(args[i]);
            }
            
            result = parent_methods[method].apply(this, args);
            
            for(i = 0; i &amp;lt; args.length; i++) {
                on_after_insert(args[i]);
            }

            return result;
        };
    };
    
    $.fn.append = dom_events_modifyer(&#39;append&#39;);
    $.fn.prepend = dom_events_modifyer(&#39;prepend&#39;);
    $.fn.after = dom_events_modifyer(&#39;after&#39;);
    $.fn.before = dom_events_modifyer(&#39;before&#39;);
&lt;/pre&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;
And we&#39;re done. Here is the complete jquery extension code:&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;pre class=&quot;brush:[javascript]&quot;&gt;/** 
 * Adds a domInsert event to dom insertion methods 
 */

(function($) {
    
    var parent_methods = {
        // inset inside methods
        /*
         * append
         * appendTo
         * html
         */
        append: $.fn.append,
        /*
         * prepend
         * prependTo
         */
        prepend: $.fn.prepend,
        // insert outside methods
        /*
         * after
         * insertAfter
         */
        after: $.fn.after,
        /*
         * before
         * insertBefore
         */
        before: $.fn.before
    };
    
    /**
     * Triggers an event if item is a jquery object
     * @param {type} item
     * @return {undefined}
     */
    var on_after_insert = function(item) {
        if (item.triggerHandler) {
            if(item.closest(&#39;body&#39;).length &amp;gt; 0) {
                item.triggerHandler(&#39;domInsert&#39;);
                item.find(&#39;*&#39;).each(function() {
                    $(this).triggerHandler(&#39;domInsert&#39;);
                });
            }
        }
    };
    
    /**
     * Triggers an event before the element has been inserted
     * @param {type} item
     * @returns {undefined}
     */
    var on_before_insert = function(item) {
        if(item.triggerHandler) {
            if(item.closest(&#39;body&#39;).length === 0) {
                item.triggerHandler(&#39;beforeDomInsert&#39;);
                item.find(&#39;*&#39;).each(function() {
                    $(this).triggerHandler(&#39;beforeDomInsert&#39;);
                });
            }
        }
    };
    
    /**
     * modifys a dom insertion method
     * @param {type} method
     * @return {unresolved}
     */
    var dom_events_modifyer = function(method) {
        return function() {
            var args = Array.prototype.splice.call(arguments,0),
                result = undefined,
                i = 0;
        
            for(i = 0; i &amp;lt; args.length; i++) {
                on_before_insert(args[i]);
            }
            
            result = parent_methods[method].apply(this, args);
            
            for(i = 0; i &amp;lt; args.length; i++) {
                on_after_insert(args[i]);
            }

            return result;
        };
    };
    
    $.fn.append = dom_events_modifyer(&#39;append&#39;);
    $.fn.prepend = dom_events_modifyer(&#39;prepend&#39;);
    $.fn.after = dom_events_modifyer(&#39;after&#39;);
    $.fn.before = dom_events_modifyer(&#39;before&#39;);
    
})($);
&lt;/pre&gt;
</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/5421865769938973531/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2014/02/create-jquery-extension-for-handling.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/5421865769938973531'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/5421865769938973531'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2014/02/create-jquery-extension-for-handling.html' title='Create a jquery extension for handling dom insert events'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjQ6Gd7-WMNpn1gCqB5ukKn9jADacV_NRok54S1H2Min747l9lOld6-DEfTuWEn79mp8ZGzA6yyWBHo4rLKaE3OmlT9iJMrsSGQ16FVlNEMrIp-VBzDibnz-SrMc0L5CrvH-VhpHYqnarI/s72-c/Screen+Shot+2014-02-13+at+4.38.23+PM.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-1973067584517522425</id><published>2013-03-29T09:49:00.000+02:00</published><updated>2013-03-29T12:17:04.583+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Other"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><title type='text'>Fixing filename encoding using a PHP console script</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCiNiWQM3DU_J7RmsZ2Zf3VmCVCu-0ObnPrQL_3XXvM58KPk8OO64NBTyQ03yJO86uM1w4WKjx624MgIIIcuimJNV21hgs3ZbO2ipdQSR4eseOIUBp7oDnOdhp5eJeBZdtJztPfOlctts/s1600/encoding.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCiNiWQM3DU_J7RmsZ2Zf3VmCVCu-0ObnPrQL_3XXvM58KPk8OO64NBTyQ03yJO86uM1w4WKjx624MgIIIcuimJNV21hgs3ZbO2ipdQSR4eseOIUBp7oDnOdhp5eJeBZdtJztPfOlctts/s1600/encoding.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
Recently i had received an archive with files required for a project. It was awful. The filenames were in ciryllic and on top of that the encoding was broken. So what to do when something like this happens? I wrote a little php script that walks all directories and files and renames the files with the appropriate encoding:&lt;br /&gt;
&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:[php]&quot;&gt;&amp;lt;?php
const FromEncoding = &#39;utf-8&#39;;
const ToEncoding = &#39;cp1251&#39;;


function convertEncoding($filename) {
    return mb_convert_encoding($filename, ToEncoding, FromEncoding);
}

function traverse($dir) {
    $handler = opendir($dir);
 
    if(!$handler) {
        echo (&quot;\n* * *\tError: Cannot open directory ($dir)\n&quot;);
        return 0;
    }
 
    echo &quot;* * *\tENTERING: &quot; . $dir . PHP_EOL;
 
    while($filename = readdir($handler)) {
        if($filename != &#39;.&#39; &amp;amp;&amp;amp; $filename != &#39;..&#39;) {
            echo $dir . &#39;/&#39; . $filename;
         
            $newName = convertEncoding($filename);
         
            rename($dir . &#39;/&#39; . $filename, $dir . &#39;/&#39; . $newName);
         
            echo &quot;\n\t=&amp;gt;\t&quot; . $newName . PHP_EOL;
         
            if(is_dir($dir . &#39;/&#39; . $newName)) {
                traverse($dir . &#39;/&#39; . $newName);
            }
        }
    }
}

if(is_dir($argv[1])) {
    chdir($argv[1]);
    traverse(getcwd());
} else {
    die(&quot;\n* * *\tError: Cannot open directory ($argv[1])\n&quot;);
}

echo &quot;\n* * * DONE * * *\n&quot;;
?&amp;gt;
&lt;/pre&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
After that just open a terminal window and write:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class=&quot;brush:[bash]&quot;&gt;php mb_conv.php /PATH
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
After that i found a really good tool that does the same thing, it&#39;s called &lt;a href=&quot;http://www.j3e.de/linux/convmv/man/&quot; target=&quot;_blank&quot;&gt;convmv&lt;/a&gt;.&lt;br /&gt;
If you are using Ubuntu you can open a terminal window and type:&lt;br /&gt;
&lt;pre class=&quot;brush:[bash]&quot;&gt;sudo apt-get install convmv
convmv --notest -r -f cp1251 -t utf8 DIR
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
Hope that helps someone out there :).</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/1973067584517522425/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/fixing-filename-encoding-using-php.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/1973067584517522425'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/1973067584517522425'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/fixing-filename-encoding-using-php.html' title='Fixing filename encoding using a PHP console script'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjCiNiWQM3DU_J7RmsZ2Zf3VmCVCu-0ObnPrQL_3XXvM58KPk8OO64NBTyQ03yJO86uM1w4WKjx624MgIIIcuimJNV21hgs3ZbO2ipdQSR4eseOIUBp7oDnOdhp5eJeBZdtJztPfOlctts/s72-c/encoding.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-2997914541832690394</id><published>2013-03-15T23:51:00.001+02:00</published><updated>2013-03-21T09:32:06.374+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="Оther"/><title type='text'>Startup Weekend Varna: Как ще протече събитието</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVTHukQSxqpD4sKNANReKRxBlb2O-SIXBfvQ4RctWNjFeoid9DH23yaAL3SmYCvKEoeAwqHXC2a69R-Z6VeamJVvD-1FFNvBDC_kOezMv4SWK7oCTmF2vsBLdzA3hHgsTF6ETwACrOehI/s1600/Varna.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;206&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVTHukQSxqpD4sKNANReKRxBlb2O-SIXBfvQ4RctWNjFeoid9DH23yaAL3SmYCvKEoeAwqHXC2a69R-Z6VeamJVvD-1FFNvBDC_kOezMv4SWK7oCTmF2vsBLdzA3hHgsTF6ETwACrOehI/s640/Varna.png&quot; width=&quot;100%&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #333333; font-family: LatoRegular, Lucida, Verdana, sans-serif; font-size: 14px; font: inherit; line-height: 22.265625px; margin-bottom: 14px; margin-top: 14px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;a href=&quot;http://varna.startupweekend.org/&quot; target=&quot;_blank&quot;&gt;Startup Weekend Varna&lt;/a&gt; започва с регистрирането на участниците в Петък 18.00 и на техните идеи. След това на всеки участник се дава възможност да презентира идеята си пред другите в рамките на 60 секунди (Elevator pitch / Power pitch). Участниците гласуват за най-добрите идеи и се присъединяват към определна идея, която им е допаднала. Сформираните екипи често включват маркетолог, програмист, дизайнер и бизнес анализатор или предприемач.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #333333; font-family: LatoRegular, Lucida, Verdana, sans-serif; font-size: 14px; font: inherit; line-height: 22.265625px; margin-bottom: 14px; margin-top: 14px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Дните Събота и Неделя се използват за разработването на продукт или крайното оформяне на бизнес идеята в бизнес план с ясни параметри за изпълнение. Като през тези два дни на разположение на екипите са Бизнес ментори и Технически помощници. Те помагат да се изясни пазара на различните идеи, как да се достигне до клиента, точни бизнес модели и монетаризационен модел.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #333333; font-family: LatoRegular, Lucida, Verdana, sans-serif; font-size: 14px; font: inherit; line-height: 22.265625px; margin-bottom: 14px; margin-top: 14px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
В Неделя 18.00 всички екипи представят готовите си продукти или услугите пред всички частници и журито, което награждава най-добрите. Често този етап от събитието присъстват бизнес ангели и инвеститори желаещи да подпомогнат стартиращите идейни бизнеси.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;border: 0px; color: #333333; font-family: LatoRegular, Lucida, Verdana, sans-serif; font-size: 14px; font: inherit; line-height: 22.265625px; margin-bottom: 14px; margin-top: 14px; padding: 0px; vertical-align: baseline;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Това събитие ще отбележи Варна на световната карта на предприемачестовто за млади хора и ще сформира кръг от млади, позитивни и предприемчиви хора които целят да използват знанието от университета, високите технологии и инновации за да стартират бизнес.&lt;/div&gt;
&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/2997914541832690394/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/startup-weekend-varna.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/2997914541832690394'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/2997914541832690394'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/startup-weekend-varna.html' title='Startup Weekend Varna: Как ще протече събитието'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgVTHukQSxqpD4sKNANReKRxBlb2O-SIXBfvQ4RctWNjFeoid9DH23yaAL3SmYCvKEoeAwqHXC2a69R-Z6VeamJVvD-1FFNvBDC_kOezMv4SWK7oCTmF2vsBLdzA3hHgsTF6ETwACrOehI/s72-c/Varna.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-3849284425682839634</id><published>2013-03-15T10:43:00.000+02:00</published><updated>2013-03-21T09:33:29.248+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="C++"/><category scheme="http://www.blogger.com/atom/ns#" term="Photoshop"/><category scheme="http://www.blogger.com/atom/ns#" term="Qt"/><category scheme="http://www.blogger.com/atom/ns#" term="UI Design"/><title type='text'>UI Creation using QtQuick</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB0lcpu0nAZVeedjGKhEKRIhCzzcjaszgTXdaBpYO38klFB7dekXXgzyJl3GrH0suhWSDsUgYitL7hLCRrmtpoTazForEuz08icnVVymmbVkC3kcWj0hNJQkdPRo2lfOUZwwtGGgSoi-g/s1600/Qt.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;99&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB0lcpu0nAZVeedjGKhEKRIhCzzcjaszgTXdaBpYO38klFB7dekXXgzyJl3GrH0suhWSDsUgYitL7hLCRrmtpoTazForEuz08icnVVymmbVkC3kcWj0hNJQkdPRo2lfOUZwwtGGgSoi-g/s200/Qt.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
Justin Noel, Senior Consulting Engineer at ICS gives a detailed overview of Qt Quick, and how to create killer user interfaces using a combination of Qt Quick, C++, and PhotoShop.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, Bitstream Charter, Times, serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;Part 1:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, Bitstream Charter, Times, serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;&lt;object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot; height=&quot;315&quot; width=&quot;560&quot;&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;src&quot; value=&quot;http://www.youtube-nocookie.com/v/2_W9YotVDWM?version=3&amp;amp;hl=bg_BG&quot; /&gt;&lt;param name=&quot;allowfullscreen&quot; value=&quot;true&quot; /&gt;&lt;embed width=&quot;560&quot; height=&quot;315&quot; type=&quot;application/x-shockwave-flash&quot; src=&quot;http://www.youtube-nocookie.com/v/2_W9YotVDWM?version=3&amp;amp;hl=bg_BG&quot; allowFullScreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; /&gt;&lt;/object&gt;&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, Bitstream Charter, Times, serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;Part 2:&lt;/span&gt;&lt;/span&gt;&lt;br /&gt;
&lt;span style=&quot;font-family: Georgia, Times New Roman, Bitstream Charter, Times, serif; font-size: x-small;&quot;&gt;&lt;span style=&quot;line-height: 19px;&quot;&gt;&lt;object classid=&quot;clsid:d27cdb6e-ae6d-11cf-96b8-444553540000&quot; codebase=&quot;http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0&quot; height=&quot;315&quot; width=&quot;560&quot;&gt;&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot; /&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot; /&gt;&lt;param name=&quot;src&quot; value=&quot;http://www.youtube-nocookie.com/v/AnOGELkt6ac?hl=bg_BG&amp;amp;version=3&quot; /&gt;&lt;param name=&quot;allowfullscreen&quot; value=&quot;true&quot; /&gt;&lt;embed width=&quot;560&quot; height=&quot;315&quot; type=&quot;application/x-shockwave-flash&quot; src=&quot;http://www.youtube-nocookie.com/v/AnOGELkt6ac?hl=bg_BG&amp;amp;version=3&quot; allowFullScreen=&quot;true&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; /&gt;&lt;/object&gt;&lt;/span&gt;&lt;/span&gt;</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/3849284425682839634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/ui-creation-using-qtquick.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/3849284425682839634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/3849284425682839634'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/ui-creation-using-qtquick.html' title='UI Creation using QtQuick'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjB0lcpu0nAZVeedjGKhEKRIhCzzcjaszgTXdaBpYO38klFB7dekXXgzyJl3GrH0suhWSDsUgYitL7hLCRrmtpoTazForEuz08icnVVymmbVkC3kcWj0hNJQkdPRo2lfOUZwwtGGgSoi-g/s72-c/Qt.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-7558684945483952480</id><published>2013-03-15T10:35:00.001+02:00</published><updated>2013-03-31T15:12:12.241+03:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="jQueryUI"/><category scheme="http://www.blogger.com/atom/ns#" term="web development"/><title type='text'>JQuery UI resizable layout</title><content type='html'>&lt;br /&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8JlV8tw-BPQA0oOyKOg-6cji-YLBxTwubLRMvRqRYdI63QVzbdaXb6bEEvn_sQjzhfFBTdwA9qKPC0Ik-THVw92K8wUWwvKPtyzZnBK9_0UbGcLhl-Mwi2V278lc_rwSlzlVRnosmtto/s1600/Screenshot.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;193&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8JlV8tw-BPQA0oOyKOg-6cji-YLBxTwubLRMvRqRYdI63QVzbdaXb6bEEvn_sQjzhfFBTdwA9qKPC0Ik-THVw92K8wUWwvKPtyzZnBK9_0UbGcLhl-Mwi2V278lc_rwSlzlVRnosmtto/s320/Screenshot.png&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
I&#39;ve created a plugin for jquery ui that enables developers to create layouts that can be resized by the users, and brings a more functional frontend design.&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
You will need git to download it. The repository url is&amp;nbsp;&lt;a data-mce-href=&quot;https://github.com/lexmihaylov/jquery.ui.layout&quot; href=&quot;https://github.com/lexmihaylov/jquery.ui.layout&quot; target=&quot;_blank&quot;&gt;https://github.com/lexmihaylov/jquery.ui.layout&lt;/a&gt;&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;strong&gt;How to use:&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
Creating a vertical resizable layout:&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;pre class=brush:[html]&gt;
&lt;script&gt;
  $(function() {
      $(&#39;#layout&#39;).layout({
        type: &#39;vertical&#39;,
        resizable: true,
        helper: false,
        panes: [
          [&#39;#pane1&#39;, {minWidth: 200, maxWidth: 400}],
          [&#39;#pane2&#39;]
        ]
      });
  });
&lt;/script&gt;
 
&lt;div id=&quot;layout&quot;&gt;
  &lt;div id=&quot;grid1&quot; style=&quot;width: 200px&quot;&gt;Some Content Here&lt;/div&gt;
  &lt;div id=&quot;grid2&quot;&gt;Some Content Here&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
Creating a horizontal layout:&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:[html]&quot;&gt;
&lt;script&gt;
  $(function() {
     $(&#39;#hLayout&#39;).layout({
       type: &#39;horizontal&#39;,
       resizable: true,
       helper: &#39;ui-layout-resize-h&#39;,
       panes: [
         [&#39;#pane3&#39;, {minHeight: 200, maxHeight: 400}],
         [&#39;#pane4&#39;]
       ]
     });
  });
&lt;/script&gt;
 
&lt;div id=&quot;hLayout&quot;&gt;
  &lt;div id=&quot;pane3&quot; style=&quot;height: 200px&quot;&gt;Some content&lt;/div&gt;
  &lt;div id=&quot;pane4&quot;&gt;Some content&lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
Creating a mixture of horizontal and vertical layouts:&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;pre class=&quot;brush:[html]&quot;&gt;
&lt;script&gt;
  $(function() {
    $(&#39;#layout&#39;).layout({
      type: &#39;vertical&#39;,
      resizable: true,
      helper: false,
      panes: [
        [&#39;#pane1&#39;, {minWidth: 200, maxWidth: 400}],
        [&#39;#pane2&#39;]
      ]
    });
                    
    $(&#39;#hLayout&#39;).layout({
      type: &#39;horizontal&#39;,
      resizable: true,
      helper: &#39;ui-layout-resize-h&#39;,
      panes: [
        [&#39;#pane3&#39;, {minHeight: 200, maxHeight: 400}],
        [&#39;#pane4&#39;]
      ]
    });
  });
&lt;/script&gt;
 
&lt;div id=&quot;layout&quot;&gt;
  &lt;div id=&quot;pane1&quot; style=&quot;width: 200px;&quot;&gt;Your content&lt;/div&gt;
  &lt;div id=&quot;pane2&quot;&gt;
    &lt;div id=&quot;hLayout&quot;&gt;
      &lt;div id=&quot;pane3&quot; style=&quot;height: 200px&quot;&gt;Your Content&lt;/div&gt;
      &lt;div id=&quot;pane4&quot;&gt;Your content&lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
&lt;/div&gt;
&lt;/pre&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;strong&gt;Options:&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;b&gt;type&lt;/b&gt; - determines the type of the layout (horizontal or vertical);&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;b&gt;resizable&lt;/b&gt; - if true than the layout would be resizable be the users&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;b&gt;helper&lt;/b&gt; - enables or disables the use of helpers when resizing&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
&lt;b&gt;panes&lt;/b&gt; - an array of panes; the pane should be set as an array: the first element of the array should be the id of the element and the second is optional and it should be an object that holds the minimum and maximum width or height used when resizing.&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px; text-align: justify;&quot;&gt;
You can view a live demo&amp;nbsp;&lt;a data-mce-href=&quot;https://c9.io/lexmihaylov/ui_layout/workspace/index.html&quot; href=&quot;https://c9.io/lexmihaylov/ui_layout/workspace/index.html&quot; target=&quot;_blank&quot; title=&quot;Jquery Ui Resizable Layout&quot;&gt;here&lt;/a&gt;.&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/7558684945483952480/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/jquery-ui-resizable-layout.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/7558684945483952480'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/7558684945483952480'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/jquery-ui-resizable-layout.html' title='JQuery UI resizable layout'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEj8JlV8tw-BPQA0oOyKOg-6cji-YLBxTwubLRMvRqRYdI63QVzbdaXb6bEEvn_sQjzhfFBTdwA9qKPC0Ik-THVw92K8wUWwvKPtyzZnBK9_0UbGcLhl-Mwi2V278lc_rwSlzlVRnosmtto/s72-c/Screenshot.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-9145399328525553719</id><published>2013-03-15T10:15:00.000+02:00</published><updated>2013-03-21T09:36:11.376+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="JavaScript"/><category scheme="http://www.blogger.com/atom/ns#" term="jQuery"/><category scheme="http://www.blogger.com/atom/ns#" term="web development"/><title type='text'>Object Oriented JavaScript Using JQuery</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIvF31GG31nIf0Xh1S9hEsMxvFi8WdFjXgtuVfI_8pqlAqbFVVkw4irwkhJuhqBdGxEyrwstLcME9-tx2UQwKcSX66DCKB0KcCgHXMIVAAOPwCpyqUgFRUSJdNOMv3ApnCxdhyphenhypheneGru_D4/s1600/Javascript_icon.svg.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIvF31GG31nIf0Xh1S9hEsMxvFi8WdFjXgtuVfI_8pqlAqbFVVkw4irwkhJuhqBdGxEyrwstLcME9-tx2UQwKcSX66DCKB0KcCgHXMIVAAOPwCpyqUgFRUSJdNOMv3ApnCxdhyphenhypheneGru_D4/s1600/Javascript_icon.svg.png&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
Javascript becomes more and more popular these days, and what best way to write reusable code if not writing it the OO style. JS is not your tipical programming language, the classes in js are not actualy classes, but funcions. Every function has a prototype object that contains methods and properties, we can use this object to write javascript classes.&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
1. Creating a JS Class:&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
To create a js class you need to create a function and after that you can use the this keyword to access the object&#39;s properties and methods.&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;br /&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434573.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
2. Inheritance&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
Basicaly to inherit a class you need to extend the parent&#39;s class prototype object. To do that we can use jQuery.extend() function.&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434657.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
To call a parent method in the context of the child class you can use the call function:&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434678.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
3. How to extend the jQuery Class&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434713.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
After creating the object in the constructor we have to set the object&#39;s constructor to jquery&#39;s constructor, because jquery is using it internaly.&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/9145399328525553719/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/object-oriented-javascript-using-jquery.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/9145399328525553719'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/9145399328525553719'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/object-oriented-javascript-using-jquery.html' title='Object Oriented JavaScript Using JQuery'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhIvF31GG31nIf0Xh1S9hEsMxvFi8WdFjXgtuVfI_8pqlAqbFVVkw4irwkhJuhqBdGxEyrwstLcME9-tx2UQwKcSX66DCKB0KcCgHXMIVAAOPwCpyqUgFRUSJdNOMv3ApnCxdhyphenhypheneGru_D4/s72-c/Javascript_icon.svg.png" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-2811803634622326165</id><published>2013-03-15T09:59:00.001+02:00</published><updated>2013-03-21T09:36:59.296+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="compression"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="web development"/><title type='text'>Using compression in REST communication between applications</title><content type='html'>&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY-6blgIR_S90H0rGf3hzZs6uocbIbXDgiDWx74EWCcAq5grfzGDgJErsy7jGlRziSXpZ-oECwaUnQWl8vipxmcggu_d7w7ZxcYZ7fDZNiuBU2GWj-UqoCxK599P12OB7xDl_BiOJHpx0/s1600/Compression.jpg&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em; text-align: justify;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;240&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY-6blgIR_S90H0rGf3hzZs6uocbIbXDgiDWx74EWCcAq5grfzGDgJErsy7jGlRziSXpZ-oECwaUnQWl8vipxmcggu_d7w7ZxcYZ7fDZNiuBU2GWj-UqoCxK599P12OB7xDl_BiOJHpx0/s320/Compression.jpg&quot; width=&quot;320&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;span style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;When you are working on a large project, there are alot of situations that the project is composed of more than one application. The problem here is how to solder everything together. There are alot of ways you can handle communication between applications, for example you can use XML, JSON, HTTP Requests, etc. If you are using PHP for building your project maybe the easiest way of handling communication is by using JSON.&lt;/span&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
There are two buildin function that you need to look at before starting:&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
-&amp;nbsp;&lt;strong&gt;json_encode()&lt;/strong&gt;:&amp;nbsp;&lt;a data-mce-href=&quot;http://php.net/manual/en/function.json-encode.php&quot; href=&quot;http://php.net/manual/en/function.json-encode.php&quot;&gt;http://php.net/manual/en/function.json-encode.php&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
-&amp;nbsp;&lt;strong&gt;json_decode()&lt;/strong&gt;:&amp;nbsp;&lt;a data-mce-href=&quot;http://php.net/manual/en/function.json-decode.php&quot; href=&quot;http://php.net/manual/en/function.json-decode.php&quot;&gt;http://php.net/manual/en/function.json-decode.php&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We will use these two functions to serializing and deserializing the data that we need to send between applications.&lt;/div&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
So what we need now is methods for encoding data and sending the encoded data to a certain url:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434436.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Now we have two static methods:&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
- send - sends the json string via http post request&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
- encodeParams - convert an object or array to json string&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Because we don&#39;t need to wait for the request to finish we add:&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
curl_setopt($curl, CURLOPT_FRESH_CONNECT, true);&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
curl_setopt($curl, CURLOPT_TIMEOUT, 1);&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
This two lines of code mean that the connection will be broken after one second.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
If there is alot of data that needs to be tranfered then we will need to use somekind of data compression. To do that in php we can use the zlip library.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
-&amp;nbsp;gzcompress() -&amp;nbsp;&lt;a data-mce-href=&quot;http://php.net/manual/en/function.gzcompress.php&quot; href=&quot;http://php.net/manual/en/function.gzcompress.php&quot;&gt;http://php.net/manual/en/function.gzcompress.php&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
-&amp;nbsp;gzuncompress() -&amp;nbsp;&lt;a data-mce-href=&quot;http://php.net/manual/en/function.gzuncompress.php&quot; href=&quot;http://php.net/manual/en/function.gzuncompress.php&quot;&gt;http://php.net/manual/en/function.gzuncompress.php&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434417.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
We update the encodeParams method to handle zlip compression.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
1. We convert the object to a json string&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
2. We compress that string using gzcompression&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
3. Because the compressed string has many bytes that connot be send via a post request, we need to encoded. We use base64 firs because we wont gain much if url encode it first.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
4. We encode the string with urlencode, because we need to send it via a http post request.&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
To recieve compressed data from another application we need to decode the post prameter:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434412.js&quot;&gt;&lt;/script&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
Here is the complete class:&lt;/div&gt;
&lt;div style=&quot;text-align: justify;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div style=&quot;font-family: Georgia, &#39;Times New Roman&#39;, &#39;Bitstream Charter&#39;, Times, serif; font-size: 13px; line-height: 19px;&quot;&gt;
&lt;script src=&quot;https://gist.github.com/lexmihaylov/4434387.js&quot;&gt;&lt;/script&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/2811803634622326165/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/using-compression-in-rest-communication.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/2811803634622326165'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/2811803634622326165'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/using-compression-in-rest-communication.html' title='Using compression in REST communication between applications'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhY-6blgIR_S90H0rGf3hzZs6uocbIbXDgiDWx74EWCcAq5grfzGDgJErsy7jGlRziSXpZ-oECwaUnQWl8vipxmcggu_d7w7ZxcYZ7fDZNiuBU2GWj-UqoCxK599P12OB7xDl_BiOJHpx0/s72-c/Compression.jpg" height="72" width="72"/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-8586650242273506656.post-2052698986589990319</id><published>2012-11-06T13:54:00.000+02:00</published><updated>2013-03-15T10:11:24.811+02:00</updated><category scheme="http://www.blogger.com/atom/ns#" term="encryption"/><category scheme="http://www.blogger.com/atom/ns#" term="open ssl"/><category scheme="http://www.blogger.com/atom/ns#" term="php"/><category scheme="http://www.blogger.com/atom/ns#" term="security"/><category scheme="http://www.blogger.com/atom/ns#" term="web development"/><title type='text'>Securing your data using PHP and OpenSSL</title><content type='html'>&lt;br /&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2YCUIrUO8OJFswbtaDrmNauvUsQHjbh3SyNbH2kqXy3mCKtEJFS518nD4XPbhqh-J2f7CWdeqMCFas2Vqa0J5S75bc0q3IGGK0-Ioh3yLSSNMfivM4De8U01x0eRH7EJIUuyfeZbrVgI/s1600/secure-site.png&quot; imageanchor=&quot;1&quot; style=&quot;clear: left; float: left; margin-bottom: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; height=&quot;200&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2YCUIrUO8OJFswbtaDrmNauvUsQHjbh3SyNbH2kqXy3mCKtEJFS518nD4XPbhqh-J2f7CWdeqMCFas2Vqa0J5S75bc0q3IGGK0-Ioh3yLSSNMfivM4De8U01x0eRH7EJIUuyfeZbrVgI/s200/secure-site.png&quot; width=&quot;200&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
I saw that there wasn’t alot of information on the internet about how to encrypt data in your web application using php an openssl, so here it is.&lt;br /&gt;
First of all you need to understand how ssl connections works. If you already know that just skip this part:&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
The secured socket layer or ssl has many applications, but mostly it is used for creating an encrypted data tunnel between two remote machines.&lt;br /&gt;
1. The client application sends a handshake request to the remote server;&lt;br /&gt;
2. The server sends the ssl certificate information along with his public key;&lt;br /&gt;
3. The client application checks the hostname, expiration date, and authority registration of the certificate, and if some of these parameters is not met then a warning message is displayed to the user.&lt;br /&gt;
4. After receiving the public key form the server the client application generates an envelope key that is used to encrypt the data transfer between the two machines. This key is then encrypted with the server’s public key and send back to the server.&lt;br /&gt;
5. The envelope key can be decrypted only with the private key that server has.&lt;br /&gt;
6. After both machines have the envelope the data transfer can begin.&lt;br /&gt;
&lt;a name=&#39;more&#39;&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: center;&quot;&gt;
&lt;a href=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKWSncoWu08oyeNLKboa_5vc1AKlrwkyXl5LPcTvVpUIgNek4EillcXLVDjjqdCYxpmQ4f9UCuDMvDPm7ho8UR6UzaQi8W5yYZxH8TUb0NDUa383wtdCvdKe1wnyLBsghvVbrJkMPmfuM/s1600/Ssl_02b.jpg&quot; imageanchor=&quot;1&quot; style=&quot;margin-left: 1em; margin-right: 1em;&quot;&gt;&lt;img border=&quot;0&quot; src=&quot;https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKWSncoWu08oyeNLKboa_5vc1AKlrwkyXl5LPcTvVpUIgNek4EillcXLVDjjqdCYxpmQ4f9UCuDMvDPm7ho8UR6UzaQi8W5yYZxH8TUb0NDUa383wtdCvdKe1wnyLBsghvVbrJkMPmfuM/s1600/Ssl_02b.jpg&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
&lt;div class=&quot;separator&quot; style=&quot;clear: both; text-align: left;&quot;&gt;
&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
Although we won’t use any transfer protocol, we will do something very similar.&lt;br /&gt;
Lets start with openssl. OpenSSL is a command line tool that can help you generate your public and private keys needed for this example.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
1. For generating public-private key pair, open a terminal and run:&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;# openssl genrsa -des3 -out certificate.pem 1024&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
You will be prompted for a passphrase. This passphrase will be used for decrypting the private key and it’s use is recommended.&lt;br /&gt;
After executing the command you should have a file named certificate.pem that should look like this:&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
—–BEGIN RSA PRIVATE KEY—–&lt;br /&gt;
Proc-Type: 4,ENCRYPTED&lt;br /&gt;
DEK-Info: DES-EDE3-CBC,3D2A826DAA45A4FD&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
oejviR8IoXgLnS3ZEC26vBt+IIlrRpvCn5R/JGm49UCEr5ItLdpWqQxib40IPgYu&lt;br /&gt;
f9nusVYKi2WLtCmtGKI7UcyZvZYOfksTbC6vzemorwcnkgBkWoLn1W/qyLaW2t6S&lt;br /&gt;
H4w+woz4hmak/VJJFBx2KGn9jWdC3rx4GdlNWJDLuzpa4ObUPgqClhLoBS2nXwWe&lt;br /&gt;
mjdrs7jNcz7CPXYTGhS5puAYzS6d8/0oJVBuZTtmXvJNU2TMwKcpmYMxJZ4ZBbR/&lt;br /&gt;
dfZyTq671i36ra3j7d7uSVRDlTFbd8708OalhRHxOuVHJKnd5H9N0AU8baXV6D0X&lt;br /&gt;
5EPMK8INiLZxtnZdc0zO7b+zOJ1f7ELL7g7Cwj8TzBJ8nT0yJCGnJWkp0ZpUGsOT&lt;br /&gt;
K9zeSApQgUWGj8ejaPOIkoqToNrSkiv/8/LzAkep37SBYpMdQf6sAuNDRYed+ktM&lt;br /&gt;
vsZYyOkNXXzxEUkPZsfzntGTDYypMJKX7FI4z8ovL5L+OPjrHIZVuNNrmgnOKs1E&lt;br /&gt;
KHCwQ0XQlPlK3/BC1TxB13PaSlf+/UGgzuQzl7gf6f48UMlOse0lhVzVj5U7zKhz&lt;br /&gt;
/ZAWg9oz0MjTXTccyQkuMMcrvOx9qN1o3YEuafcmDFK0CVkMvle53GvRzk+sVx76&lt;br /&gt;
UMO4/h6MrUo+WEslHbHgwOYrGCqw7xYRUhjUVY6/mthOeeJHg9uyMYyqWiyb0AE3&lt;br /&gt;
3ZSHVKkB9qjWCW8B74aW93XsV9oMungfLBBB8BC4c0NPBZVSSvZbmDWQOD0/qP6T&lt;br /&gt;
qYiffbW9kDwrjX2CnWccFk4o90XiAcP40GeLzna0xNRgsF+DL9o8kg==&lt;br /&gt;
—–END RSA PRIVATE KEY—–&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
2. Now we need to export the public key that will be used to encrypt our data. Run the following command:&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;# openssl rsa -in certificate.pem -pubout &amp;gt; public.key&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
You will be prompted for the passphrase that you’ve entered earlier.&lt;br /&gt;
Now we should have a file named public.key that looks like this:&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
—–BEGIN PUBLIC KEY—–&lt;br /&gt;
MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC0VfvEmljGvRQDmEPpy2UgsWsJ&lt;br /&gt;
d5kJJMmUENbeKquR8RDeZTKdLfO4Ts4cWucKOfJFREWgub1pf0ncZeyjZlkbPKEZ&lt;br /&gt;
wFT3ECrercmlK7QYZkh1R7AzPUxrj4foSP6EsvanxzFIQi2SkgNKLRyoRRfuMNaR&lt;br /&gt;
2/8P7Z3aKmnqhvse7wIDAQAB&lt;br /&gt;
—–END PUBLIC KEY—–&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
We can go ahead now and move the certificate.pem to a safe place where the apache user can’t access it.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
Using openssl and php to encrypt and decrypt data.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
There are three functions used in this example:&lt;br /&gt;
-&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;openssl_seal&lt;/strong&gt;() -&amp;gt; for encrypting data&lt;br /&gt;
-&amp;nbsp;&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;openssl_open&lt;/strong&gt;() -&amp;gt; for decrypting data&lt;br /&gt;
-&amp;nbsp;&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;openssl_get_privatekey&lt;/strong&gt;() -&amp;gt; for loading the private key&lt;/div&gt;
&lt;h3 style=&quot;background-color: white; border: 0px; color: #181818; font-family: Arial, Helvetica, serif; font-size: 24px; font-weight: normal; font: inherit; line-height: 1.25; margin: 0px 0px 9px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
Encrypting data.&lt;/h3&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
For the data encryption we need only the public key that we’ve created. Note that data encrypted with the public key can only be decrypted with it’s private key.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
Code:&lt;br /&gt;
&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;?php&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$publicKeyPath&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;border: 0px; color: #99cc00; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;‘/path/public.key’&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$data&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;border: 0px; color: #99cc00; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;‘I should be encrypted’&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$publicKey&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;border: 0px; color: cyan; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;array&lt;/span&gt;(file_get_contents($publicKeyPath));&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$encData&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;border: 0px; color: cyan; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$envKey&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;border: 0px; color: cyan; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;null&lt;/span&gt;;&lt;br /&gt;
openssl_seal(&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$data&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$encData&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$envKey&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$publicKey&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;em style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: silver; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;// as we use only one public key to encrypt data we will receive only one envelope key&lt;/span&gt;&lt;/em&gt;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$envKey&lt;/span&gt;&amp;nbsp;= current(&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$envKey&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
var_dump(&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$encData&lt;/span&gt;&lt;em style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&lt;span style=&quot;border: 0px; color: silver; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;/*encrypted data*/&lt;/span&gt;&lt;/em&gt;,&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$envKey&lt;/span&gt;&lt;span style=&quot;border: 0px; color: silver; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;/*envelope key*/&lt;/span&gt;);&lt;br /&gt;
&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;?&amp;gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
The data from this example can be then saved to the application’s database for future usage.&lt;/div&gt;
&lt;h3 style=&quot;background-color: white; border: 0px; color: #181818; font-family: Arial, Helvetica, serif; font-size: 24px; font-weight: normal; font: inherit; line-height: 1.25; margin: 0px 0px 9px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
Decrypting data:&lt;/h3&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
Code:&lt;br /&gt;
&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;lt;?php&lt;/strong&gt;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$privateKeyPath&lt;/span&gt;&amp;nbsp;=&lt;span style=&quot;border: 0px; color: #99cc00; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;‘/path/certificate.pem’&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$passPhrase&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;border: 0px; color: #99cc00; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;‘passphrese for decrypting the private key’&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$encData&lt;/span&gt;&amp;nbsp;=&lt;span style=&quot;border: 0px; color: #99cc00; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;&amp;nbsp;‘the encrypted data string’&lt;/span&gt;;&lt;br /&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$envKey&lt;/span&gt;&amp;nbsp;=&amp;nbsp;&lt;span style=&quot;border: 0px; color: #99cc00; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;‘envelope key used for encryption’&lt;/span&gt;;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$privateKey&lt;/span&gt;&amp;nbsp;= openssl_get_privatekey(file_get_contents(&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$privateKeyPath&lt;/span&gt;),&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$passPhrase&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$data&lt;/span&gt;&amp;nbsp;= null;&lt;br /&gt;
openssl_open(&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$encData&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$data&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$envKey&lt;/span&gt;,&amp;nbsp;&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$privateKey&lt;/span&gt;);&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px 0px 0px 30px; text-align: justify; vertical-align: baseline;&quot;&gt;
var_dump(&lt;span style=&quot;border: 0px; color: #ff6600; font: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;$data&lt;/span&gt;);&lt;br /&gt;
&lt;strong style=&quot;border: 0px; font: inherit; line-height: inherit; margin: 0px; padding: 0px; vertical-align: baseline;&quot;&gt;?&amp;gt;&lt;/strong&gt;&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
There are numerous ways of decrypting your data depending on the sensitivity level of the information. You can import the private key from a remote machine, use it in another system that will need the ability of reading this data or you can implement it on the same machine and application, wich is not recommended, beacause if an attacker has gained access to your system he can easily load your private key and access the information.&lt;/div&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;b&gt;Source:&amp;nbsp;&lt;/b&gt;&lt;a href=&quot;http://team.158ltd.com/2012/11/06/securing-your-data-using-php-and-openssl/&quot; style=&quot;background-color: transparent; text-align: left;&quot; target=&quot;_blank&quot;&gt;http://team.158ltd.com/2012/11/06/securing-your-data-using-php-and-openssl/&lt;/a&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;div style=&quot;background-color: white; border: 0px; clear: none; color: #555555; font-family: Arial, Helvetica, serif; font-size: 14px; font: inherit; line-height: 17px; margin-bottom: 10px; padding: 0px; text-align: justify; vertical-align: baseline;&quot;&gt;
&lt;br /&gt;&lt;/div&gt;
</content><link rel='replies' type='application/atom+xml' href='http://lexmihaylov.blogspot.com/feeds/2052698986589990319/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/securing-your-data-using-php-and-openssl.html#comment-form' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/2052698986589990319'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8586650242273506656/posts/default/2052698986589990319'/><link rel='alternate' type='text/html' href='http://lexmihaylov.blogspot.com/2013/03/securing-your-data-using-php-and-openssl.html' title='Securing your data using PHP and OpenSSL'/><author><name>lexmihaylov</name><uri>http://www.blogger.com/profile/18444200429851482681</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='https://img1.blogblog.com/img/b16-rounded.gif'/></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2YCUIrUO8OJFswbtaDrmNauvUsQHjbh3SyNbH2kqXy3mCKtEJFS518nD4XPbhqh-J2f7CWdeqMCFas2Vqa0J5S75bc0q3IGGK0-Ioh3yLSSNMfivM4De8U01x0eRH7EJIUuyfeZbrVgI/s72-c/secure-site.png" height="72" width="72"/><thr:total>0</thr:total></entry></feed>