Skip to content

Instantly share code, notes, and snippets.

View joshuaadickerson's full-sized avatar

Joshua Dickerson joshuaadickerson

View GitHub Profile
@joshuaadickerson
joshuaadickerson / Test1.php
Created August 26, 2015 02:17
I am getting a memory exhaustion while creating objects that aren't assigned to variables. This is the tests for that
<?php
/** RESULTS: Closures and str_repeat()
php /var/www/BBC/Test.php
Test started
0 || 263152
1000 || 485437312
2000 || 970686632
3000 || 1458032936
@joshuaadickerson
joshuaadickerson / instr.php
Created August 25, 2015 23:40
An insitu (no copy) string comparison comparable to substr_compare()
<?php
function instr($string, $substr, $offset = 0, $length = -1)
{
$pos = (int) $offset;
$substr_pos = 0;
for (; $pos !== $length; $pos++, $substr_pos++)
{
vagrantfile:
target: local
vm:
box: puphpet/ubuntu1404-x64
box_url: puphpet/ubuntu1404-x64
hostname: 56.php.vm
memory: '512'
cpus: '1'
chosen_provider: virtualbox
network:
@joshuaadickerson
joshuaadickerson / BBCHelpers.php
Last active August 29, 2015 14:27
SMF/Elkarte BBC Parser
<?php
/**
* Microsoft uses their own character set Code Page 1252 (CP1252), which is a
* superset of ISO 8859-1, defining several characters between DEC 128 and 159
* that are not normally displayable. This converts the popular ones that
* appear from a cut and paste from windows.
*
* @param string|false $string
* @return string $string
<?php
function pc_next_permutation($p, $size)
{
// slide down the array looking for where we're smaller than the next guy
for ($i = $size - 1; $p[$i] >= $p[$i + 1]; --$i);
// if this doesn't occur, we've finished our permutations
// the array is reversed: (1, 2, 3, 4) => (4, 3, 2, 1)
if ($i == -1)
<?php
function getIPBanRange(array $start, array $end)
{
$parts_count = count($start);
if ($parts_count !== count($end))
{
throw new \InvalidArgumentException('$start and $end must be the same length');
}
@joshuaadickerson
joshuaadickerson / GistTag.php
Created August 8, 2015 05:38
A BBC tag for adding gist snippets
<?php
function gist_bbc(&$codes, &$no_autolink_tags, &$itemcodes)
{
$codes[] = array(
'tag' => 'gist',
'type' => 'unparsed_content',
'content' => '<script src="$1.js"></script>',
'validate' => function(&$tag, &$data, $disabled) {
$data = strtr($data, array('<br />' => ''));
@joshuaadickerson
joshuaadickerson / Post.Controller.php
Last active August 29, 2015 14:24
Working on refactoring. Taking a while and a lot of work
<?php
/**
* The job of this file is to handle everything related to posting replies,
* new topics, quotes, and modifications to existing posts. It also handles
* quoting posts by way of javascript.
*
* @name ElkArte Forum
* @copyright ElkArte Forum contributors
* @license BSD http://opensource.org/licenses/BSD-3-Clause
<?php
function getBoardTree()
{
global $cat_tree, $boards, $boardList;
$db = database();
// Getting all the board and category information you'd ever wanted.
$request = $db->query('', '
SELECT
IFNULL(b.id_board, 0) AS id_board, b.id_parent, b.name AS board_name, b.description, b.child_level,
<?php
namespace Hashtags\Controller;
class Hashtags
{
protected $hashtag_manager;
public function pre_dispatch()
{