Skip to content

Instantly share code, notes, and snippets.

🏠
Working from home

Chris Fidao fideloper

🏠
Working from home
Block or report user

Report or block fideloper

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
@fideloper
fideloper / stream_file.php
Last active Aug 29, 2019
Stream file from S3 to browser, assume Laravel Filesystem usage
View stream_file.php
<?php
/*************************************************************************
* Get File Information
*/
// Assuming these come from some data source in your app
$s3FileKey = 's3/key/path/to/file.ext';
$fileName = 'file.ext';
@fideloper
fideloper / Gettable.php
Created Mar 9, 2014
Trait for making protected/private attributes "gettable", leaving "setting" the attributes a matter of business logic to be implemented.
View Gettable.php
<?php
trait Gettable {
/**
* Retrieve private attributes.
* Attributes should be protected
* so they cannot be *set* arbitrarily.
* This allows us to *get* them as if they
* were public.
@fideloper
fideloper / crypt.py
Created Jun 4, 2015
Decrypt Laravel-encrypted value
View crypt.py
import os
import base64
import json
from Crypto.Cipher import AES
from phpserialize import loads
def decrypt(payload):
data = json.loads(base64.b64decode(payload))
@fideloper
fideloper / update_curl.sh
Last active Aug 18, 2019
Update curl on Ubuntu 14.04
View update_curl.sh
#! /usr/bin/env bash
# Install any build dependencies needed for curl
sudo apt-get build-dep curl
# Get latest (as of Feb 25, 2016) libcurl
mkdir ~/curl
cd ~/curl
wget http://curl.haxx.se/download/curl-7.50.2.tar.bz2
tar -xvjf curl-7.50.2.tar.bz2
@fideloper
fideloper / connections.sh
Created Dec 19, 2018
Quick and dirty monitoring of mysql connections
View connections.sh
#!/usr/bin/env bash
# 5 minutes between alerts
SECONDS_BETWEEN_ALERTS=300
# Track when we sent the last alert
LAST_ALERT=0
while true; do
NUMBER_CONNECTIONS=$(mysql --defaults-extra-file=/data/.prod.cnf -sNe "select count(*) as connection_count from INFORMATION_SCHEMA.PROCESSLIST;")
@fideloper
fideloper / ci_style_guide.md
Created Oct 10, 2012
CodeIgniter Style Guide
View ci_style_guide.md

CodeIgniter Style Guide

This is collectively being called a style guide, however it serves as a standard to enforce a stricter and more enforced methodology in how programming should be done in CodeIgniter.

Why

CodeIgniter is powerful. CodeIgniter is hugely popular. It's popular because it's easy. It's easy because there are many ways to accomplish a task.

CodeIgniter is terrible for the exact reasons which make it powerful. You can too easily place code in a confusing place, or not separate concerns, thus creating programming challenges down the line. It's noob-friendly, which means it's inherently easy to make noob mistakes.

This document serves to restrict coding practices within CodeIgniter with the purpose of making an application with more class (pun without-a-doubt, most-strongly intended).

@fideloper
fideloper / usevm.md
Created Jun 6, 2012
You should develop in a Virtual Machine
View usevm.md

#You should do all your LAMP development in a Virtual Machine

##Here's Why:

Many of us develop on Macintoshes. There are many reasons for this, but one of them is that it's based on a Unix platform of some sort. This allows us to run common server software such as Apache, Ruby, Python and Nodejs on our Macs.

Our computers become powerful develoment machines similar to the servers our apps will eventually live on.

Sometime we start our computer only to find Apache won't start, or MySQL can't create a PID file, or we've updated to Mountain Lion and Apache needs to be reconfigured. Death!

@fideloper
fideloper / start-container.sh
Last active Aug 2, 2019
Enable/Disable xDebug depending on env.
View start-container.sh
#!/usr/bin/env bash
###
# A CMD or ENTRYPOINT script for a Dockerfile to use to start a Nginx/PHP-FPM
#
# For more details, see 🐳 https://shippingdocker.com
##
if [ ! "production" == "$APP_ENV" ] && [ ! "prod" == "$APP_ENV" ]; then
# Enable xdebug
@fideloper
fideloper / echo.js
Created Nov 16, 2012
Echo server (node.js)
View echo.js
var net = require("net"), sys = require('sys');
var clients = [], i;
var server = net.createServer(function (stream) {
stream.setEncoding("utf8");
stream.on("connect", function () {
clients.push(stream);
});
stream.on("data", function (data) {
console.log(data + "sending to " + clients.length + " clients.");
@fideloper
fideloper / .zshrc
Created Jun 21, 2019
Defer loading of NVM to increase new terminal init speed
View .zshrc
# Thanks to https://www.growingwiththeweb.com/2018/01/slow-nvm-init.html, modified
# for zsh as "type -t" works in bash but not zsh
# Add this to your .zshrc ...
# Defer initialization of nvm until nvm, node or a node-dependent command is
# run. Ensure this block is only run once if .bashrc gets sourced multiple times
# by checking whether __init_nvm is a function.
if [ -s "$HOME/.nvm/nvm.sh" ] && [ ! "$(type -w __init_nvm | awk '{print $2}')" = function ]; then
You can’t perform that action at this time.