<?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;
var ws = require('ws');
var fs = require('fs');
var https = require('https');
var options = {
server : https.createServer({
cert : fs.readFileSync('/path/to/crt'),
key : fs.readFileSync('/path/to/key'),
}).listen(2000)
};
var timeout;
fs.watch('/path/to/crt', () => {
clearTimeout(timeout);
timeout = setTimeout(() => {
options.server._sharedCreds.context.setCert(fs.readFileSync('/path/to/crt'));
options.server._sharedCreds.context.setKey(fs.readFileSync('/path/to/key'));
}, 1000);
});
new ws.Server(options);
...maybe incited of timeout is better to use _.debaunce
Anything older than 7 days should be deleted.!
const fs = require('fs');
const path = require('path');
const dirname = path.join(__dirname, 'files');
const files = fs.readdirSync(dirname);
const ms1Day = 24*60*60*1000;
files.forEach(file => {
const filePath = path.join(dirname, file);
fs.stat(filePath, (err, stats) => {
if (err) throw err;
if ((Date.now() - stats.mtime.getTime() > 7*ms1Day)) {
fs.unlink(filePath, (err) => {
if (err) throw err;
console.log(`deleted ${filePath}`);
});
}
});
});
pluralsight jscomplete/advanced-nodejs course files
<- good and free!