Skip to content

Instantly share code, notes, and snippets.

View nticaric's full-sized avatar

Nenad Ticaric nticaric

View GitHub Profile

Awesome PHP Libraries

A list of amazingly awesome PHP libraries that you should consider using (and some other shiny extras).

@nticaric
nticaric / BoyerMoore.php
Last active July 16, 2022 08:25
Boyer–Moore algorithm implementation in PHP
<?php
/**
* Returns the index of the first occurrence of the
* specified substring. If it's not found return -1.
*
* @param text The string to be scanned
* @param pattern The target string to search
* @return The start index of the substring
*/
@nticaric
nticaric / gist:0f76f9dc1ae5e84e601d
Last active August 29, 2015 14:04
encoding video that works in video tag
ffmpeg -v verbose -i header-orig.mp4 -c:v libx264 -level:v 3.0 -bf 1 -s 1360x768 -profile:v baseline -r 29.97 -pix_fmt yuv420p -movflags +faststart header.mp4
<?php namespace App\Console\Commands;
use Illuminate\Console\Command;
use TeamTNT\TNTSearch\TNTSearch;
use Config;
use Goutte\Client;
class IndexDocumentation extends Command
{
/**
<?php
public function scrapePHPUnitDe()
{
$client = new Client();
$crawler = $client->request('GET', 'https://phpunit.de/manual/current/en/index.html');
$toc = $crawler->filter('.toc');
file_put_contents(base_path('resources/docs/').'index.html', $toc->html());
$crawler->filter('.toc > dt a')->each(function($node) use ($client) {
<?php
public function handle()
{
$this->scrapePHPUnitDe();
$tnt = new TNTSearch;
$config = [
"storage" => storage_path(),
<?php
public function search(Request $request)
{
$this->tnt->loadConfig([
"storage" => storage_path(),
"driver" => 'filesystem',
]);
$this->tnt->selectIndex("docs");
<?php
public function processResults($res, $request)
{
$data = ['hits' => [], 'nbHits' => count($res)];
foreach ($res as $result) {
$file = file_get_contents($result['path']);
$crawler = new Crawler;
$crawler->addHtmlContent($file);
@nticaric
nticaric / loadMNISTLabels.php
Last active November 10, 2016 21:52
A function that returns an array containing MNIST labels
<?php
public function loadMNISTLabels($filename)
{
$fp = fopen($filename, 'rb');
$array = unpack("N2", fread($fp, 8));
$magic = $array[1];
if($magic != 2049) {
@nticaric
nticaric / loadMNISTImages.php
Created November 10, 2016 21:53
A function that returns an array containing raw MNIST images
<?php
public function loadMNISTImages($filename)
{
$fp = fopen($filename, 'rb');
$array = unpack("N4", fread($fp, 16));
$magic = $array[1];
if($magic != 2051) {