How to enable gzip for yii2? - .htaccess

I need to add new rules to .htaccess or to add the code to index.php of YII2?
My site is on shared hosting.
I want to compress only .css and .js files. I don't want to compress all responses.

You can make it work by attaching event handler on yii\web\Response in index.php.
$application = new yii\web\Application($config);
$application->on(yii\web\Application::EVENT_BEFORE_REQUEST, function(yii\base\Event $event){
$event->sender->response->on(yii\web\Response::EVENT_BEFORE_SEND, function($e){
ob_start("ob_gzhandler");
});
$event->sender->response->on(yii\web\Response::EVENT_AFTER_SEND, function($e){
ob_end_flush();
});
});
$application->run();

I added the following rules to .htaccess:
<IfModule mod_filter.c>
AddOutputFilterByType DEFLATE "application/atom+xml" \
"application/javascript" \
"application/json" \
"application/ld+json" \
"application/manifest+json" \
"application/rdf+xml" \
"application/rss+xml" \
"application/schema+json" \
"application/vnd.geo+json" \
"application/vnd.ms-fontobject" \
"application/x-font-ttf" \
"application/x-javascript" \
"application/x-web-app-manifest+json" \
"application/xhtml+xml" \
"application/xml" \
"font/eot" \
"font/opentype" \
"image/bmp" \
"image/svg+xml" \
"image/vnd.microsoft.icon" \
"image/x-icon" \
"text/cache-manifest" \
"text/css" \
"text/html" \
"text/javascript" \
"text/plain" \
"text/vcard" \
"text/vnd.rim.location.xloc" \
"text/vtt" \
"text/x-component" \
"text/x-cross-domain-policy" \
"text/xml"
</IfModule>
Configuration list: https://github.com/h5bp/server-configs

Related

hudi delta streamer job via apache livy

Please help how to pass --props file and --source-class file to LIVY API POST .
spark-submit --packages org.apache.hudi:hudi-utilities-bundle_2.11:0.5.3,org.apache.spark:spark-avro_2.11:2.4.4 \
--master yarn \
--deploy-mode cluster \
--conf spark.sql.shuffle.partitions=100 \
--driver-class-path $HADOOP_CONF_DIR \
--class org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer \
--table-type MERGE_ON_READ \
--source-class org.apache.hudi.utilities.sources.JsonKafkaSource \
--source-ordering-field tst \
--target-base-path /user/hive/warehouse/stock_ticks_mor \
--target-table test \
--props /var/demo/config/kafka-source.properties \
--schemaprovider-class org.apache.hudi.utilities.schema.FilebasedSchemaProvider \
--continuous
I have converted the configs you are using in a json file to be passed to LIVY API
{
"className": "org.apache.hudi.utilities.deltastreamer.HoodieDeltaStreamer",
"proxyUser": "root",
"driverCores": 1,
"executorCores": 2,
"executorMemory": "1G",
"numExecutors": 4,
"queue": "default",
"name": "stock_ticks_mor",
"file": "hdfs://tmp/hudi-utilities-bundle_2.12-0.8.0.jar",
"conf": {
"spark.sql.shuffle.partitions": "100",
"spark.jars.packages": "org.apache.hudi:hudi-spark-bundle_2.12:0.8.0,org.apache.spark:spark-avro_2.12:3.0.2",
"spark.serializer": "org.apache.spark.serializer.KryoSerializer",
"spark.task.cpus": "1",
"spark.executor.cores": "1"
},
"args": [
"--props","/var/demo/config/kafka-source.properties",
"--table-type","MERGE_ON_READ",
"--source-class", "org.apache.hudi.utilities.sources.JsonKafkaSource",
"--target-base-path","/user/hive/warehouse/stock_ticks_mor",
"--target-table","test",
"--schemaprovider-class","org.apache.hudi.utilities.schema.FilebasedSchemaProvider",
"--continuous"
]
}
You can submit this json to the LIVY endpoint like
curl -H "X-Requested-By: admin" -H "Content-Type: application/json" -X POST -d #config.json http://localhost:8999/batches
For reference : https://community.cloudera.com/t5/Community-Articles/How-to-Submit-Spark-Application-through-Livy-REST-API/ta-p/247502

Sort does not work on Text query with parse-server

The parse-server documentation is a bit outdated: http://docs.parseplatform.org/rest/guide/
Try this query:
curl -X GET \
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
-G \
--data-urlencode 'where={"name":{"$text":{"$search":{"$term":"Milk"}}}}' \
--data-urlencode 'order="$score"' \
--data-urlencode 'key="$score"' \
https://localhost:1337/parse/classes/Groceries
And it with return this error:
{
"code": 102,
"error": "Invalid parameter for query: key"
}
Question, how do you sort by "score" when doing Full-text search with Parse if the query parameters does not work?

css sed unterminated address regex

The following sed command works great most of the time except when I try it with the following script. I get the error
sed: -e expression #1, char 3495: unterminated address regex
It points at the last character } but I can't figure out how to terminate the sed command. Usually its not a problem. Hep would be appreciated.
sed -i '/body *{/,/}/c \
body{\
z-index:1;\
margin:0;\
background-image: url("http://www.calmchess.com/images/frgrnd1366.png");\
background-repeat:repeat;\
}\
\
#header0{\
position:relative; \
width:1100px; \
height:114px; \
text-align:center; \
font-size:16px; \
color:000000; \
background-size:1100px 114px; \
background-image: url("http://www.calmchess.com/images/854x480/header854x480_114_0.png"); \
background-repeat: no-repeat; \
}\
\
#fullcontentcontainer0{ \
position:relative; \
z-index:0; \
text-align:center; \
font-size:16px; \
color:000000; \
width:1100px; \
height:135%; \
} \
\
#lrgcontentimgcontainer0{ \
position:relative; \
top:75px; \
margin:0 auto 0 auto; \
font-size:16px; \
color:000000; \
width:530px; \
height:575px; \
background-size:530px 575px; \
background-image: url("http://www.calmchess.com/images/lrgcontent0.png"); \
background-repeat: no-repeat; \
} \
\
#nav0{ \
width:1100px; \
height:60px; \
position:absolute; \
color:000000; \
z-index:6; \
font-size:16px; \
border-top:1px solid 000000; \
border-bottom:1px solid 000000; \
background-image:url("http://www.calmchess.com/images/mediumformbak0.png");\
background-repeat: no-repeat; \
} \
\
.btncon0{ \
position:relative; \
width:205px; \
height:60px; \
margin:0 auto 0 auto; \
} \
\
#footer0{ \
position:absolute; \
top:100%; \
width:100%; \
height:180px; \
font-size:16px; \
border-top:1px solid 000000; \
background-image: url("http://www.calmchess.com/images/mediumformbak0.png"); \
background-repeat: no-repeat; \
} \
\
.foliotop0{ \
position:absolute; \
width:100px; \
height:35px; \
top:5px; \
left:0px; \
font-size:16px; \
z-index:2; \
background-size:100px 35px; \
background-image: url("http://www.calmchess.com/images/port0.png"); \
background-repeat: no-repeat; \
} \
\
.foliobottom0{ \
position:absolute; \
width:100px; \
height:35px; \
top:5px; \
left:0px; \
font-size:16px; \
z-index:1; \
background-size:100px 35px; \
background-image: url("http://www.calmchess.com/images/buttonbottom0.png"); \
background-repeat: no-repeat; \
} \
\
.contacttop0{ \
position:absolute; \
width:100px; \
height:35px; \
top:5px; \
left:105px; \
font-size:16px; \
z-index:2; background-size:100px 35px; \
background-image: url("http://www.calmchess.com/images/contact0.png"); \
background-repeat: no-repeat; \
} \
\
.contactbottom0{ \
position:absolute; \
width:100px; \
height:35px; \
top:5px; \
left:105px; \
font-size:16px; \
z-index:1; \
background-size:100px 35px; \
background-image: url("http://www.calmchess.com/images/buttonbottom0.png"); \
background-repeat: no-repeat; \
} \
\
#paypal0{ \
position:absolute; \
left:460px; \
top:840px; \
font-size:21pt;\
} \
\
#paypal0 input{ \
width:300px; \
height:150px; \
} \
\
#para0{ \
font-size:21pt; \
position:absolute; \
width:500px; \
left:15px; \
top:10px; \
text-align:left; \
} \
\
#para1{ \
font-size:21pt; \
position:absolute; \
width:500px; \
left:15px; \
top:110px; \
text-align:left; \
} \
\
#para2{ \
font-size:21pt; \
position:absolute; \
width:500px; \
left:15px; \
top:350px; \
text-align:left; \
} \
\
#para3{ \
font-size:21pt; \
position:absolute; \
width:500px; \
left:15px; \
top:445px; \
text-align:left; \
} \
\
.businesscard0{ \
width:640px; \
height:480px; \
margin:0 auto 0 auto; \
font-size:16px; \
}' $file0
If you want a backslash to mark a line break, no trailing spaces are allowed.
cat -n file_with_sed_code | grep '\\ \+$'

how to configuration vim-easytags for javascript

I want to use vim-easytags for javascript, so that it can use jsctags to generate tags each time I save my code. From the documentation of vim-easytags, I notice it supports javascript tags and jsctags. But how to set the configuration struggled me. Can anyone help me fix my .vimrc?
let g:easytags_python_enabled=1
let g:easytags_events = ['BufWritePost']
let b:easytags_auto_highlight = 1
let g:easytags_async=1
let g:easytags_by_filetype=1
let g:easytags_languages = {
\ 'javascript': {
\ 'cmd': 'jsctags',
\ 'args': ['-f'],
\ 'fileoutput_opt': '-f',
\ 'stdout_opt': '-f-',
\ 'recurse_flag': '-R'
\ }
\}
This seems to do it for me:
let g:easytags_languages = {
\ 'javascript': {
\ 'cmd': 'jsctags',
\ 'recurse_flag': ''
\ }
\}

Displaying ► character in Vim terminal lightline status bar

I am working on SUSE Linux Enterprise Desktop 11 (x86_64) and I am using Vim in terminal as my editor. I have recently installed a plugin called lightline from https://github.com/itchyny/lightline.vim. The plugin uses special characters to make the status line look like this:
The > part of the bar is actually ► character coloured like the square next to it. The problem is that the bar, in my case, looks like this:
The ► character is not displayed properly, although the encoding is set to UTF-8 and all the required fonts are installed on the system (fonts for powerline). In this case the font set on terminal is Liberation Mono for Powerline.
Lightline settings in my vimrc:
set encoding=utf-8
scriptencoding utf-8
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'separator': {'left': "\u25B6", 'right': ''},
\ 'subseparator': { 'left': '', 'right': ''}
\ }
I also tried copying the ► character like this
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'separator': {'left': "►", 'right': ''},
\ 'subseparator': { 'left': '', 'right': ''}
\ }
But it manifests in the same way.
Furthermore, there is a problem with ^ characters wherever there is supposed to be whitespace.
Is there any solution for this?
Following is my my_configs.vim for lightline, it works perfectly in my Fedora 26 system.
let g:lightline = {
\ 'colorscheme': 'wombat',
\ }
let g:lightline = {
\ 'colorscheme': 'wombat',
\ 'active': {
\ 'left': [ ['mode', 'paste'],
\ ['fugitive', 'readonly', 'filename', 'modified'] ],
\ 'right': [ [ 'lineinfo' ], ['percent'] ]
\ },
\ 'component': {
\ 'readonly': '%{&filetype=="help"?"":&readonly?"\ue0a2":""}',
\ 'modified': '%{&filetype=="help"?"":&modified?"\ue0a0":&modifiable?"":"-"}',
\ 'fugitive': '%{exists("*fugitive#head")?fugitive#head():""}'
\ },
\ 'component_visible_condition': {
\ 'readonly': '(&filetype!="help"&& &readonly)',
\ 'modified': '(&filetype!="help"&&(&modified||!&modifiable))',
\ 'fugitive': '(exists("*fugitive#head") && ""!=fugitive#head())'
\ },
\ 'separator': { 'left': "\ue0b0", 'right': "\ue0b2" },
\ 'subseparator': { 'left': "\ue0b1", 'right': "\ue0b3" }
\ } "" This is comment: I fotgot this line in my last post, just added
Sorry for my mistake, I just fixed this config.
If you installed hack font from https://github.com/chrissimpkins/Hack/releases
and install powerline-fonts by command "sudo dnf install powerline-fonts" in Fedora 26 system, you probably want to add the following configs to your
/etc/fonts/local.conf
<?xml version="1.0"?>
<!DOCTYPE fontconfig SYSTEM "fonts.dtd">
<fontconfig>
<alias>
<family>Hack</family>
<prefer>
<family>PowerlineSymbols</family>
</prefer>
</alias>
</fontconfig>
The problem was explained in this thread stackoverflow.com/questions/7223309/. It says that if the stl and stlnc have the same values, they will be replaced with ^^^. It works when you put * for stlnc and whitespace for stl.

Resources