Skip to content

Instantly share code, notes, and snippets.

@MontealegreLuis
MontealegreLuis / User.php
Last active December 12, 2015 05:18
usort example
<?php
class User
{
protected $createdAt;
protected $name;
public function __construct($name, DateTime $createdAt)
{
$this->name = $name;
@MontealegreLuis
MontealegreLuis / courses.html
Created February 7, 2013 16:38
Ajax example
<!DOCTYPE HTML>
<html>
<body>
<form>
<select name="courses" id="courses">
<option value="">Select a course</option>
<option value="1">JavaScript</option>
<option value="2">PHP</option>
<option value="3">HTML &amp; CSS</option>
@MontealegreLuis
MontealegreLuis / get-new-records.php
Created February 7, 2013 17:30
JavaScript setInterval example
<?php
//Count the records in your database
//SELECT COUNT(*) FROM ....
$records = array(
array('name' =>'Richard Feynman', 'age' => 30), //You already have this one in your HTML
array('name' =>'Erwin Schrödinger', 'age' => 31),
array('name' => 'Albert Einstein', 'age' => 32),
);
$count = filter_var($_GET['recordsCount'], FILTER_VALIDATE_INT);
@MontealegreLuis
MontealegreLuis / curl-example.php
Created February 12, 2013 02:59
CURL example with SSL certificate
<?php
$url = 'https://www.somedomain.com/a-page';
$certificateFile = 'ceritificate.pem';
$certificatePassword = 'password';
$handler = curl_init();
$options = array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => true,
@MontealegreLuis
MontealegreLuis / database.sql
Last active December 13, 2015 20:18
SQL to find friends in common.
CREATE TABLE user (
user_id INT NOT NULL AUTO_INCREMENT,
name VARCHAR(256) CHARACTER SET 'utf8' COLLATE 'utf8_general_ci' NOT NULL,
PRIMARY KEY (user_id)
) ENGINE = InnoDB
DEFAULT CHARACTER SET = utf8
COLLATE = utf8_general_ci;
CREATE TABLE user_friends (
user_id INT NOT NULL,
@MontealegreLuis
MontealegreLuis / find-dups-array.php
Created March 8, 2013 18:24
Finding duplicates in an array
<?php
$array = array('pedro', 'juan', 'paco', 'pedro');
$repeated = array_filter(array_count_values($array), function($count) {
return $count > 1;
});
foreach ($repeated as $key => $value) {
echo "Key '$key' is repeated $value times <br />";
}
@MontealegreLuis
MontealegreLuis / VenueTypeFixture.php
Last active December 14, 2015 23:19
Slim application functional test (Very simplified version of a RESTful Web Service)
<?php
// /tests/functional/Application/DataFixture/VenueTypeFixture.php
namespace Application\DataFixture;
use \Doctrine\DBAL\Connection;
class VenueTypeFixture
{
protected $connection;
@MontealegreLuis
MontealegreLuis / date-diff.php
Created June 20, 2013 20:20
Difference in hours between two dates.
<?php
$now = new DateTime('now', new DateTimeZone('America/Mexico_City'));
$twoHoursAgo = clone $now;
$twoHoursAgo = $twoHoursAgo->sub(new DateInterval('PT2H'));
$diff = $now->diff($twoHoursAgo);
echo $diff->format("%H hours\n");
@MontealegreLuis
MontealegreLuis / ajax.js
Created September 12, 2013 19:11
Ajax function
function CreateAjax() {
var objetoAjax = false;
try {
/* Para navegadores distintos a Internet Explorer */
objetoAjax = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
/* Para explorer */
objetoAjax = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
@MontealegreLuis
MontealegreLuis / composer.json
Created November 24, 2013 03:52
composer.json for Drupal 8 + DrupalAppConsole
{
"name": "drupal/drupal",
"description": "Drupal is an open source content management platform powering millions of websites and applications.",
"type": "drupal-core",
"license": "GPL-2.0+",
"repositories": [
{
"type": "vcs",
"url": "https://github.com/MontealegreLuis/DrupalAppConsole.git"
}