Skip to main content

Posts

Enable Https by self-signing certification.

  Run make-ssl-cert command > sudo make-ssl-cert generate-default-snakeoil will created 2 files in following directory.     - /etc/ssl/certs/ssl-cert-snakeoil.pem     - /etc/ssl/private/ssl-cert-snakeoil.key Open /etc/apache2/site-avilable and find and modify with below line (with above certs paths) .         SSLCertificateFile    /etc/ssl/certs/ssl-cert-snakeoil.pem         SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key > sudo a2ensite default-ssl > sudo a2enmode ssl > sudo systemctl restart apache2 Open https://localhost
Recent posts

Javascript Generator as promise

     function* makeIterator(data) {       for(i in data){                 yield data[i];         }     }         function runPull() {         var obj = it.next();         var val;         console.log("RunPull Clicked",obj);         if(!obj.done) {             val = obj.value;             val.click();             setTimeout(function(){                 runPull();             },200);         }     }     ru...

Recursive array calls one after another through promise

 data = [1,2,3,4] rules = [                     function(d){ return d.map(x => x * 2); },                     function(d){ return d.map(x => x * 2); }                ] recursive(0,rules,data); function somelongrunningprocess(rule, data){     var d = $.Deferred();     setTimeout(function(){ var result = rule.call(undefined,data); d.resolve(result); },1000);     return d; } function recursive(index, rules, data) {             if(index < rules.length) {                 $.when(somelongrunningprocess(rules[index],data)).then(function(response){                     console.log("after_rule",respon...

Sort an Array by keys based on another Array

 <?php $customer [ 'address' ] = '123 fake st' ; $customer [ 'name' ] = 'Tim' ; $customer [ 'dob' ] = '12/08/1986' ; $customer [ 'dontSortMe' ] = 'this value doesnt need to be sorted' ; $properOrderedArray = array_merge ( array_flip ( array ( 'name' , 'dob' , 'address' )), $customer ); // or $properOrderedArray = array_replace ( array_flip ( array ( 'name' , 'dob' , 'address' )), $customer );

Custom Sorting Array List in PHP

 <?php $order = array("Z","Srilanka","34", "Canada", "India", "USA"); $array = array(     array('id' => 7867867, 'title' => 'USA'),     array('id' => 3452342, 'title' => 'India'),     array('id' => 1231233, 'title' => 'Srilanka'),     array('id' => 5867867, 'title' => 'Z'), ); usort($array, function ($a, $b) use ($order) {     $pos_a = array_search($a['title'], $order);     $pos_b = array_search($b['title'], $order);     return $pos_a - $pos_b; }); print_r($array); ?>

Reading Large JSON file through PHP Script

 <?php /* cat mexico.geojson | wc sed ':a;N;$!ba;s/\n/ /g' mexico.geojson  > mexico.geojson_out1 cat mexico.geojson_out1 | wc http://localhost/Utility/cord/largefile.php?filename=mexico.geojson_out1 sed -E 's/\{ "type": "FeatureCollection", "name": "mexico_administrative_osm_province_boundaries", "crs": \{ "type": "name", "properties": \{ "name": "urn:ogc:def:crs:OGC:1.3:CRS84" \} \}, "features": \[//g' ./mexico.geojson_out1  > mexico.geojson_out2 http://localhost/Utility/cord/largefile.php?filename=mexico.geojson_out2 sed -E 's/(\[|\{|\}|\])/ \1 /g' ./mexico.geojson_out2 > ./output/mexico.geojson_output http://localhost/Utility/cord/largefile.php?filename=output/mexico.geojson_output */ ini_set('max_execution_time', '500'); //300 seconds = 5 minutes ini_set('memory_limit', '1G');   //ini_set('max_execution...