Skip to content

Instantly share code, notes, and snippets.

View ogabrielguerra's full-sized avatar
🏠
Working from home

Gabriel Guerra ogabrielguerra

🏠
Working from home
View GitHub Profile
new Promise<XMLHttpRequest>((resolve, reject) => {
xhr.onreadystatechange = ()=> resolve(xhr);
})
.then(result => {
(result.status == 200) ? statusMessage(messageSuccess) : statusMessage(messageError);
})
.catch(error => console.log('ERROR:', error.message));
@ogabrielguerra
ogabrielguerra / onlyNumbers.js
Created December 31, 2020 19:16
Only numbers
$(document).ready(() => {
$(".onlyNumbers").keypress(function (e) {
if (e.which !== 8 && e.which !== 0 && (e.which < 48 || e.which > 57)) {
return false;
}
});
});
@ogabrielguerra
ogabrielguerra / detectAnagram.php
Created October 8, 2020 18:35
Detect Anagram
<?php
/*
must return TRUE:

('arc', 'car')

('listen', 'silent')

('malarm', 'malmar')

('peer', 'eper')

must return FALSE:

@ogabrielguerra
ogabrielguerra / AstronautController.php
Last active September 25, 2020 01:36
AstronautController
<?php
class AstronautController{
private string $name;
private float $pounds;
function __construct(string $name, float $pounds){
$this->setName($name);
@ogabrielguerra
ogabrielguerra / branch_as_composer_dependency.json
Created September 25, 2020 01:18
Branch as Composer Dependency
{
"repositories": [
{
"type": "git",
"url": "https://github.com/pressbooks/new-private-project"
}
],
"require": {
"pressbooks/new-private-project": "dev-bugfixes"
}
@ogabrielguerra
ogabrielguerra / course_manager_queries.sql
Created September 25, 2020 01:15
SQL Script - Course Manager Queries
-- COUNT APPLICATIONS BY USER
SELECT ca.id_user, u.name,
COUNT(ca.id_user) as num_applications
FROM course_application ca, user u
WHERE ca.id_user = u.id
GROUP BY ca.id_user, u.name;
-- COUNT COURSES BY USER OF ID 1
@ogabrielguerra
ogabrielguerra / course_manager_data.sql
Created September 25, 2020 01:12
SQL Script - Course Manager Data
-- INSERT DATA
INSERT INTO `course` (`id`, `title`)
VALUES
(1,'Cooking for Fun'),
(2,'Arduin and Automation'),
(3,'Education for Life'),
(4,'Modern PHP Definitive Guide');
INSERT INTO `course_application`
@ogabrielguerra
ogabrielguerra / courses_manager_structure.sql
Created September 25, 2020 01:10
SQL Script - Courses Manager Structure
-- CREATE STRUCTURE
DROP TABLE IF EXISTS `course`;
CREATE TABLE `course` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`title` varchar(255) NOT NULL DEFAULT '',
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
@ogabrielguerra
ogabrielguerra / sortWords.php
Last active September 25, 2020 01:07
Sort Special Words
<?php
function sortWords(String $string){
$words = explode(' ', $string);
$numWords = count($words);
$englishWords = [];
$chineseWords = [];
for($i=0; $i<$numWords; $i++){
if(ctype_alnum($words[$i])){
@ogabrielguerra
ogabrielguerra / SiteImages.Class.php
Last active May 1, 2020 21:04
Get images from a dir and return HTML accordingly with passed template.
<?php
class SiteImages{
public string $path = '';
public string $template = '';
public function __construct(string $path, string $template){
$this->setPath($path);
$this->setTemplate($template);