Skip to content

Instantly share code, notes, and snippets.

<?php
include ('vendor/autoload.php');
use PhpAmqpLib\Connection\AMQPStreamConnection;
use PhpAmqpLib\Message\AMQPMessage;
$connection = new AMQPStreamConnection('localhost', 5672, 'guest', 'guest');
$channel = $connection->channel();
//Create the queue
<?php
include ('vendor/autoload.php');
use prodigyview\media\Video;
use prodigyview\util\FileManager;
use PhpAmqpLib\Connection\AMQPStreamConnection;
//Start RabbitMQ Server
$connection = new AMQPStreamConnection('127.0.0.1', 5672, 'guest', 'guest');
$channel = $connection->channel();
@odixon
odixon / remove-duplicates.sql
Created July 9, 2019 22:38 — forked from adamgibbons/remove-duplicates.sql
delete duplicate zips
DELETE FROM geoname WHERE (zip, place, state) IN
(SELECT DISTINCT ON (zip) zip, place, state FROM geoname WHERE zip IN
( '10804',
'15129',
'15714',
'19018',
'27539',
'28470',
@odixon
odixon / node-pdf-generator.js
Created July 9, 2019 22:37 — forked from adamgibbons/node-pdf-generator.js
Display or download PDF from node.js server
var restify = require('restify')
, port = process.env.PORT || 3000
, Phantom = require('phantom')
, tmpdir = require('os').tmpdir()
, fs = require('fs');
var server = restify.createServer();
function setResponseHeaders(res, filename) {
res.header('Content-disposition', 'inline; filename=' + filename);
@odixon
odixon / slim-stream-route.php
Created July 9, 2019 22:32 — forked from james2doyle/slim-stream-route.php
Create a streaming download of a large file with Slim PHP using the build in Stream class
<?php
use Slim\Http\Request;
use Slim\Http\Response;
use Slim\Http\Stream;
$app->get('/stream', function (Request $request, Response $response, array $args) {
// a 100mb file
$path = '../public/files/document.pdf';
@odixon
odixon / pre-push
Created June 13, 2019 22:19 — forked from barryvdh/pre-push
Git pre-push hook for PHPUnit
#!/usr/bin/env php
<?php
echo "Running tests.. ";
exec('vendor/bin/phpunit', $output, $returnCode);
if ($returnCode !== 0) {
// Show full output
echo PHP_EOL . implode($output, PHP_EOL) . PHP_EOL;
echo "Cannot push changes untill tests are OK.." . PHP_EOL;
exit(1);
}
@odixon
odixon / pre-commit
Created June 12, 2019 21:55 — forked from raphaelstolt/pre-commit
A pre-commit for running PHPUnit
#!/usr/bin/php
<?php
printf("%sGit pre-commit hook %1\$s", PHP_EOL);
$projectName = basename(getcwd());
exec('phpunit --configuration phpunit.xml', $output, $returnCode); // Assuming cwd here
if ($returnCode !== 0) {
$minimalTestSummary = array_pop($output);
printf("Test suite for %s failed: ", $projectName);
printf("( %s ) %s%2\$s", $minimalTestSummary, PHP_EOL);
return false; // exit(1);
@odixon
odixon / pre-commit
Created June 12, 2019 21:51 — forked from polonskiy/pre-commit
PHPLint pre-commit git hook
#!/usr/bin/php
<?php
exec('git diff --name-only --diff-filter=ACM --cached', $files);
$status = 0;
foreach ($files as $file) {
if (pathinfo($file, PATHINFO_EXTENSION) != 'php') continue;
$file = escapeshellarg($file);
$message = array();
exec("git show :$file | php -l 2>&1", $message, $code);
@odixon
odixon / sources.list
Created June 12, 2019 04:04 — forked from h0bbel/sources.list
/etc/apt/sources.list for Ubuntu 18.04.1 LTS Bionic Beaver
# See http://help.ubuntu.com/community/UpgradeNotes for how to upgrade to
# newer versions of the distribution.
deb http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic main restricted
## Major bug fix updates produced after the final release of the
## distribution.
deb http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
# deb-src http://us.archive.ubuntu.com/ubuntu/ bionic-updates main restricted
@odixon
odixon / guzzle-http-errors-example.php
Created October 11, 2018 12:58
Guzzle with http errors off
<?php
// create client
$client = new \GuzzleHttp\Client();
$res = $client->request('GET', $someApi, ['http_errors' => false]);
// check http status code
if ($res->getStatusCode() != 200) {
// handle it
}