Really simple and bare-bone example:
function MacBook() {
this.cost = function () {
return 997
};
this.screenSize = function () {
return 11.6
};
}
// Decorator 1
function Memory(macbook) {
var v = macbook.cost();
macbook.cost = function() {
return v + 75;
};
}
// Decorator 2
function Engraving(macbook) {
var v = macbook.cost();
macbook.cost = function() {
return v + 200;
};
}
// Decorator 3
function Insurance(macbook) {
var v = macbook.cost();
macbook.cost = function() {
return v + 250;
};
}
var mb = new MacBook();
Memory(mb);
Engraving(mb);
Insurance(mb);
// Outputs: 1522
console.log(mb.cost());
// Outputs: 11.6
console.log(mb.screenSize());
My Pastebin example...
Unlike zip
, gzip
functions as a compression algorithm only.
Because of various reasons some of which hearken back to the era of tape drives, Unix uses a program named tar
to archive data, which can then be compressed with a compression program like gzip
, bzip2
, 7zip
, etc.
In order to "zip" a directory, the correct command would be:
tar -zcvf archive.tar.gz directory/
This will tell
tar to:
directory
(tar
is recursive by default)f
(file) named archive.tar.gz
The tar
command offers gzip
support (via the -z
flag) purely for your convenience. The gzip
command/lib is completely separate. The command above is effectively the same as:
tar -cv directory | gzip > archive.tar.gz
To decompress and unpack the archive into the current directory you would use:
tar -zxvf archive.tar.gz
That command is effectively the same as:
gunzip < archive.tar.gz | tar -xv
UPDATE: 2020-02-04
Using the -a
prefix will auto-detect the compression type from the extension type:
tar -acf [file.gz|bz...] [directory]
to compress -c
tar -axf [file.gz|bz...]
to extract -x
.htaccess
in apache2Redirect 301 /path/to/the-url /new-path/to/the-new-url
$ mysqladmin -u my_pass -p -i 1 processlist
This will print the current queries on your screen every second.
-u
The mysql user you want to execute the command as-p
Prompt for your password (so you don't have to save it in a file or have the command appear in your command history)-i
The interval in seconds.Use the --verbose
flag to show the full process list, displaying the entire query for each process.
There is a possible downside: fast queries might not show up if they run between the interval that you set up. IE: My interval is set at one second and if there is a query that takes .02
seconds to run and is ran between intervals, you won't see it.
Use this option preferably when you quickly want to check on running queries without having to set up a listener or anything else.
<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'YOUR-API-ACCESS-KEY-GOES-HERE' );
$registrationIds = array( $_GET['id'] );
// prep the bundle
$msg = array
(
'message' => 'here is a message. message',
'title' => 'This is a title. title',
'subtitle' => 'This is a subtitle. subtitle',
'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
'vibrate' => 1,
'sound' => 1,
'largeIcon' => 'large_icon',
'smallIcon' => 'small_icon'
);
$fields = array
(
'registration_ids' => $registrationIds,
'data' => $msg
);
$headers = array
(
'Authorization: key=' . API_ACCESS_KEY,
'Content-Type: application/json'
);
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;