Skip to content

Instantly share code, notes, and snippets.

View stefanorg's full-sized avatar

Stefano stefanorg

View GitHub Profile
function random_text( $type = 'alnum', $length = 8 )
{
switch ( $type ) {
case 'alnum':
$pool = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'alpha':
$pool = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
break;
case 'hexdec':
@stefanorg
stefanorg / find-missing-return-types.php
Created January 23, 2016 06:29 — forked from Ocramius/find-missing-return-types.php
Script to find classes/interfaces/traits with missing return types: ADD THEM TO YOUR SHIT.
<?php
require_once __DIR__ . '/vendor/autoload.php';
$namespace = 'PutYourProjectNamespaceHere\\';
foreach (new RegexIterator(new RecursiveIteratorIterator(new RecursiveDirectoryIterator(__DIR__ . '/src')), '/^.+\.php$/i', RecursiveRegexIterator::GET_MATCH) as $file) {
require_once $file[0];
}
@stefanorg
stefanorg / CastsValueObject.php
Created February 28, 2016 20:10 — forked from cmaas/CastsValueObject.php
A Trait to automatically cast value objects in Laravel without needing a Mutator and an Accessor.
<?php
trait CastsValueObjects
{
protected function castAttribute($key, $value)
{
$castToClass = $this->getValueObjectCastType($key);
// no Value Object? simply pass this up to the parent
if (!$castToClass) {
return parent::castAttribute($key, $value);
@stefanorg
stefanorg / INSTALL.rst
Created January 17, 2017 06:56 — forked from jensens/INSTALL.rst
sentry setup with docker-compose

In order to run this image do: docker-compose up -d to get all up. On first run DB initialization and initial user setup is done like so:

First start a bash in the container: docker-compose exec sentry /bin/bash. Then, inside bash, do sentry upgrade wait until it asks you for an inital user. When finished exit the bash.

When in doubt check with docker-compose ps if all went fine.

@stefanorg
stefanorg / ResponseTimeLogger.java
Created September 29, 2017 20:46 — forked from erard22/ResponseTimeLogger.java
An interceptor logging the response time and additional information of a REST call to a Resteasy resource
import javax.servlet.http.HttpServletRequest;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.annotations.interception.ServerInterceptor;
import org.jboss.resteasy.core.ResourceMethod;
import org.jboss.resteasy.core.ServerResponse;
import org.jboss.resteasy.spi.Failure;
import org.jboss.resteasy.spi.HttpRequest;
@stefanorg
stefanorg / .gitlab-ci.yml
Created October 10, 2018 15:17 — forked from jlis/.gitlab-ci.yml
AWS ECS and ECR deployment via Docker and Gitlab CI
image: docker:latest
variables:
REPOSITORY_URL: <AWS ACCOUNT ID>.dkr.ecr.eu-central-1.amazonaws.com/<ECS REPOSITORY NAME>
REGION: eu-central-1
TASK_DEFINTION_NAME: <TASK DEFINITION NAME>
CLUSTER_NAME: <CLUSTER NAME>
SERVICE_NAME: <SERVICE NAME>
services:
@stefanorg
stefanorg / api.js
Created March 12, 2019 06:07 — forked from giacomocerquone/api.js
Api service
const makeCancelable = promise => {
let hasCanceled = false;
const wrappedPromise = new Promise((resolve, reject) => {
promise.then(
val => (hasCanceled ? reject(Error('Request canceled')) : resolve(val)),
error =>
hasCanceled ? reject(Error('Request canceled')) : reject(error),
);
});
@stefanorg
stefanorg / network-stack.ts
Created April 28, 2019 05:45 — forked from jewelsjacobs/network-stack.ts
CDK VPC Subnets with CIDR Addresses
import cdk = require('@aws-cdk/cdk');
import ec2 = require('@aws-cdk/aws-ec2');
import { SubnetType } from '@aws-cdk/aws-ec2';
const region = 'us-east';
const azA = `${region}-1a`;
const azB = `${region}-1b`;
const azC = `${region}-1c`;
const availabilityZones = [azA, azB, azC];
const publicCidrs = ['10.1.192.0/24', '10.1.194.0/24', '10.1.196.0/24']
@stefanorg
stefanorg / S3-Static-Sites.md
Created May 5, 2019 13:35 — forked from bradwestfall/S3-Static-Sites.md
Use S3 and CloudFront to host Static Single Page Apps (SPAs) with HTTPs and www-redirects. Also covers deployments.

S3 Static Sites

What this will cover

  • Host a static website at S3
  • Redirect www.website.com to website.com
  • Website can be an SPA (requiring all requests to return index.html)
  • Free AWS SSL certs
  • Deployment with CDN invalidation

Resources

@stefanorg
stefanorg / wildfly-9.0.2.Final-standalone-full-ha.cli
Created June 21, 2019 07:17 — forked from cheinema/wildfly-9.0.2.Final-standalone-full-ha.cli
WildFly CLI scripts to build the default configurations
embed-server --server-config=custom-full-ha.xml --empty-config --remove-existing
# Extensions first
batch
/extension=org.jboss.as.clustering.infinispan:add
/extension=org.jboss.as.clustering.jgroups:add
/extension=org.jboss.as.connector:add
/extension=org.jboss.as.deployment-scanner:add
/extension=org.jboss.as.ee:add
/extension=org.jboss.as.ejb3:add
/extension=org.jboss.as.jaxrs:add