Skip to content

Instantly share code, notes, and snippets.

View thiagolcks's full-sized avatar

Thiago Locks thiagolcks

View GitHub Profile
@thiagolcks
thiagolcks / ML2-Trabalho-1-Q1.ipynb
Created May 8, 2018 19:07
Questão 1 - Classificação
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@thiagolcks
thiagolcks / DecoratorAbstract.php
Last active January 31, 2017 16:57 — forked from CMCDragonkai/DecoratorAbstract.php
PHP: DecoratorAbstract - Allows the creation of flexible nested decorators.
<?php
/**
* DecoratorAbstract allows the creation of flexible nested decorators. All decorators must extend from this class.
* Decorators can be stacked. They can also have methods that overwrite each other.
* Decorators can omit methods that parent decorators have defined and/or child decorators have defined.
* Methods will cascade to the original child object.
* Properties will read and set from the original child object except when your instance has the property defined.
*/
abstract class DecoratorAbstract
@thiagolcks
thiagolcks / letsencrypt.sh
Last active October 5, 2016 16:02
Script to generate the SSL certificate via Letsencrypt
#!/bin/sh
if [ ! -d "/opt/letsencrypt" ]
then
sudo git clone https://github.com/letsencrypt/letsencrypt /opt/letsencrypt
fi
if [ ! -f "/etc/nginx/snippets/letsencrypt.conf" ]
then
echo "location '/.well-known/acme-challenge' {\n default_type 'text/plain';\n root /tmp/letsencrypt;\n}" | sudo tee /etc/nginx/snippets/letsencrypt.conf
@thiagolcks
thiagolcks / README.md
Created September 27, 2016 01:43 — forked from oodavid/README.md
Backup MySQL to Amazon S3

Backup MySQL to Amazon S3

This is a simple way to backup your MySQL tables to Amazon S3 for a nightly backup - this is all to be done on your server :-)

Sister Document - Restore MySQL from Amazon S3 - read that next

1 - Install s3cmd

this is for Centos 5.6, see http://s3tools.org/repositories for other systems like ubuntu etc

@thiagolcks
thiagolcks / app-threads.py
Last active August 31, 2016 22:55
Playing with threads using Python
import threading, time, random
class Counter (threading.Thread):
num = 0
def reset(self):
self.num = 0
def run(self):
while True:
@thiagolcks
thiagolcks / CNPJ.php
Created December 10, 2015 17:16
Validador de CNPJ para Phalcon
<?php
namespace App\Validators;
use Phalcon\Validation\Message;
use Phalcon\Validation\Validator;
use Phalcon\Validation\ValidatorInterface;
use Phalcon\Validation;
class CNPJ extends Validator implements ValidatorInterface
@thiagolcks
thiagolcks / CPF.php
Created December 10, 2015 13:04
Validador de CPF para Phalcon
<?php
namespace App\Validators;
use Phalcon\Validation\Message;
use Phalcon\Validation\Validator;
use Phalcon\Validation\ValidatorInterface;
use Phalcon\Validation;
class CPF extends Validator implements ValidatorInterface
@thiagolcks
thiagolcks / ZName.php
Last active July 5, 2016 12:55
Class to sanitize user names
<?php
namespace Library\ZName;
class ZName
{
static private $compound_names = [];
public static function validate($name)
{
@thiagolcks
thiagolcks / Z_Settings_Fields.php
Last active September 14, 2015 18:47
Class to help create fields with WP Settings API
<?php
if ( ! class_exists( 'Z_Settings_Fields' ) ) {
class Z_Settings_Fields {
public function text( $args = array() ) {
$value = esc_attr( get_option( $args['id'] ) );
// Note the ID and the name attribute of the element should match that of the ID in the call to add_settings_field
$html = '<input type="text" class="regular-text" id="' . $args['id'] . '" name="' . $args['id'] . '" value="' . $value . '" />';