2016 m. gruodžio 24 d., šeštadienis

MX forwarder

jeigu nenorite isduoti savo mail serverio, kad nsulaukti isilaizeliu spameriu, glaima naudoti MX forwarderi http://improvmx.com/

2016 m. lapkričio 22 d., antradienis

apsauga nuo ddos

apsisaugojimui glai buti naudojamas tas ats cloudflare ar sucuri.net ar  Imperva, tik esme - neisduoti savo IP. T.y. pasto serveri laikyti butinai ant kito IP (tiek gaunamu tiek siunciamu). Ir per weba neleisti kelti failu. Arba naudotis mokamomis f-jomi, sukuriant tunnel. Perejus ant saugiu technologiju, pasikeisti IP, nes ji gali zinoti kas nors is seniau.

esanciai atakai dar glai padeti fail2ban, ipdables blokavimai, jei nera daug skirtingu IP

 o ir iš www siunčiant email naudoti ne mail(), o smtp autorizaciją - tuomet (priklausomai nuo pašto serverio konfigo) www ip nesimatys.

apsauga nuo ddos

apsisaugojimui glai buti naudojamas tas ats cloudflare ar sucuri.net ar  Imperva, tik esme - neisduoti savo IP. T.y. pasto serveri laikyti butinai ant kito IP (tiek gaunamu tiek siunciamu). Ir per weba neleisti kelti failu. Arba naudotis mokamomis f-jomi, sukuriant tunnel. Perejus ant saugiu technologiju, pasikeisti IP, nes ji gali zinoti kas nors is seniau.

esanciai atakai dar glai padeti fail2ban, ipdables blokavimai, jei nera daug skirtingu IP

https://www.digitalocean.com/community/tutorials/how-to-protect-ssh-with-fail2ban-on-centos-6

2016 m. lapkričio 20 d., sekmadienis

servuko atnaujinimai

https://doc.owncloud.org/server/8.1/admin_manual/installation/php_54_installation.html
https://techjourney.net/install-and-run-multiple-and-newer-5-4-or-5-5-php-versions-in-virtualmin/
https://www.webfoobar.com/index.php/node/45

smtp 25 porto blokavimas

iptables -A INPUT -p tcp --destination-port 80 -j DROP
service iptables save

blokuojam tik incoming 25 tcp port

google drive failu nuskaitymas su php


//reikalingas service accont iš https://console.developers.google.com
$client = new Google_Client();

$credentialsFile = __DIR__ . '/googleserviceaccount.json';

if (!file_exists($credentialsFile)) {
    throw new RuntimeException('Service account credentials Not Found!');
}

$client->setAuthConfig($credentialsFile);
$client->setApplicationName("Service Account Example");
$client->setScopes(Google_Service_Drive::DRIVE);

$service = new Google_Service_Drive($client);

//glaime rodyti tik is tam tikro folderio
$files = $service->files->listFiles(array('q' => "'0B6Gt1nOByOdfsdfdsfsdZ3BqOGc' in parents"));
//failu sarasas
var_dump($files);

//failo turinys
$content = $service->files->export('13yrUsfsdfdsfsdfsdf454u_LC1eJA1mNs', 'text/html', array(
  'alt' => 'media' ));

var_dump($content->getBody()->read(1024));

google drive failu nuskaitymas su php


//reikalingas service accont iš https://console.developers.google.com
$client = new Google_Client();

$credentialsFile = __DIR__ . '/googleserviceaccount.json';

if (!file_exists($credentialsFile)) {
    throw new RuntimeException('Service account credentials Not Found!');
}

$client->setAuthConfig($credentialsFile);
$client->setApplicationName("Service Account Example");
$client->setScopes(Google_Service_Drive::DRIVE);

$service = new Google_Service_Drive($client);

//glaime rodyti tik is tam tikro folderio
$files = $service->files->listFiles(array('q' => "'0B6Gt1nOByOdfsdfdsfsdZ3BqOGc' in parents"));
//failu sarasas
var_dump($files);

//failo turinys
$content = $service->files->export('13yrUsfsdfdsfsdfsdf454u_LC1eJA1mNs', 'text/html', array(
  'alt' => 'media' ));

var_dump($content->getBody()->read(1024));

2016 m. lapkričio 13 d., sekmadienis

Eshop

El. parduotuvės privalės skelbti specialios svetainės adresą, kurios pagalba vartotojai ginčus su pardavėjais gali išspręsti be teismo. To nepadariusios parduotuvės bus baudžiamos. https://webgate.ec.europa.eu/odr/main/index.cfm?event=main.home.show&lng=LT

2016 m. spalio 20 d., ketvirtadienis

MySQL partitioning by column

ALTER TABLE `products` DROP PRIMARY KEY , ADD PRIMARY KEY ( `id` , `category` );
ALTER TABLE `products` PARTITION BY KEY(category) PARTITIONS 6;

2016 m. rugsėjo 5 d., pirmadienis

PHP slugify url

static public function slugify($text)
{
  // replace non letter or digits by -
  $text = preg_replace('~[^\pL\d]+~u', '-', $text);

  // transliterate
  $text = iconv('utf-8', 'us-ascii//TRANSLIT', $text);

  // remove unwanted characters
  $text = preg_replace('~[^-\w]+~', '', $text);

  // trim
  $text = trim($text, '-');

  // remove duplicate -
  $text = preg_replace('~-+~', '-', $text);

  // lowercase
  $text = strtolower($text);

  if (empty($text)) {
    return 'n-a';
  }

  return $text;
}

2016 m. rugpjūčio 8 d., pirmadienis

bootstrap above fold load ciritical css

https://www.appneta.com/blog/bootstrap-pagespeed/

Enable mod_pagespeed
<IfModule pagespeed_module>
    ModPageSpeed on
    ModPagespeedRewriteLevel CoreFilters
    ModPagespeedEnableFilters prioritize_critical_css
    ModPagespeedEnableFilters defer_javascript
    ModPagespeedEnableFilters sprite_images
    ModPagespeedEnableFilters convert_png_to_jpeg,convert_jpeg_to_webp
    ModPagespeedEnableFilters collapse_whitespace,remove_comments
</IfModule>

Minify CSS

yum compress JS and load async
$ cat jquery.js bootstrap.js holder.js > all.js
$ yui-compressor all.js -o all.min.js

Optimize CSS Delivery

Run a Javascript bookmarklet to detect and list CSS that is “above the
fold”
Inline the “above the fold” CSS directly into the HTML
Defer loading the rest of the “below the fold” CSS using a simple, yet
not cross browser compatible solution by Paul Irish

arba: https://github.com/addyosmani/critical 

2016 m. rugpjūčio 3 d., trečiadienis

bootlint - bootstrap error checker

https://github.com/twbs/bootlint

pakanka i koda ideti eilute
(function(){var s=document.createElement("script");s.onload=function(){bootlint.showLintReportForCurrentDocument([]);};s.src="https://maxcdn.bootstrapcdn.com/bootlint/latest/bootlint.min.js";document.body.appendChild(s)})();

2016 m. liepos 13 d., trečiadienis

2016 m. kovo 29 d., antradienis

seo dynamic url - hashbang

Google sees a link to example.com/#!/blog
Google requests example.com/?_escaped_fragment_=/blog

php:
if(isset($_GET['_escaped_fragment_'])) {
    Header( "HTTP/1.1 301 Moved Permanently" );
    header('Location: http://'.$_SERVER['HTTP_HOST'].$_GET['_escaped_fragment_']);
    die();
}

js:
history.pushState('page', null, '/#!/'+v.url+'/');

https://github.com/browserstate/history.js/ - pluginas kuris history state daro su hashbang arba be jo prilausomai ar html4 ar html5 narsykle

hadangi html5 palaiko pushstate, tai vengti hashbang.

FB mygtuku atveju nenaudoti hashbang, vistiek turime patiekti originalu normalu url.
Jeigu dinamiskai keitesei url, galima perkrauti FB skriptus:
FB.XFBML.parse(document.getElementById('myModal'));

Facebook scraper is respecting the google ajax specifications and it will convert the #! to ?_escaped_fragment_= You can check this out for yourself with the facebook debugger:https://developers.facebook.com/tools/debug

Update - google jau palaiko JS, todėl: Instead of the _escaped_fragment_ URLs, we'll generally crawl, render, and index the #! URLs.



2016 m. kovo 20 d., sekmadienis

2016 m. kovo 10 d., ketvirtadienis

WebSockets tutorial

websockets - dvipusis bendravimas serverio su narsykle
http://www.binarytides.com/websockets-php-tutorial/
js biblioteka http://socket.io/   o serverside naudoti node.js


server-sent events - info uzklausimai kas kelias sekundes. Galima is serverio paduoti retry parametra po kiek laiko kita karta uzklausti info.
http://www.w3schools.com/html/html5_serversentevents.asp
Jau susijungus su serveriu, glaima padaryti, kad php skriptas tampa veikiantis be sustojimo su while, ir su obflush ispushina info narsyklei tada kada nori serveris: http://www.howopensource.com/2014/12/introduction-to-server-sent-events/

Long Polling Ajax - kai uzklausa nueina i sevreri, o srveris atsako tik tada, kai turi naujos info. Uzdedamas ilgas timeout. Gavus atsakyma, uzklausa vel kartojama is narsykles i serveri:
http://techoctave.com/c7/posts/60-simple-long-polling-example-with-javascript-and-jquery/

2016 m. kovo 2 d., trečiadienis

2016 m. vasario 7 d., sekmadienis

inode suvaldymas

komanda paziurejimui kiek inode naudojama:
df -i

Komanda paziurejimui kurios direktorijos kiek inode naudoja:
cd /path/to/folder/

find . -printf "%h\n" | cut -d/ -f-2 | sort | uniq -c | sort -rn

Pasalinimui direktorijos
rm -rf mydir

smtp, dkim, spf tools

spf iraso konfoguratorius
http://spfwizard.com/

spf/dkim tester, spamscore tester
http://dkimvalidator.com/

2016 m. vasario 3 d., trečiadienis

Responsive images sprendimai

https://github.com/teleject/hisrc - html kode nurodome img matmenis trijų dydžių, JS pagalba nustato kurį dydį krauti
http://adaptive-images.com/ - mažiausiai riekia keisti kodo. Per Htaccess paveikslėlių užkrovimą perduodame PHP skriptui, kuris pagal prieš tai padėtą cookie arba user-agent nustato kokia raiška reikalinga ir užkrauna reikiamą paveikslėlį, pakešuoja skirtingų dydžių versijas (panašiai daro WP).
https://responsiveimages.org/  - dar geresnis sprendimas, kode leidžiantisn urodyti skiritngas versijas. tik reikia pasikurti php skriptą kuris apdorotų ir pakešuotų paveikslėlius pagal dydį.
https://developers.google.com/web/fundamentals/design-and-ui/media/images/images-in-markup?hl=en -  google rekomenduojamos technikos repsonsive paveikslėliams, taip pat Retina ekranams kur pixel density didesnis, nurodant HTML IMG kode skiritngas paveikslėlių versijas

Background paveiksėliams - per media queries - http://www.html5rocks.com/en/mobile/high-dpi/#toc-tech-overview

SVG vektorinių paveikslėlių kompresinimas: https://jakearchibald.github.io/svgomg/

WEBP - naujas paveiksėlių formatas, 22% mažiau užimantis už PNG. Konverteris - http://webp-converter.com/  tik reikia pasidomėti kaip užkrauti ne webp paveikslą jei browseris nepalaiko, kaip tai aptikti: https://developers.google.com/speed/webp/faq  (rašo glaima su moderinzer.js)

2016 m. sausio 28 d., ketvirtadienis

PHP irankis minimizavimui html/css, apjungimui i viena faila

https://github.com/mrclay/minify - nors man kazkodel nepasileido
https://github.com/matthiasmullie/minify - minifikatorius, bet kazin ar turi cache
http://rakaz.nl/code/combine - paprastas 1 failo skriptas su file cache filetime md5 pagrindu

2016 m. sausio 27 d., trečiadienis

Mokejimu gateway

https://www.paysera.lt/
https://mistertango.lt
https://cardinity.lt
https://opay.lt

Uzsienio
https://fortumo.com
https://coingate.com
http://www.worldpay.com/
https://www.braintreepayments.com

load async

https://css-tricks.com/thinking-async/

taip pat rekomendujama sfriftus laikyti local storage http://www.sitepoint.com/improving-font-performance-subsetting-local-storage/

tinklalapio pagespeed optimization guide

http://www.appneta.com/blog/bootstrap-pagespeed/

mysql benchmarkt tool - mytop

yum install mytop
mytop --prompt
taip pat padeda sql komanda SHOW GLOBAL STATUS

server info



wget http://percona.com/get/pt-summary
bash ./pt-summary
more info: https://www.percona.com/doc/percona-toolkit/2.2/pt-summary.html

memcached konfiguravimas

http://www.cyberciti.biz/faq/howto-install-memcached-under-rhel-fedora-centos/

2016 m. sausio 18 d., pirmadienis

page optimisation

kaip is google pagespeed insights 77 score pasiekti 100, bootstrap atveju
http://www.appneta.com/blog/bootstrap-pagespeed/
vienas svarbesniu momentu - google pagespeed module
https://developers.google.com/speed/pagespeed/module/

load jquery after page load

https://github.com/danriti/bootstrap-pagespeed/commit/50e10b6a908d71fa8b79b153c36042a5d29efe1b

<script type="text/javascript">
+    // Add a script element as a child of the body
+    function downloadJSAtOnload() {
+    var element = document.createElement("script");
+    element.src = "scripts/all.min.js";
+    document.body.appendChild(element);
+    }
+
+    // Check for browser support of event handling capability
+    if (window.addEventListener)
+    window.addEventListener("load", downloadJSAtOnload, false);
+    else if (window.attachEvent)
+    window.attachEvent("onload", downloadJSAtOnload);
+    else window.onload = downloadJSAtOnload;
+    </script>

Load jQuery with Javascript and use jQuery

http://stackoverflow.com/questions/10113366/load-jquery-with-javascript-and-use-jquery

Cordova - Mobile apps with HTML, CSS & JS

https://cordova.apache.org/

2016 m. sausio 9 d., šeštadienis

Javacript document.write catch


If you're dealing with 3rd party scripts, simply replacing document.write to capture the output and stick it in the right place isn't good enough, since they could change the script and then your site would break.
writeCapture.js does what you need (full disclosure: I'm the author). It basically rewrites the script tags so that each one captures it's own document.write output and puts it in the correct place. The usage (using jQuery) would be something like:
$(document.body).writeCapture().append('<script type="text/javascript" src="http://3rdparty.com/foo.js"></script>');
Here I'm assuming that you want to append to the end of the body. All jQuery selectors and manipulation methods will work with the plugin, so you can inject it anywhere and however you want. It can also be used without jQuery, if that is a problem.

2016 m. sausio 7 d., ketvirtadienis

Neapkraunantis youtube užkrovimas

Jei viename tinklalapio lange norite ikelti daug youtube video, tai labai akraus puslapi, jei desite embeded visus youtube video. Todel geriau deti tik youtube cover paveiksleli su ant virsaus nupiestu play mygtuku. Istraukti coveri ir ji suaktyvinti, kad paspaudus coveri isikeltu grotuvas, nesunkiai galima padaryti su JS funkcija: http://www.sitepoint.com/faster-youtube-embeds-javascript/

Lightweight social share buttons

be addthis.com dar yra paprastas lengvas skriptukas http://sapegin.github.io/social-likes/  ( https://github.com/sapegin/social-likes )

papsrastas budas pasidaryti mytukus su fontawesome: http://webdesignerhut.com/css-social-sharing-buttons/

Geras budas pasidaryti mygtukus su counteriais, ne atskiro srifto failo (sriftas itrauktas i js): http://sapegin.github.io/social-likes/


2016 m. sausio 4 d., pirmadienis

JS ekrano screenshot paėmimas ir siuntimas į serverį

http://permadi.com/2010/10/html5-saving-canvas-image-data-using-php-and-ajax/
http://www.jedox.com/en/screen-shot-web-via-javascript-saving-back-server
https://html2canvas.hertzen.com/
html to canvas alternatyva: http://cburgmer.github.io/rasterizeHTML.js/ taip pat https://github.com/Irrelon/html-to-canvas

function saveViaAJAX()
{
var testCanvas = document.getElementById("testCanvas");
var canvasData = testCanvas.toDataURL("image/png");
var postData = "canvasData="+canvasData;
var debugConsole= document.getElementById("debugConsole");
debugConsole.value=canvasData;

//alert("canvasData ="+canvasData );
var ajax = new XMLHttpRequest();
ajax.open("POST",'testSave.php',true);
ajax.setRequestHeader('Content-Type', 'canvas/upload');
//ajax.setRequestHeader('Content-TypeLength', postData.length);


ajax.onreadystatechange=function()
{
if (ajax.readyState == 4)
{
//alert(ajax.responseText);
// Write out the filename.
document.getElementById("debugFilenameConsole").innerHTML="Saved as<br><a target='_blank' href='"+ajax.responseText+"'>"+ajax.responseText+"</a><br>Reload this page to generate new image or click the filename to open the image file.";
}
}

ajax.send(postData);
}


Tačiau mums reikia html versti į canvas, naudojant html2canvas.js
function takeScreenShot(){
html2canvas(window.parent.document.body, {
onrendered: function(canvas) {
var cand = document.getElementsByTagName('canvas');
if(cand[0] === undefined || cand[0] === null){
}else{
//cand[0].remove();
document.body.removeChild(cand[0]);
}
document.body.appendChild(canvas);
}
});
}




Server side:
<?php
if (isset($GLOBALS["HTTP_RAW_POST_DATA"]))
{
  // Get the data
  $imageData=$GLOBALS['HTTP_RAW_POST_DATA'];
  // Remove the headers (data:,) part.
  // A real application should use them according to needs such as to check image type
  $filteredData=substr($imageData, strpos($imageData, ",")+1);
  // Need to decode before saving since the data we received is already base64 encoded
  $unencodedData=base64_decode($filteredData);
  //echo "unencodedData".$unencodedData;
  // Save file. This example uses a hard coded filename for testing,
  // but a real application can specify filename in POST variable
  $fp = fopen( 'test.png', 'wb' );
  fwrite( $fp, $unencodedData);
  fclose( $fp );
}
?>