Skip to content

Instantly share code, notes, and snippets.

@RichiUfo
RichiUfo / SearchResults.php
Created April 19, 2019 09:01 — forked from kevinquillen/SearchResults.php
Example of a Controller using SearchAPI to generate a results page (without Views).
<?php
namespace Drupal\velirsearch\Controller;
use Drupal\Core\Controller\ControllerBase;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpFoundation\Request;
use Drupal\velirsearch\Service\PagerService;
class SearchResults extends ControllerBase {
@RichiUfo
RichiUfo / lamp-stack-osx-virtualhostx.md
Created February 18, 2019 21:45 — forked from pwenzel/lamp-stack-osx-virtualhostx.md
LAMP stack on OSX with Homebrew, built-in Apache, multiple PHP versions, VirtualhostX optional

This guide shows how to set up a PHP and MySQL development environment using OSX's built-in Apache, using Homebrew to install necessary components. With this strategy, you can use different versions of PHP for certain virtual hosts.

VirtualHostX is a convenient way to manage development sites, but not required.

Install PHP and MySQL with Homebrew

brew update
brew install php56
brew install php56-mcrypt
brew install mysql
@RichiUfo
RichiUfo / MySQL_macOS_Sierra.md
Created February 18, 2019 21:45 — forked from nrollr/MySQL_macOS_Sierra.md
Install MySQL on Sierra using Homebrew

Install MySQL on macOS Sierra

This procedure explains how to install MySQL using Homebrew on macOS Sierra 10.12

Install Homebrew

  • Installing Homebrew is effortless, open Terminal and enter :
    $ /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
  • Note: Homebrew will download and install Command Line Tools for Xcode 8.0 as part of the installation process.

Install MySQL

At this time of writing, Homebrew has MySQL version 5.7.15 as default formulae in its main repository :

@RichiUfo
RichiUfo / random_color.php
Created January 22, 2018 13:44 — forked from agarzon/random_color.php
PHP Random Color Generator Hex
<?php $color = dechex(rand(0x000000, 0xFFFFFF)); ?>
<body style="background-color: <?php echo $color; ?>;">
<h1><?php echo $color ?></h1>
</body>
@RichiUfo
RichiUfo / macro.md
Created January 22, 2018 11:47 — forked from brunogaspar/macro.md
Recursive Laravel Collection Macros

What?

If a nested array is passed into a Laravel Collection, by default these will be threaded as normal arrays.

However, that's not always the ideal case and it would be nice if we could have nested collections in a cleaner way.

This is where this macro comes in handy.

Setup

@RichiUfo
RichiUfo / 010-functions.php
Created April 25, 2017 13:51 — forked from ms-studio/010-functions.php
Using vimeo API in Wordpress
// vimeo helper function
// Curl helper function
// based on this example
// https://github.com/vimeo/vimeo-api-examples/blob/master/simple-api/simple/simple.php
// detailed explanations are in this post:
// http://ms-studio.net/2012/notes/using-the-vimeo-api-in-wordpress/
function curl_get($url) {
$curl = curl_init($url);
@RichiUfo
RichiUfo / wordpress-tinymce.js
Created March 27, 2017 09:32 — forked from RadGH/wordpress-tinymce.js
Get/Set content of a TinyMCE visual or text editor with JavaScript
/*
Based on: http://wordpress.stackexchange.com/questions/42652/#answer-42729
These functions provide a simple way to interact with TinyMCE (wp_editor) visual editor.
This is the same thing that WordPress does, but a tad more intuitive.
Additionally, this works for any editor - not just the "content" editor.
Usage:
@RichiUfo
RichiUfo / handle_file_upload.php
Created February 15, 2017 10:56 — forked from ebidel/handle_file_upload.php
Uploading files using xhr.send(FormData) to PHP server
<?php
$fileName = $_FILES['afile']['name'];
$fileType = $_FILES['afile']['type'];
$fileContent = file_get_contents($_FILES['afile']['tmp_name']);
$dataUrl = 'data:' . $fileType . ';base64,' . base64_encode($fileContent);
$json = json_encode(array(
'name' => $fileName,
'type' => $fileType,
'dataUrl' => $dataUrl,
@RichiUfo
RichiUfo / apache.conf
Created November 23, 2016 13:36 — forked from imposibrus/apache.conf
config files samples
<VirtualHost *:81>
ServerAdmin vp@ft-ru.ru
DocumentRoot /home/ubuntu/www/ft-ru.ru
ServerName ft-ru.ru
ErrorLog ${APACHE_LOG_DIR}/ft-ru.ru.error.log
CustomLog ${APACHE_LOG_DIR}/ft-ru.ru.access.log common
SetEnv ENV "development"
</VirtualHost>
@RichiUfo
RichiUfo / db.js
Created November 23, 2016 13:36 — forked from imposibrus/db.js
Node.js MySQL connection pool with node-mysql package
var mysql = require('mysql');
function handleDisconnect(db_config) {
var connection = mysql.createPool(db_config);
connection.on('error', function(err) {
console.error('db error', err, err.code);
if(err.code === 'PROTOCOL_CONNECTION_LOST') {
handleDisconnect(db_config);