Skip to content

Instantly share code, notes, and snippets.

View campezzi's full-sized avatar

Thiago Campezzi campezzi

View GitHub Profile
@campezzi
campezzi / gist:a5ec0ec17497df2d081d
Last active August 29, 2015 14:05
PHPThumb - Rotate image based on orientation
// Get PHPThumb from: https://github.com/masterexploder/PHPThumb
App::import('Vendor', 'PHPThumb', array('file' => 'PHPThumb/ThumbLib.inc.php'));
try {
$image = PhpThumbFactory::create($file_path, array('jpegQuality' => 75));
} catch (Exception $e) {
$this->outputError(array('unknown_error' => 'unknown_error'));
}
$exif = @exif_read_data($file_path);
if (!empty($exif['Orientation'])) {
$orientation = $exif['Orientation'];
@campezzi
campezzi / gulpfile.js
Created March 24, 2015 23:20
Gulp + Browserify + Reactify + Watch + LiveReload
var source = require('vinyl-source-stream');
var gulp = require('gulp');
var gutil = require('gulp-util');
var browserify = require('browserify');
var reactify = require('reactify');
var notify = require("gulp-notify");
var livereload = require('gulp-livereload');
var scriptsDir = './src/js';
var buildDir = './public/js';
@campezzi
campezzi / ecs-cli-commands.sh
Last active February 22, 2021 02:02
Amazon ECS deployment using the ecs-cli
# Full documentation: http://docs.aws.amazon.com/AmazonECS/latest/developerguide/ECS_CLI.html
# Replace the cluster name, keypair, exposed ports etc. as necessary.
# Install the ECS CLI and make it executable
sudo curl -o /usr/local/bin/ecs-cli https://s3.amazonaws.com/amazon-ecs-cli/ecs-cli-linux-amd64-latest
sudo chmod +x /usr/local/bin/ecs-cli
# Configure the CLI (login details, region and cluster name)
ecs-cli configure --region ap-southeast-2 --access-key $AWS_ACCESS_KEY_ID --secret-key $AWS_SECRET_ACCESS_KEY --cluster CreateBTATaskUI

A “Rosetta Stone” project to learn new web frameworks. Try to figure out the ideal path to learn a new programming language or framework - a kind of project that uses most features of regular web applications, but is reasonably simple to build. After that sample application is built, the programmer should feel confident about trying the language/framework in production, knowing that he’ll be able to perform a good portion of the work (of course there are always some app-specific requirements that cause problems, but that’s fine as long as the bulk of the work can be tackled with confidence).

  • CRUD
  • Serializing and deserializing JSON
  • Consuming third-party REST APIs
  • Data validation
  • User authentication + sessions
  • Database IO
  • Disk IO
  • Long running background tasks
@campezzi
campezzi / docker-compose.yml
Created September 7, 2016 11:08
PostGres Provisioning with docker-compose
version: '2'
services:
dev_db:
image: "postgres:9.5"
environment:
- POSTGRES_PASSWORD=postgres
- POSTGRES_DB=dev_database
ports:
@campezzi
campezzi / instructions.md
Last active September 19, 2016 10:03
Phoenix + Elm setup

Phoenix + Elm Setup

Important

  1. This was tested on Phoenix 1.2.0;
  2. Make sure you have npm 3.x or above - older versions will spit out tons of Babel-related errors.

Instructions

  1. Create a Phoenix project: mix phoenix.new my_awesome_project
@campezzi
campezzi / 01_imperative.exs
Created October 11, 2016 23:25
Comparison of an imperative bit of code vs. a typical Elixir functional implementation
chunk_size = 50_000
lists =
Enum.map(0..19, fn x ->
range_start = x * chunk_size
range_end = range_start + chunk_size
Enum.map(range_start..range_end, fn y -> %{data: %{title: "#{y} is love, #{y} is life"}} end)
end)
Enum.each(lists, fn list -> Repo.insert_all(Meme, list) end)
@campezzi
campezzi / query.sql
Created October 11, 2016 23:32
Calculate Postgres index size
SELECT
t.tablename,
indexname,
c.reltuples AS num_rows,
pg_size_pretty(pg_relation_size(quote_ident(t.tablename)::text)) AS table_size,
pg_size_pretty(pg_relation_size(quote_ident(indexrelname)::text)) AS index_size,
CASE WHEN indisunique THEN 'Y'
ELSE 'N'
END AS UNIQUE,
idx_scan AS number_of_scans,
@campezzi
campezzi / api.tf
Created November 15, 2016 00:01 — forked from keeth/api.tf
Apex + Terraform + AWS Lambda + API Gateway + JSON Encoded Errors + CORS
resource "aws_api_gateway_rest_api" "myApi" {
name = "myApi-${var.env}"
description = "My awesome API (${var.env} environment)"
}
resource "aws_api_gateway_deployment" "myApi" {
depends_on = [
"aws_api_gateway_integration.myApi_myEndpoint_post",
"aws_api_gateway_integration_response.myApi_myEndpoint_post",
"aws_api_gateway_integration_response.myApi_myEndpoint_post_400",
@campezzi
campezzi / logsearch.sh
Created May 29, 2017 05:04
Search for lambda logs
#!/usr/bin/env bash
function get_events() {
echo "Fetching logs for $1 lambda in the $2 region (since $3)..."
aws logs filter-log-events --log-group-name "/aws/lambda/$1" --region "$2" --start-time "$3" --filter-pattern requestId | jq '.events'
}
case $1 in
"all")
get_events $2 ${3:-us-west-2} ${4:-1496030995836}
;;