Skip to content

Instantly share code, notes, and snippets.

View felipecwb's full-sized avatar
🎧
🚀

Felipe Francisco felipecwb

🎧
🚀
View GitHub Profile
@felipecwb
felipecwb / unix2DosTime.php
Last active August 29, 2015 14:03
The function unix2DosTime() case someone need.
<?php
function unix2DosTime($unixtime = 0) {
$timearray = $unixtime ? getdate($unixtime) : getdate();
if ($timearray['year'] < 1980) {
$timearray['year'] = 1980;
$timearray['mon'] = 1;
$timearray['mday'] = 1;
$timearray['hours'] = 0;
@felipecwb
felipecwb / somecode.php
Last active August 29, 2015 14:04
Some code
<?php
namespace felipecwb\Something;
interface Storage {
public function persist($data);
public function delete($data);
public function getById($id);
}
@felipecwb
felipecwb / simpleCalculator.py
Created August 15, 2014 05:19
Exemplo de uma simples calculadora para meu mano Patrick!
# -*- coding: utf-8 -*-
opcao = True;
# enquanto (while) opcao for diferente de 0 roda o bloco de codigo dentro dele
while opcao != 0:
# imprime nome e opcoes do programa
print "\n+---------- SIMPLES CALCULADORA ------------+"
print "Opcoes:"
@felipecwb
felipecwb / ProviderInterface.php
Last active August 29, 2015 14:05
Example about how to protect of CSRF attack.
<?php
namespace Storage\Provider;
interface ProviderInterface
{
/**
* @param string $identifier
* @param mixed $data
* @return bool
@felipecwb
felipecwb / codeStyle.js
Last active August 29, 2015 14:08
How I write my javascript!
(function (global) {
"use strict";
// namespace
global.Space = {
entities: {}
};
// class
global.Space.entities.UserEntity = function (theName, theAge) {
@felipecwb
felipecwb / liskov.php
Last active August 29, 2015 14:08
Liskov Substitution Principe
<?php
// uma subclasse deve sobrescrever os métodos da classe pai,
// de tal maneira que não quebre a funcionalidade do ponto de vista do cliente.
namespace Application\Repository;
use Application\DataManager\DataManager;
class DataRepository
@felipecwb
felipecwb / jsonview.php
Last active August 29, 2015 14:11
A simple JSON pretty view written in PHP.
#!/usr/bin/env php
<?php
define('TITLE', PHP_EOL . "Json Pretty print - @felipecwb" . PHP_EOL);
function showHelp() {
echo TITLE;
echo "\tUsage:" . PHP_EOL;
echo "\t- jsonlint [file.json]" . PHP_EOL;
echo "\t- string.json | jsonlint" . PHP_EOL . PHP_EOL;
@felipecwb
felipecwb / container.php
Created January 5, 2015 21:53
Simple Data Container
<?php
namespace Felipecwb\Sample;
class Container
{
private $maps = [];
public function __call($identity, array $arguments)
{
@felipecwb
felipecwb / Date.compare.js
Last active August 29, 2015 14:14
compare between Dates
(function () {
/**
* compare date, return 0 = equals, 1 = date1 > date2, -1 = date1 < date2
* @param {String} date1 string in W3C format (Y-m-d\TH:i:sP)
* @param {String} date2 string in W3C format (Y-m-d\TH:i:sP)
* @return {int|bool} false if dates are invalid, 0 = equals, 1 = date1 > date2, -1 = date1 < date2
*/
Date.compare = function (date1, date2) {
if (! (date1 instanceof Date)) {
date1 = new Date(date1);
@felipecwb
felipecwb / cnhValidation.js
Last active November 16, 2022 01:16
CNH (Carteira Nacional de Habilitação) validation in JS
function validateCNH(cnh) {
var char1 = cnh.charAt(0);
if (cnh.replace(/[^\d]/g, '').length !== 11 || char1.repeat(11) === cnh) {
return false;
}
for (var i = 0, j = 9, v = 0; i < 9; ++i, --j) {
v += +(cnh.charAt(i) * j);
}