Category Archives: Web

Web

Chrome Rulz

Xmarks
LastPass
Fiddler
Web developer

Rulz 🙂

/usr/bin/google-chrome-stable -disk-cache-dir="/tmp/ccache/" -disk-cache-size=600000000 --password-store=basic

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Оптимизиране на chrome,firefox -- linux

file:/etc/rc.local

#Optimize chrome
mkdir /tmp/ccache
mount -t tmpfs -o size=512M,mode=0744 tmpfs /tmp/ccache/;
chmod -R 777 /tmp/ccache/;

#Shortcut
#/usr/bin/google-chrome-stable -disk-cache-dir="/tmp/ccache/" -disk-cache-size=600000000 --password-store=basic#Optimize firefox

about:config
browser.cache.disk.enable -- false
browser.cache.memory.enable -- true
about:cache

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Синхронизиране с ftp (lftp) rsync

lftp -u FTP_USER,FTP_PASS -e 'mirror REMOTE_DIRECTORY LOCAL_DIRECTORY' FTP_SERVER

Ако излезе тази грешка:
mirror: Fatal error: Certificate verification: certificate common name doesn't match requested host name ‘FTP_SERVER’
1 error detected

Фикса е:

echo "set ssl:verify-certificate no" >> ~/.lftp/rc

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Sublime

Тук ще описвам интересни бележки за Sublime

Любими плъгини:
Emmet
BracketHighlighter
Color Highlighter
ColorPicker (Ctrl + Shift + C )
Theme Centurion
AutoFileName
TabsExtra
SublimeLinter
sublimelinter
sublimelinter-php
sublimelinter-jshint
HTML-CSS-JS Prettify
SideBarEnhancements
Super Calculator

 

Инсталиране на jshint linux:
apt-get update && apt-get install nodejs npm nodejs-legacy php;
npm install -g jshint;
npm install -g csshint;

Монтиране на ssh на отдалечена машина
apt-get install && apt-get install -y sshfs;
sshfs amri@server.bg:/w/ ~/Desktop/server.bg -o port=33

Синтаксис по подразбиране PHP(може и Html и други):

File: ~/.config/sublime-text-3/Packages/User/default_syntax.py

import sublime, sublime_plugin

class DefaultSyntaxCommand(sublime_plugin.EventListener):
def on_new(self, view):
view.set_syntax_file('Packages/PHP/PHP.tmLanguage')

 

Инсталиране на пакети (в случая emmet за отворени/затворени тагове)

В този случай : emmet
https://packagecontrol.io/installation

ctrl+` или View > Show Consol

import urllib.request,os,hashlib; h = 'df21e130d211cfc94d9b0905775a7c0f' + '1e3d39e33b79698005270310898eea76'; pf = 'Package Control.sublime-package'; ipp = sublime.installed_packages_path(); urllib.request.install_opener( urllib.request.build_opener( urllib.request.ProxyHandler()) ); by = urllib.request.urlopen( 'http://packagecontrol.io/' + pf.replace(' ', '%20')).read(); dh = hashlib.sha256(by).hexdigest(); print('Error validating download (got %s instead of %s), please try manual install' % (dh, h)) if dh != h else open(os.path.join( ipp, pf), 'wb' ).write(by)

Ctrl + Shift + P или  Preferences > Package Control > Package Control: Install Package
Emmet и това е 🙂
Комбинацията е Control + Shift + ' и се маркира затварящия таг

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Инсталиране на yuicompressor (оптимизиране на js, css)

1. Инсталиране на java
mkdir -p /usr/share/java

wget https://github.com/yui/yuicompressor/releases/download/v2.4.8/yuicompressor-2.4.8.jar -P /usr/share/java

vi /usr/bin/yc

#!/bin/sh

java -jar /usr/share/java/yuicompressor-2.4.8.jar "$@"
chmod +x /usr/bin/yc
yc default.css -o default-min.css

yc sample.js -o sample-min.js

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Скриване на елемент за мобилни устройства

Идеята е с javascript да идентифицираме клиента по user agent-а и да скрием id блок от него.

<script>
var mobile = (/iphone|ipod|android|blackberry|mini|windows\sce|palm/i.test(navigator.userAgent.toLowerCase()));
if (mobile) {
$('#bu1').hide();
}

</script>

VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
VN:F [1.9.22_1171]
Rating: 0 (from 0 votes)

Google maps embed iframe -- респонсив

<style>
    .google-maps {
        position: relative;
        padding-bottom: 30%; // This is the aspect ratio
        height: 0;
        overflow: hidden;
    }
    .google-maps iframe {
        position: absolute;
        top: 0;
        left: 0;
        width: 100% !important;
        height: 100% !important;
    }
</style>
<br /><br /><center><h3>Map</h3><br /></center>
<div class='google-maps'>
<iframe src='https://www.google.com/maps/embed?pb=!1m18!1m12!1m3!1d2932.58550931219!2d23.29158247261225!3d42.69132162380618!2m3!1f0!2f0!3f0!3m2!1i1024!2i768!4f13.1!3m3!1m2!1s0x40aa85232c054953:0x408417d08050add6!2sBusiness+Centre+Serdika!5e0!3m2!1sen!2sbg!4v1468307728158&quot; width='600' height='450' frameborder='0' style='border:0' allowfullscreen></iframe>
</div>
VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

mysql tips random

идеята е една колона в mysql таблица да се напълни със случайни числа от 1 до 3, но от mysql.

Решението: update articles set sezon_id=ceil(RAND()*3)

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

Оптимизиране на изображенията (png,jpg)

Идеята е да се оптимизират изображнията за по- бързо зареждане и според Google PageSpeed Insights:

find . -iname '*.jpg' -print0 | xargs -0 jpegoptim --max=90 --strip-all --preserve --totals;
find $PWD -type f -name "*.jpg*" -execdir jpegoptim -v --strip-all --max=85 --preserve '{}' \;
find . -iname '*.png' -print0 | xargs -0 optipng -o7 -preserve;

Резултата:

./images/back.jpg 85x203 24bit Adobe  [OK] 1044 --> 724 bytes (30.65%), optimized.
./images/322.jpg 100x100 24bit JFIF  [OK] 3044 --> 2666 bytes (12.42%), optimized.
./images/257.jpg 100x100 24bit JFIF  [OK] 2929 --> 2533 bytes (13.52%), optimized.
Average compression (1636 files): 48.48% (10643k)



** Processing: ./selector-arrow.png
13x10 pixels, 4 bits/pixel, 16 colors (1 transparent) in palette
Input IDAT size = 81 bytes
Input file size = 211 bytes

Trying:
  zc = 9  zm = 9  zs = 0  f = 0		IDAT size = 68
  zc = 9  zm = 8  zs = 0  f = 0		IDAT size = 68
  zc = 8  zm = 9  zs = 0  f = 0		IDAT size = 68
  zc = 8  zm = 8  zs = 0  f = 0		IDAT size = 68
  zc = 7  zm = 9  zs = 0  f = 0		IDAT size = 68
  zc = 7  zm = 8  zs = 0  f = 0		IDAT size = 68
  zc = 6  zm = 9  zs = 0  f = 0		IDAT size = 68
  zc = 6  zm = 8  zs = 0  f = 0		IDAT size = 68
  zc = 5  zm = 9  zs = 0  f = 0		IDAT size = 68
  zc = 5  zm = 8  zs = 0  f = 0		IDAT size = 68
  zc = 4  zm = 9  zs = 0  f = 0		IDAT size = 68
  zc = 4  zm = 8  zs = 0  f = 0		IDAT size = 68
  zc = 3  zm = 9  zs = 0  f = 0		IDAT size = 68
  zc = 3  zm = 8  zs = 0  f = 0		IDAT size = 68
  zc = 3  zm = 9  zs = 1  f = 0		IDAT size = 68
  zc = 3  zm = 8  zs = 1  f = 0		IDAT size = 68
                               
Selecting parameters:
  zc = 3  zm = 8  zs = 1  f = 0		IDAT size = 68

Output IDAT size = 68 bytes (13 bytes decrease)
Output file size = 198 bytes (13 bytes = 6.16% decrease)

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)

htaccess

RewriteEngine On


#Options -Indexes

ErrorDocument 404 /404.php
#RewriteBase /
#RewriteCond %{HTTP_HOST} !^DOMAIN$ [NC]
#RewriteRule ^(.*)$ http://DOMAIN/$1 [L,R=301]

RewriteRule ^css.min/(.*\.css) /m/?f=/css/$1 [NC,L,QSA]
RewriteRule ^js.min/(.*\.js) /m/?f=/js/$1 [NC,L,QSA]

## EXPIRES CACHING ##

ExpiresActive On
ExpiresByType image/jpg "access 1 year"
ExpiresByType image/jpeg "access 1 year"
ExpiresByType image/gif "access 1 year"
ExpiresByType image/png "access 1 year"
ExpiresByType text/css "access 1 month"
ExpiresByType application/pdf "access 1 month"
ExpiresByType application/x-javascript "access 1 month"
ExpiresByType application/x-shockwave-flash "access 1 month"
ExpiresByType image/x-icon "access 1 year"
ExpiresDefault "access 2 days"

## EXPIRES CACHING ##


# Set up caching on media files for 1 year (forever?)
<FilesMatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$">
ExpiresDefault A29030400
Header append Cache-Control "public"


# Set up caching on media files for 1 week
<FilesMatch "\.(gif|jpg|jpeg|png|swf)$">
ExpiresDefault A604800
Header append Cache-Control "public"


# Set up 2 Hour caching on commonly updated files
<FilesMatch "\.(xml|txt|html|js|css)$">
ExpiresDefault A9200
Header append Cache-Control "proxy-revalidate"


# Force no caching for dynamic files
<FilesMatch "\.(php|htm)$">
ExpiresActive Off
Header set Cache-Control "private, no-cache, no-store, proxy-revalidate, no-transform"
Header set Pragma "no-cache"



AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

VN:F [1.9.22_1171]
Rating: 5.0/5 (1 vote cast)
VN:F [1.9.22_1171]
Rating: +1 (from 1 vote)