Skip to content

Instantly share code, notes, and snippets.

@alrik11es
alrik11es / memorize.php
Created July 10, 2017 10:24
Saves methods result on memory. Needs to be private or protected to work. Public methods will never be saved in memory.
<?php
namespace App;
trait Memorize
{
/**
* @var array [method][parameters]
*/
private $memorizedResults = [];
@alrik11es
alrik11es / manage-etc-hosts.sh
Last active April 27, 2021 12:29 — forked from stvvt/manage-etc-hosts.sh
Bash Script to Manage /etc/hosts file for adding/removing hostnames.
#!/usr/bin/env bash
set -eu
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
# PATH TO YOUR HOSTS FILE
@alrik11es
alrik11es / test.php
Last active January 14, 2016 15:08
Example wordpress REST route
<?php
// http://my-site.com/wp-json/pandora/avatar
function my_func()
{
register_rest_route( 'pandora', '/avatar', array(
'methods' => \WP_REST_Server::READABLE,
'callback' => 'my_call',
)
);
}
var io = require('socket.io-client');
var nano = require('nano')('http://localhost:5984');
var server = 'http://localhost:8080';
module.exports = {
setUp: function (callback) {
this.socket = io.connect(server, {'reconnect': false, 'force new connection': true});
callback();
@alrik11es
alrik11es / calendar.php
Created May 13, 2012 20:48
Dibujado de un calendario en PHP del año indicado.
<?php
function drawCalendar($year = null){
$cal = '';
$month_name = array('','Enero','Febrero','Marzo','Abril','Mayo','Junio','Julio','Agosto','Septiembre','Octubre','Noviembre','Diciembre');
if($year == null)
$year = date('Y');