Skip to content

Instantly share code, notes, and snippets.

@pafnuty
pafnuty / init.php
Last active June 5, 2017 17:43
Вывод отладки в Bitrix через Kint
<?
# /local/php_interface/init.php
/**
* Вывод дебага через класс Kint
* @author Павел Белоусов <pb@infoexpert.ru>
*
* @param mixed $var Данные, которые требуется вывести
* @param string $function Функция, вызываемая из класса Kint. По умолчанию 'd'. Можно передать s, cd или ddd
* @param boolean $bAllUsers True — выводить всем пользователям (по умолчанию только для админов)
@Integralist
Integralist / convert-p12-pem-formats.bash
Created November 17, 2015 12:57
Convert a P12 into a PEM and vice versa
# Convert p12 to pem
openssl pkcs12 -in certificate.p12 -out certificate.pem -clcerts -nodes
# Convert pem to p12
openssl pkcs12 -export -in certificate.pem -out certificate.p12 -passout pass:password
@wpscholar
wpscholar / array-insert-after.php
Created November 7, 2015 13:04
Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended to the end of the array.
<?php
/**
* Insert a value or key/value pair after a specific key in an array. If key doesn't exist, value is appended
* to the end of the array.
*
* @param array $array
* @param string $key
* @param array $new
*
@Thinkscape
Thinkscape / EffectiveUrlMiddleware.php
Last active October 4, 2022 18:30
getEffectiveUrl() replacement for Guzzle 6.*
<?php
namespace Thinkscape\Guzzle;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
class EffectiveUrlMiddleware
{
/**
* @var Callable
@wpscholar
wpscholar / vagrant-cheat-sheet.md
Last active May 22, 2024 07:14
Vagrant Cheat Sheet

Typing vagrant from the command line will display a list of all available commands.

Be sure that you are in the same directory as the Vagrantfile when running these commands!

Creating a VM

  • vagrant init -- Initialize Vagrant with a Vagrantfile and ./.vagrant directory, using no specified base image. Before you can do vagrant up, you'll need to specify a base image in the Vagrantfile.
  • vagrant init <boxpath> -- Initialize Vagrant with a specific box. To find a box, go to the public Vagrant box catalog. When you find one you like, just replace it's name with boxpath. For example, vagrant init ubuntu/trusty64.

Starting a VM

  • vagrant up -- starts vagrant environment (also provisions only on the FIRST vagrant up)
@johandouma
johandouma / gist:73b5da17334773138d60
Last active January 16, 2016 08:12
Craft CMS + Foundation Top Bar Twig Macro
{% macro menu(entries, active, level) %}
{% if entries|length %}
{% set level = level|default(1) %}
<ul class="level-{{ level }} {{ level > 1 ? "dropdown sub" : "left top" }}">
{% for n in entries %}
<li class="{{ loop.first ? "first" : "" }} {{ loop.last ? "last" : "" }}
{%- if n.children|length %}has-dropdown{% endif %}
{%- if active is defined and (active.descendantOf(n) or active.id == n.id) %} active{% endif %}">
<a href="{{ n.url }}">
{{ n }}
@joshmfrankel
joshmfrankel / fixBrokenHTMLString.php
Last active September 8, 2023 12:22
PHP: Fix broken html tags in string and use html entities
/**
* Fix for broken html tags inside strings for php.
*
* By using passing the html through DOMDocument and converting the html
* entities we are left with beautiful well formatted code. Huzzah!
*
* "Nothing is ever easy" -Zedd, Wizards First Rule
*
* @var DOMDocument
*/
@cuth
cuth / debug-scroll.md
Last active February 7, 2024 18:17
Find the elements that are causing a horizontal scroll. Based on http://css-tricks.com/findingfixing-unintended-body-overflow/

Debug Horizontal Scroll

(function (d) {
    var w = d.documentElement.offsetWidth,
        t = d.createTreeWalker(d.body, NodeFilter.SHOW_ELEMENT),
        b;
    while (t.nextNode()) {
        b = t.currentNode.getBoundingClientRect();
 if (b.right &gt; w || b.left &lt; 0) {
@xeoncross
xeoncross / domdocument_encoding.php
Last active July 8, 2023 14:46
Fix HTML encoding errors with PHP DOMDocument
<?php
// Ignore errors
libxml_use_internal_errors(true) AND libxml_clear_errors();
// http://stackoverflow.com/q/10237238/99923
// http://stackoverflow.com/q/12034235/99923
// http://stackoverflow.com/q/8218230/99923
// original input (unknown encoding)
@jdewit
jdewit / unuconvd_template
Last active March 21, 2021 03:38
unoconv daemon
### BEGIN INIT INFO
# Provides: unoconvd
# Required-Start: $network
# Required-Stop: $network
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Description: unoconvd Converting documents to PDF by unoconv
### END INIT INFO
#!/bin/sh
case "$1" in