Skip to content

Instantly share code, notes, and snippets.

@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 / 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-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 / 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 / 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 / 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',
<?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();
<?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
@odixon
odixon / node_redis_cache.js
Created August 20, 2019 21:07 — forked from bradtraversy/node_redis_cache.js
Node.js & Redis Caching
const express = require('express');
const fetch = require('node-fetch');
const redis = require('redis');
const PORT = process.env.PORT || 5000;
const REDIS_PORT = process.env.PORT || 6379;
const client = redis.createClient(REDIS_PORT);
const app = express();
@odixon
odixon / snake-nginx.nix
Created September 19, 2019 19:15 — forked from thoughtpolice/snake-nginx.nix
A complete example of a working Hydra build machine and other stuff.
let
# Wrap a nginx server block in an HTTPS site
wrapSSL = site: cert: key: block: ''
server {
listen 80;
listen [::]:80;
server_name ${site};
location /nginx_status {
stub_status on;