Skip to content

Instantly share code, notes, and snippets.

Shaun shaunlee

Block or report user

Report or block shaunlee

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@shaunlee
shaunlee / CorsMiddleware.php
Last active Mar 14, 2017
Lumen with CORS and OPTIONS requests
View CorsMiddleware.php
<?php
namespace App\Http\Middleware;
use Closure;
class CorsMiddleware
{
/**
* Handle an incoming request.
View circle_byte_buffer.go
package main
import (
"io"
"errors"
)
var ErrBufferIsNotEnough = errors.New("buffer is not enough")
type ByteBuffer struct {
@shaunlee
shaunlee / gist:dfbf5d805d4f5a3f9a54
Created Oct 26, 2015 — forked from jessedearing/gist:2351836
Create self-signed SSL certificate for Nginx
View gist:dfbf5d805d4f5a3f9a54
#!/bin/bash
echo "Generating an SSL private key to sign your certificate..."
openssl genrsa -des3 -out myssl.key 1024
echo "Generating a Certificate Signing Request..."
openssl req -new -key myssl.key -out myssl.csr
echo "Removing passphrase from key (for nginx)..."
cp myssl.key myssl.key.org
openssl rsa -in myssl.key.org -out myssl.key
View angularjs_demo.js
angular.module('App', []).config(['$interpolateProvider', function($interpolateProvider) {
$interpolateProvider.startSymbol('[[');
$interpolateProvider.endSymbol(']]');
}]);
@shaunlee
shaunlee / router.php
Created Aug 28, 2015
Phalcon Micro MVC Router
View router.php
<?php
$filename = $_SERVER['REQUEST_URI'];
if ($i = strpos($filename, '?')) {
$filename = substr($filename, 0, $i);
}
if (file_exists(__DIR__ . $filename)) {
return false;
}
@shaunlee
shaunlee / clear_tube.php
Last active Mar 2, 2016
beanstalkd: clear tube
View clear_tube.php
<?php
include 'pheanstalk/pheanstalk_init.php';
$ph = new Pheanstalk_Pheanstalk('127.0.0.1');
$ph->ignore('default')->watch($tube);
while ($job = $ph->reserve(0)) {
$ph->delete($job);
fwrite(STDOUT, $job->getId() . "\r");
@shaunlee
shaunlee / main.js
Last active Jun 10, 2018
NodeJS Cluster
View main.js
var cluster = require('cluster'),
numCPUs = require('os').cpus().length;
if (cluster.isMaster) {
while (numCPUs-- > 0) cluster.fork();
cluster.on('exit', function(worker, code, signal) {
console.log('worker ' + worker.process.pid + ' died');
cluster.fork();
});
@shaunlee
shaunlee / pre-commit.sh
Last active Mar 2, 2016
Git hooks for phpcs
View pre-commit.sh
#!/bin/bash
#.git/hooks/pre-commit
EXEC=`php -r "echo 'php ', implode(DIRECTORY_SEPARATOR, [__DIR__, 'vendor', 'bin', 'phpcs']);"`
FILES=`git diff --cached --name-only | grep -i php$ | grep ^app`
ARGS='--standard=psr2 --encoding=utf8 -p'
for fn in $FILES; do
if [ ! -f $fn ]; then
DELETE=($fn)
@shaunlee
shaunlee / queue.go
Last active Mar 2, 2016
Recycle Queue
View queue.go
package main
import (
"fmt"
"time"
"sync/atomic"
)
const (
ITEM_DATA_SIZE = 4096
@shaunlee
shaunlee / restful.go
Last active Sep 29, 2017
Simple RESTful web dispatcher
View restful.go
package main
import (
"fmt"
"log"
"net/http"
"regexp"
"strings"
)
You can’t perform that action at this time.