Skip to content

Instantly share code, notes, and snippets.

View felladrin's full-sized avatar

Victor Nogueira felladrin

View GitHub Profile
const server = require('./server');
console.log('Checking if database tables are up to date...');
const dataSource = server.dataSources.db;
const modelsNamesInLowerCase = [];
const modelsToCheck = [];
Object.keys(server.models).forEach((model) => {
if (modelsNamesInLowerCase.indexOf(model.toLowerCase()) !== -1) return;
@felladrin
felladrin / php-time-to-js-date.pipe.spec.ts
Created November 17, 2017 15:29
Angular Pipe to convert PHP time() (unix timestamp) to JS Date and return as string. It makes use of Angular's built-in DatePipe.
import {PhpTimeToJsDatePipe} from './php-time-to-js-date.pipe';
describe('PhpTimeToJsDatePipe', () => {
it('correctly transform "1510688296" into "14 de nov de 2017"', () => {
const pipe = new PhpTimeToJsDatePipe('pt-BR');
expect(pipe.transform(1510688296)).toBe('14 de nov de 2017');
});
});
@felladrin
felladrin / index.html
Created November 7, 2017 23:31
Unity3D WebGL index.html to display game always in full-screen
<!DOCTYPE html>
<html lang="en-us">
<head>
<meta charset="utf-8">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Game</title>
<link rel="shortcut icon" href="TemplateData/favicon.ico">
<link rel="stylesheet" href="TemplateData/style.css">
<script src="TemplateData/UnityProgress.js"></script>
<script src="Build/UnityLoader.js"></script>
@felladrin
felladrin / ViaCEP_jQuery.js
Created June 30, 2016 22:32
Pega o valor do campo de texto #cep (ao deixar o campo), consulta o viacep.com.br e preenche os campos do formulário com o retorno. Além disso garante que o campo tenha apenas caracteres numéricos. Não repete a consulta enquanto o cep permanecer o mesmo. E só realiza a consulta no webservice se o CEP for composto de exatamente 8 caracteres numér…
var lastCheckedValue = null;
$("#cep").blur(function () {
var cep = $(this).val().replace(/\D/g, "");
if (cep.length != 8) {
console.error("CEP deve ser composto por exatamente 8 caracteres numéricos.");
return;
}
if (cep == lastCheckedValue)
@felladrin
felladrin / Permutation.java
Created June 24, 2016 00:16
Just a simple Java permutation script I've written for a friend.
import java.util.ArrayList;
import java.util.List;
public class Permutation {
private List<String> result = new ArrayList<String>();
public Permutation(int number) {
List<Integer> sequence = new ArrayList<Integer>();
@felladrin
felladrin / str_replace_last_occurrence.php
Created April 11, 2016 00:17
PHP function that replaces the last occurrence of a string in a string.
<?php
/**
* Replaces the last occurrence of a string in a string.
*
* @param string $search The value being searched for.
* @param string $replace The replacement string.
* @param string $subject The string being searched and replaced on.
*
* @return string The string with the replaced values.
*/
@felladrin
felladrin / mail_utf8.php
Created April 11, 2016 00:15
Improved mail function to correctly send UTF-8 characters.
<?php
/**
* Improved mail function to correctly send UTF-8 characters.
*
* @param string $to Receiver email.
* @param string $from_name Receiver name.
* @param string $from_email Sender email.
* @param string $subject Mail subject.
* @param string $message Mail content.
* @param string $cc CC emails.
@felladrin
felladrin / check_open_port.php
Created April 11, 2016 00:14
Example of checking open port with PHP.
<?php
$host = 'example.com';
$port = 80;
$fp = fsockopen($host, $port, $errno, $errstr, 2);
if($fp)
{
echo "Port $port is open on $host.";
fclose($fp);
}
else
@felladrin
felladrin / RandomName.php
Created April 11, 2016 00:13
Simple class to get a random name.
<?php
class RandomName
{
private static $maleNameList = ['Aaron','Abdul','Abe','Abel','Abraham','Abram','Adalberto','Adam','Adan','Adolfo','Adolph','Adrian','Agustin','Ahmad','Ahmed','Al','Alan','Albert','Alberto','Alden','Aldo','Alec','Alejandro','Alex','Alexander','Alexis','Alfonso','Alfonzo','Alfred','Alfredo','Ali','Allan','Allen','Alonso','Alonzo','Alphonse','Alphonso','Alton','Alva','Alvaro','Alvin','Amado','Ambrose','Amos','Anderson','Andre','Andrea','Andreas','Andres','Andrew','Andy','Angel','Angelo','Anibal','Anthony','Antione','Antoine','Anton','Antone','Antonia','Antonio','Antony','Antwan','Archie','Arden','Ariel','Arlen','Arlie','Armand','Armando','Arnold','Arnoldo','Arnulfo','Aron','Arron','Art','Arthur','Arturo','Asa','Ashley','Aubrey','August','Augustine','Augustus','Aurelio','Austin','Avery','Barney','Barrett','Barry','Bart','Barton','Basil','Beau','Ben','Benedict','Benito','Benjamin','Bennett','Bennie','Benny','Benton','Bernard','Bernardo','Bernie','Berry','Bert','Bertram','Bill','Billie
@felladrin
felladrin / session_start.php
Created May 25, 2015 13:44
Right way to start a session.
<?php
// Recommended way for versions of PHP >= 5.4.0:
if (session_status() == PHP_SESSION_NONE && !headers_sent()) {
session_start();
}
// For versions of PHP < 5.4.0:
if(session_id() == '' && !headers_sent()) {
session_start();